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


x86 assembly (clang, -O0):
<flash_sector_erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <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    1187 <flash_sector_erase+0x37>
jmp    1198 <flash_sector_erase+0x48>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1070 <usleep@plt>
jmp    1168 <flash_sector_erase+0x18>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1030 <do_sector_erase@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <check_wip@plt>
cmp    $0x0,%eax
je     11c9 <flash_sector_erase+0x79>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1070 <usleep@plt>
jmp    11a5 <flash_sector_erase+0x55>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define i32 @flash_sector_erase(i32 %0, i32 %1) {
%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 = %2, %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, %2
%11 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @do_sector_erase to i32 (i32, i32, ...)*)(i32 %0, i32 %1)
%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
ret i32 0
}