int flash_sector_erase(int fd, int addr) {
  printf("== %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);
  printf("== %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)
lea    0xe8b(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <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    11ac <flash_sector_erase+0x4c>
jmp    11bd <flash_sector_erase+0x5d>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1080 <usleep@plt>
jmp    118d <flash_sector_erase+0x2d>
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   1060 <check_wip@plt>
cmp    $0x0,%eax
je     11ee <flash_sector_erase+0x8e>
mov    $0x186a0,%edi
mov    $0x0,%al
call   1080 <usleep@plt>
jmp    11ca <flash_sector_erase+0x6a>
lea    0xe2e(%rip),%rdi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
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
lea    0xe92(%rip),%rdi
lea    0xe9b(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <do_write_enable@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <check_wel@plt>
test   %eax,%eax
jne    11ab <flash_sector_erase+0x4b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1080 <usleep@plt>
jmp    1190 <flash_sector_erase+0x30>
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   1060 <check_wip@plt>
test   %eax,%eax
je     11db <flash_sector_erase+0x7b>
mov    $0x186a0,%edi
xor    %eax,%eax
call   1080 <usleep@plt>
jmp    11c0 <flash_sector_erase+0x60>
lea    0xe41(%rip),%rdi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.flash_sector_erase, i64 0, i64 0))
%6 = load i32, i32* %3
%7 = call i32 (i32, ...) bitcast (i32 (...)* @do_write_enable to i32 (i32, ...)*)(i32 %6)
br label %8
8: ; preds = %13, %2
%9 = load i32, i32* %3
%10 = call i32 (i32, ...) bitcast (i32 (...)* @check_wel to i32 (i32, ...)*)(i32 %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %8
15: ; preds = %8
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 (i32, i32, ...) bitcast (i32 (...)* @do_sector_erase to i32 (i32, i32, ...)*)(i32 %16, i32 %17)
br label %19
19: ; preds = %23, %15
%20 = load i32, i32* %3
%21 = call i32 (i32, ...) bitcast (i32 (...)* @check_wip to i32 (i32, ...)*)(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i32, ...) bitcast (i32 (...)* @usleep to i32 (i32, ...)*)(i32 100000)
br label %19
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.flash_sector_erase, i64 0, i64 0))
ret i32 0
}

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