// #target: macos-x64

module mymodule;

extern fn void printf(char *, ...);

struct Foo
{
    int a;
    int ab;
    struct bob
    {
        int j;
    }
}
fn void main()
{
    int x = 0;
    var $counter = 0;
    $if $defined(x):
        x++;
        $counter++;
    $endif
    $if $defined(Foo.ab):
        int y = 10;
        $counter++;
        x++;
    $endif
    $if $defined(Foo.ab.x):
        x = 0;
        $counter = 0;
    $endif
    $if $defined(Foo.bob):
        x++;
        $counter++;
    $endif
    $if $defined($eval("x")):
        x++;
        $counter++;
    $endif
    $if $defined($typefrom("Foo").$eval("ab")):
        x++;
        $counter++;
    $endif
    $if $defined($typefrom("mymodule::Foo").$eval("bob")):
        x++;
        $counter++;
    $endif
    $if $defined(y):
        x++;
        $counter++;
        y = 1;
    $endif
    $if $defined(z):
        $counter = 0;
        x = 0;
    $endif
    int z = $counter;
    printf("%d\n", x);
}

/* #expect: mymodule.ll

define void @mymodule.main() #0 {
entry:
  %x = alloca i32, align 4
  %y = alloca i32, align 4
  %z = alloca i32, align 4
  store i32 0, ptr %x, align 4
  %0 = load i32, ptr %x, align 4
  %add = add i32 %0, 1
  store i32 %add, ptr %x, align 4
  store i32 10, ptr %y, align 4
  %1 = load i32, ptr %x, align 4
  %add1 = add i32 %1, 1
  store i32 %add1, ptr %x, align 4
  %2 = load i32, ptr %x, align 4
  %add2 = add i32 %2, 1
  store i32 %add2, ptr %x, align 4
  %3 = load i32, ptr %x, align 4
  %add3 = add i32 %3, 1
  store i32 %add3, ptr %x, align 4
  %4 = load i32, ptr %x, align 4
  %add4 = add i32 %4, 1
  store i32 %add4, ptr %x, align 4
  %5 = load i32, ptr %x, align 4
  %add5 = add i32 %5, 1
  store i32 %add5, ptr %x, align 4
  %6 = load i32, ptr %x, align 4
  %add6 = add i32 %6, 1
  store i32 %add6, ptr %x, align 4
  store i32 1, ptr %y, align 4
  store i32 7, ptr %z, align 4
  %7 = load i32, ptr %x, align 4
  call void (ptr, ...) @printf(ptr @.str, i32 %7)
  ret void
}