int flash_bulk_erase(int fd) {
  printf("== %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);
  printf("== %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)
lea    0xe8e(%rip),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1030 <do_write_enable@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <check_wel@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a9 <flash_bulk_erase+0x49>
jmp    11ba <flash_bulk_erase+0x5a>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1080 <usleep@plt>
jmp    118a <flash_bulk_erase+0x2a>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1060 <do_bulk_erase@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <check_wip@plt>
cmp    $0x0,%eax
je     11e8 <flash_bulk_erase+0x88>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1080 <usleep@plt>
jmp    11c4 <flash_bulk_erase+0x64>
lea    0xe32(%rip),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_bulk_erase>:
push   %rbx
mov    %edi,%ebx
lea    0xe96(%rip),%rdi
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <do_write_enable@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <check_wel@plt>
test   %eax,%eax
jne    11ab <flash_bulk_erase+0x4b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1080 <usleep@plt>
jmp    1190 <flash_bulk_erase+0x30>
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <do_bulk_erase@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <check_wip@plt>
test   %eax,%eax
je     11db <flash_bulk_erase+0x7b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1080 <usleep@plt>
jmp    11c0 <flash_bulk_erase+0x60>
lea    0xe3f(%rip),%rdi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.flash_bulk_erase, i64 0, i64 0))
%4 = load i32, i32* %2
%5 = call i32 (i32, ...) bitcast (i32 (...)* @do_write_enable to i32 (i32, ...)*)(i32 %4)
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %2
%8 = call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %6
13: ; preds = %6
%14 = load i32, i32* %2
%15 = call i32 (i32, ...) bitcast (i32 (...)* @do_bulk_erase to i32 (i32, ...)*)(i32 %14)
br label %16
16: ; preds = %20, %13
%17 = load i32, i32* %2
%18 = call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %16
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.flash_bulk_erase, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.flash_bulk_erase, i64 0, i64 0))
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @do_write_enable to i32 (i32, ...)*)(i32 %0)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1, %6
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %6, label %10
10: ; preds = %6, %1
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @do_bulk_erase to i32 (i32, ...)*)(i32 %0)
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10, %14
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %10
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__FUNCTION__.flash_bulk_erase, i64 0, i64 0))
ret i32 0
}