#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int read_status();
int /*<<< orphan*/ recv_byte();
int /*<<< orphan*/ send_byte(int);
int dbg_mass_erase(void) {
  int attempts = 100;
  send_byte(0x14);
  recv_byte();
  while (attempts && !(read_status() & 0x80))
    attempts--;
  if (0 == attempts)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<dbg_mass_erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x64,-0x8(%rbp)
mov    $0x14,%edi
call   1040 <send_byte@plt>
mov    $0x0,%al
call   1030 <recv_byte@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x9(%rbp)
je     1176 <dbg_mass_erase+0x46>
mov    $0x0,%al
call   1050 <read_status@plt>
and    $0x80,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1186 <dbg_mass_erase+0x56>
jmp    1194 <dbg_mass_erase+0x64>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <dbg_mass_erase+0x20>
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    11ab <dbg_mass_erase+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    11b2 <dbg_mass_erase+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_mass_erase>:
push   %rbp
push   %rbx
push   %rax
mov    $0x14,%edi
call   1040 <send_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <recv_byte@plt>
mov    $0xffffff9c,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <read_status@plt>
test   $0x80,%al
jne    1164 <dbg_mass_erase+0x34>
inc    %ebp
jne    1150 <dbg_mass_erase+0x20>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dbg_mass_erase() {
%1 = alloca i32
%2 = alloca i32
store i32 100, i32* %2
%3 = call i32 @send_byte(i32 20)
%4 = call i32 (...) @recv_byte()
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = call i32 (...) @read_status()
%10 = and i32 %9, 128
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br label %13
13: ; preds = %8, %5
%14 = phi i1 [ false, %5 ], [ %12, %8 ]
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
br label %5
18: ; preds = %13
%19 = load i32, i32* %2
%20 = icmp eq i32 0, %19
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %1
br label %23
22: ; preds = %18
store i32 0, i32* %1
br label %23
23: ; preds = %22, %21
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
define i32 @dbg_mass_erase() {
%1 = tail call i32 @send_byte(i32 20)
%2 = tail call i32 (...) @recv_byte()
br label %5
3: ; preds = %5
%4 = icmp eq i32 %10, 0
br i1 %4, label %11, label %5
5: ; preds = %0, %3
%6 = phi i32 [ 100, %0 ], [ %10, %3 ]
%7 = tail call i32 (...) @read_status()
%8 = and i32 %7, 128
%9 = icmp eq i32 %8, 0
%10 = add nsw i32 %6, -1
br i1 %9, label %3, label %11
11: ; preds = %5, %3
%12 = phi i32 [ 1, %3 ], [ 0, %5 ]
ret i32 %12
}