void do_report(file, line, ok) char *file;
int line;
int ok;
{
  char reason;
  unsigned long ab;
  unsigned long fb;
  reason = ok ? 'e' : 'f';
  if (!ok) {
    do_fail(file, line, "Generic failure");
  } else {
    erl_eterm_release();
    erl_eterm_statistics(&ab, &fb);
    if ((ab == 0) && (fb == 0)) {
      reply(&reason, 1);
    } else {
      char sbuf[128];
      sprintf(sbuf,
              "still %lu terms allocated,"
              " %lu on freelist at end of test",
              ab, fb);
      do_fail(file, line, sbuf);
    }
  }
}


x86 assembly (clang, -O0):
<do_report>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x66,%eax
mov    $0x65,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    119f <do_report+0x4f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe6d(%rip),%rdx
mov    $0x0,%al
call   1030 <do_fail@plt>
jmp    1217 <do_report+0xc7>
mov    $0x0,%al
call   1050 <erl_eterm_release@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1060 <erl_eterm_statistics@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <do_report+0x90>
cmpq   $0x0,-0x28(%rbp)
jne    11e0 <do_report+0x90>
lea    -0x11(%rbp),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <reply@plt>
jmp    1212 <do_report+0xc2>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0xb0(%rbp),%rdx
mov    $0x0,%al
call   1030 <do_fail@plt>
jmp    1217 <do_report+0xc7>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_report>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
test   %edx,%edx
sete   %al
add    $0x65,%al
mov    %al,0xf(%rsp)
test   %edx,%edx
je     11ac <do_report+0x5c>
xor    %eax,%eax
call   1050 <erl_eterm_release@plt>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <erl_eterm_statistics@plt>
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %rdx,%rax
or     %rcx,%rax
jne    11ca <do_report+0x7a>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <reply@plt>
jmp    11ef <do_report+0x9f>
lea    0xe4d(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <do_fail@plt>
lea    0xe3f(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <do_fail@plt>
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Generic failure\00"
@.str.1 = [58 x i8] c"still %lu terms allocated, %lu on freelist at end of test\00"
define void @do_report(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i64
%9 = alloca i64
%10 = alloca [128 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 101, i32 102
%15 = trunc i32 %14 to i8
store i8 %15, i8* %7
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @do_fail to i32 (i8*, i32, i8*, ...)*)(i8* %19, i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %42
22: ; preds = %3
%23 = call i32 (...) @erl_eterm_release()
%24 = call i32 (i64*, i64*, ...) bitcast (i32 (...)* @erl_eterm_statistics to i32 (i64*, i64*, ...)*)(i64* %8, i64* %9)
%25 = load i64, i64* %8
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i64, i64* %9
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @reply to i32 (i8*, i32, ...)*)(i8* %7, i32 1)
br label %41
32: ; preds = %27, %22
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%34 = load i64, i64* %8
%35 = load i64, i64* %9
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i64 %34, i64 %35)
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%40 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @do_fail to i32 (i8*, i32, i8*, ...)*)(i8* %37, i32 %38, i8* %39)
br label %41
41: ; preds = %32, %30
br label %42
42: ; preds = %41, %18
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Generic failure\00"
@.str.1 = [58 x i8] c"still %lu terms allocated, %lu on freelist at end of test\00"
define void @do_report(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
%7 = alloca [128 x i8]
%8 = bitcast i64* %5 to i8*
%9 = bitcast i64* %6 to i8*
%10 = icmp eq i32 %2, 0
%11 = select i1 %10, i8 102, i8 101
store i8 %11, i8* %4
br i1 %10, label %12, label %14
12: ; preds = %3
%13 = tail call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @do_fail to i32 (i8*, i32, i8*, ...)*)(i8* %0, i32 %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %28
14: ; preds = %3
%15 = tail call i32 (...) @erl_eterm_release()
%16 = call i32 (i64*, i64*, ...) bitcast (i32 (...)* @erl_eterm_statistics to i32 (i64*, i64*, ...)*)(i64* %5, i64* %6)
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, 0
%19 = load i64, i64* %6
%20 = icmp eq i64 %19, 0
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @reply to i32 (i8*, i32, ...)*)(i8* %4, i32 1)
br label %28
24: ; preds = %14
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i64 %17, i64 %19)
%27 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @do_fail to i32 (i8*, i32, i8*, ...)*)(i8* %0, i32 %1, i8* %25)
br label %28
28: ; preds = %22, %24, %12
ret void
}