#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 u_int32_t;
struct erase_info_user {
  int start;
  int length;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int memerase(int, struct erase_info_user *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int erase_flash(int fd, u_int32_t offset, u_int32_t bytes) {
  int err;
  struct erase_info_user erase;
  erase.start = offset;
  erase.length = bytes;
  err = memerase(fd, &erase);
  if (err < 0) {
    perror("MEMERASE");
    return (1);
  }
  fprintf(stderr, "Erased %d bytes from address 0x%.8x in flash\n", bytes,
          offset);
  return (0);
}


x86 assembly (clang, -O0):
<erase_flash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <memerase@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117e <erase_flash+0x4e>
lea    0xe93(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a0 <erase_flash+0x70>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe75(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erase_flash>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    %rsp,%rsi
call   1040 <memerase@plt>
test   %eax,%eax
js     116c <erase_flash+0x3c>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    1165 <erase_flash+0x35>

LLVM IR (-O0):
%struct.erase_info_user = type { i32, i32 }
@.str = [9 x i8] c"MEMERASE\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Erased %d bytes from address 0x%.8x in flash\0A\00"
define i32 @erase_flash(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.erase_info_user
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %9, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* %7
%13 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %9, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %5
%15 = call i32 @memerase(i32 %14, %struct.erase_info_user* %9)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %25
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23)
store i32 0, i32* %4
br label %25
25: ; preds = %20, %18
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.erase_info_user = type { i32, i32 }
@.str = [9 x i8] c"MEMERASE\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"Erased %d bytes from address 0x%.8x in flash\0A\00"
define i32 @erase_flash(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.erase_info_user
%5 = bitcast %struct.erase_info_user* %4 to i8*
%6 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %4, i64 0, i32 1
store i32 %2, i32* %7
%8 = call i32 @memerase(i32 %0, %struct.erase_info_user* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %1)
br label %15
15: ; preds = %12, %10
%16 = phi i32 [ 1, %10 ], [ 0, %12 ]
ret i32 %16
}