#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 SMBReadWord(int, int);
int SMBWriteBlock(int, int, unsigned char *, int);
int /*<<< orphan*/ sleep(int);
int eraseFlashBlock(unsigned int address) {
  int status;
  unsigned char block[3];
  block[0] = address & 0xFF;
  block[1] = (address >> 8) & 0xFF;
  block[2] = (address >> 16) & 0xFF;
  status = SMBWriteBlock(0x16, 0x20, block, 3);
  if (status < 0)
    return status;
  sleep(1);
  status = SMBReadWord(0x16, 0x50);
  return status;
}


x86 assembly (clang, -O0):
<eraseFlashBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0xf(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
lea    -0xf(%rbp),%rdx
mov    $0x16,%edi
mov    $0x20,%esi
mov    $0x3,%ecx
call   1030 <SMBWriteBlock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1192 <eraseFlashBlock+0x62>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <eraseFlashBlock+0x84>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    $0x16,%edi
mov    $0x50,%esi
call   1050 <SMBReadWord@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eraseFlashBlock>:
push   %rax
mov    %edi,%eax
mov    %al,0x5(%rsp)
mov    %ah,0x6(%rsp)
shr    $0x10,%eax
mov    %al,0x7(%rsp)
lea    0x5(%rsp),%rdx
mov    $0x16,%edi
mov    $0x20,%esi
mov    $0x3,%ecx
call   1030 <SMBWriteBlock@plt>
test   %eax,%eax
js     1178 <eraseFlashBlock+0x48>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    $0x16,%edi
mov    $0x50,%esi
call   1050 <SMBReadWord@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @eraseFlashBlock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = and i32 %6, 255
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %8, i8* %9
%10 = load i32, i32* %3
%11 = lshr i32 %10, 8
%12 = and i32 %11, 255
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %13, i8* %14
%15 = load i32, i32* %3
%16 = lshr i32 %15, 16
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 %18, i8* %19
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%21 = call i32 @SMBWriteBlock(i32 22, i32 32, i8* %20, i32 3)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %1
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %30
26: ; preds = %1
%27 = call i32 @sleep(i32 1)
%28 = call i32 @SMBReadWord(i32 22, i32 80)
store i32 %28, i32* %4
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %26, %24
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @eraseFlashBlock(i32 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = trunc i32 %0 to i8
store i8 %4, i8* %3
%5 = lshr i32 %0, 8
%6 = trunc i32 %5 to i8
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 %6, i8* %7
%8 = lshr i32 %0, 16
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 %9, i8* %10
%11 = call i32 @SMBWriteBlock(i32 22, i32 32, i8* %3, i32 3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = call i32 @sleep(i32 1)
%15 = call i32 @SMBReadWord(i32 22, i32 80)
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ %15, %13 ], [ %11, %1 ]
ret i32 %17
}