#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 */
typedef int uint8_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ erase_sector(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int get_status(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int /*<<< orphan*/ set_blocksize(int, int, scalar_t__);
int /*<<< orphan*/ set_startaddress(int, int, scalar_t__);
int /*<<< orphan*/ stderr;
void erase_block(int s, uint8_t module_id, uint32_t startaddr, uint32_t blksz) {
  uint8_t status;
  printf("erasing block at startaddr 0x%06X with block size 0x%06X\n",
         (unsigned int)startaddr, (unsigned int)blksz);
  set_startaddress(s, module_id, startaddr);
  status = get_status(s, module_id, NULL);
  if (status != ((1 << 6) | (1 << 0))) {
    fprintf(stderr, "erase1 - wrong status %02X!\n", status);
    exit(1);
  }
  set_blocksize(s, module_id, blksz);
  status = get_status(s, module_id, NULL);
  if (status != ((1 << 6) | (1 << 0) | (1 << 2))) {
    fprintf(stderr, "erase2 - wrong status %02X!\n", status);
    exit(1);
  }
  erase_sector(s, module_id);
  status = get_status(s, module_id, NULL);
  if (status != ((1 << 6) | (1 << 5))) {
    fprintf(stderr, "erase3 - wrong status %02X!\n", status);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<erase_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1080 <set_startaddress@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <get_status@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x41,-0x1c(%rbp)
je     11eb <erase_block+0x7b>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <set_blocksize@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <get_status@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x45,-0x1c(%rbp)
je     1238 <erase_block+0xc8>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <erase_sector@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <get_status@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x60,-0x1c(%rbp)
je     1281 <erase_block+0x111>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe02(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erase_block>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xe78(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15,%rdx
call   1080 <set_startaddress@plt>
mov    %ebp,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <get_status@plt>
cmp    $0x41,%eax
jne    11ef <erase_block+0x7f>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1040 <set_blocksize@plt>
mov    %ebp,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <get_status@plt>
cmp    $0x45,%eax
jne    1201 <erase_block+0x91>
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <erase_sector@plt>
mov    %ebp,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <get_status@plt>
cmp    $0x60,%eax
jne    1213 <erase_block+0xa3>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dea(%rip),%rcx
mov    (%rcx),%edi
lea    0xe3b(%rip),%rsi
jmp    1223 <erase_block+0xb3>
mov    0x2dd8(%rip),%rcx
mov    (%rcx),%edi
lea    0xe46(%rip),%rsi
jmp    1223 <erase_block+0xb3>
mov    0x2dc6(%rip),%rcx
mov    (%rcx),%edi
lea    0xe51(%rip),%rsi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [58 x i8] c"erasing block at startaddr 0x%06X with block size 0x%06X\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"erase1 - wrong status %02X!\0A\00"
@.str.2 = [29 x i8] c"erase2 - wrong status %02X!\0A\00"
@.str.3 = [29 x i8] c"erase3 - wrong status %02X!\0A\00"
define void @erase_block(i32 %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i64, i64* %7
%11 = trunc i64 %10 to i32
%12 = load i64, i64* %8
%13 = trunc i64 %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = load i64, i64* %7
%18 = call i32 @set_startaddress(i32 %15, i32 %16, i64 %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @get_status(i32 %19, i32 %20, i32* null)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 65
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = load i32, i32* %9
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %4
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = load i64, i64* %8
%33 = call i32 @set_blocksize(i32 %30, i32 %31, i64 %32)
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @get_status(i32 %34, i32 %35, i32* null)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 69
br i1 %38, label %39, label %44
39: ; preds = %29
%40 = load i32, i32* @stderr
%41 = load i32, i32* %9
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %29
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = call i32 @erase_sector(i32 %45, i32 %46)
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 @get_status(i32 %48, i32 %49, i32* null)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 96
br i1 %52, label %53, label %58
53: ; preds = %44
%54 = load i32, i32* @stderr
%55 = load i32, i32* %9
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %44
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"erasing block at startaddr 0x%06X with block size 0x%06X\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"erase1 - wrong status %02X!\0A\00"
@.str.2 = [29 x i8] c"erase2 - wrong status %02X!\0A\00"
@.str.3 = [29 x i8] c"erase3 - wrong status %02X!\0A\00"
define void @erase_block(i32 %0, i32 %1, i64 %2, i64 %3) {
%5 = trunc i64 %2 to i32
%6 = trunc i64 %3 to i32
%7 = tail call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 @set_startaddress(i32 %0, i32 %1, i64 %2)
%9 = tail call i32 @get_status(i32 %0, i32 %1, i32* null)
%10 = icmp eq i32 %9, 65
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
%16 = tail call i32 @set_blocksize(i32 %0, i32 %1, i64 %3)
%17 = tail call i32 @get_status(i32 %0, i32 %1, i32* null)
%18 = icmp eq i32 %17, 69
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = tail call i32 @erase_sector(i32 %0, i32 %1)
%25 = tail call i32 @get_status(i32 %0, i32 %1, i32* null)
%26 = icmp eq i32 %25, 96
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %23
ret void
}