void test_empty() {
  gc_init(1000);
  if (0 != gc_num_roots()) {
    printf("\n%-30s failure on line %d; expecting %d found %d\n", __func__, 50,
           0, gc_num_roots());
  };
  char *expected = "next_free=0\n"
                   "objects:\n";
  char *found = gc_get_state();
  if (strcmp(expected, found) != 0) {
    printf("\n%-30s failure on line %d; expecting:\n%s\nfound:\n%s\n", __func__,
           55, expected, found);
  };
  free(found);
  gc();
  gc_done();
}


x86 assembly (clang, -O0):
<test_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3e8,%edi
mov    $0x0,%al
call   1050 <gc_init@plt>
mov    $0x0,%al
call   1040 <gc_num_roots@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11cd <test_empty+0x4d>
mov    $0x0,%al
call   1040 <gc_num_roots@plt>
mov    %eax,%r8d
lea    0xe48(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    $0x32,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe69(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <gc_get_state@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
je     121d <test_empty+0x9d>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe49(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    $0x37,%edx
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <gc@plt>
mov    $0x0,%al
call   1060 <gc_done@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_empty>:
push   %rbx
mov    $0x3e8,%edi
xor    %eax,%eax
call   1050 <gc_init@plt>
xor    %eax,%eax
call   1040 <gc_num_roots@plt>
test   %eax,%eax
je     11be <test_empty+0x3e>
xor    %eax,%eax
call   1040 <gc_num_roots@plt>
lea    0xe5a(%rip),%rdi
lea    0xe85(%rip),%rsi
mov    $0x32,%edx
xor    %ecx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10a0 <gc_get_state@plt>
movslq %eax,%rbx
lea    0xe6e(%rip),%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
je     11ff <test_empty+0x7f>
lea    0xe71(%rip),%rdi
lea    0xe49(%rip),%rsi
lea    0xe4d(%rip),%rcx
mov    $0x37,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <gc@plt>
xor    %eax,%eax
pop    %rbx
jmp    1060 <gc_done@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"\0A%-30s failure on line %d; expecting %d found %d\0A\00"
@__func__.test_empty = [11 x i8] c"test_empty\00"
@.str.1 = [22 x i8] c"next_free=0\0Aobjects:\0A\00"
@.str.2 = [52 x i8] c"\0A%-30s failure on line %d; expecting:\0A%s\0Afound:\0A%s\0A\00"
define void @test_empty() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i32 (i32, ...) bitcast (i32 (...)* @gc_init to i32 (i32, ...)*)(i32 1000)
%4 = call i32 (...) @gc_num_roots()
%5 = icmp ne i32 0, %4
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (...) @gc_num_roots()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.test_empty, i64 0, i64 0), i32 50, i32 0, i32 %7)
br label %9
9: ; preds = %6, %0
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %1
%10 = call i32 (...) @gc_get_state()
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %2
%13 = load i8*, i8** %1
%14 = load i8*, i8** %2
%15 = call i32 @strcmp(i8* %13, i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i8*, i8** %1
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.test_empty, i64 0, i64 0), i32 55, i8* %18, i8* %19)
br label %21
21: ; preds = %17, %9
%22 = load i8*, i8** %2
%23 = call i32 (...) @gc()
%24 = call i32 (...) @gc_done()
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"\0A%-30s failure on line %d; expecting %d found %d\0A\00"
@__func__.test_empty = [11 x i8] c"test_empty\00"
@.str.1 = [22 x i8] c"next_free=0\0Aobjects:\0A\00"
@.str.2 = [52 x i8] c"\0A%-30s failure on line %d; expecting:\0A%s\0Afound:\0A%s\0A\00"
define void @test_empty() {
%1 = tail call i32 (i32, ...) bitcast (i32 (...)* @gc_init to i32 (i32, ...)*)(i32 1000)
%2 = tail call i32 (...) @gc_num_roots()
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i32 (...) @gc_num_roots()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.test_empty, i64 0, i64 0), i32 50, i32 0, i32 %5)
br label %7
7: ; preds = %4, %0
%8 = tail call i32 (...) @gc_get_state()
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcmp(i8* dereferenceable(22) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.test_empty, i64 0, i64 0), i32 55, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %15
15: ; preds = %13, %7
tail call void @free(i8* %10)
%16 = tail call i32 (...) @gc()
%17 = tail call i32 (...) @gc_done()
ret void
}