int flash_bulk_erase(int fd) {
  ("== %s enter ==\n", __FUNCTION__);
  do_write_enable(fd);
  while (!check_wel(fd))
    usleep(1000 * 100);
  do_bulk_erase(fd);
  while (check_wip(fd))
    usleep(1000 * 100);
  ("== %s return ==\n", __FUNCTION__);
  return 0;
}


x86 assembly (clang, -O0):
<flash_bulk_erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1030 <do_write_enable@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1060 <check_wel@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1184 <flash_bulk_erase+0x34>
jmp    1195 <flash_bulk_erase+0x45>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1070 <usleep@plt>
jmp    1165 <flash_bulk_erase+0x15>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <do_bulk_erase@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <check_wip@plt>
cmp    $0x0,%eax
je     11c3 <flash_bulk_erase+0x73>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1070 <usleep@plt>
jmp    119f <flash_bulk_erase+0x4f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_bulk_erase>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <do_write_enable@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <check_wel@plt>
test   %eax,%eax
jne    117b <flash_bulk_erase+0x2b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1070 <usleep@plt>
jmp    1160 <flash_bulk_erase+0x10>
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <do_bulk_erase@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <check_wip@plt>
test   %eax,%eax
je     11ab <flash_bulk_erase+0x5b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1070 <usleep@plt>
jmp    1190 <flash_bulk_erase+0x40>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"== %s enter ==\0A\00"
@__FUNCTION__.flash_bulk_erase = [17 x i8] c"flash_bulk_erase\00"
@.str.1 = [17 x i8] c"== %s return ==\0A\00"
define i32 @flash_bulk_erase(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 (i32, ...) bitcast (i32 (...)* @do_write_enable to i32 (i32, ...)*)(i32 %3)
br label %5
5: ; preds = %10, %1
%6 = load i32, i32* %2
%7 = call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %5
12: ; preds = %5
%13 = load i32, i32* %2
%14 = call i32 (i32, ...) bitcast (i32 (...)* @do_bulk_erase to i32 (i32, ...)*)(i32 %13)
br label %15
15: ; preds = %19, %12
%16 = load i32, i32* %2
%17 = call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %15
21: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
define i32 @flash_bulk_erase(i32 %0) {
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @do_write_enable to i32 (i32, ...)*)(i32 %0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1, %5
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %5, label %9
9: ; preds = %5, %1
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @do_bulk_erase to i32 (i32, ...)*)(i32 %0)
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %13
17: ; preds = %13, %9
ret i32 0
}