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

/* Variables and functions */
int /*<<< orphan*/ MEMERASE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct erase_info_user *);
int /*<<< orphan*/ stderr;
void erase_flash(int fd) {
  struct erase_info_user ei;
  ei.start = 0;
  ei.length = 0x2000;
  if (ioctl(fd, MEMERASE, &ei) != 0)
    fprintf(stderr, "error erasing flash\n");
}


x86 assembly (clang, -O0):
<erase_flash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x2000,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     116e <erase_flash+0x4e>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erase_flash>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movl   $0x2000,0x8(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
je     1162 <erase_flash+0x42>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.erase_info_user = type { i32, i64 }
@MEMERASE = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"error erasing flash\0A\00"
define void @erase_flash(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.erase_info_user
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %3, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %3, i32 0, i32 0
store i32 8192, i32* %5
%6 = load i32, i32* %2
%7 = load i32, i32* @MEMERASE
%8 = call i64 @ioctl(i32 %6, i32 %7, %struct.erase_info_user* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
%struct.erase_info_user = type { i32, i64 }
@MEMERASE = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"error erasing flash\0A\00"
define void @erase_flash(i32 %0) {
%2 = alloca %struct.erase_info_user
%3 = bitcast %struct.erase_info_user* %2 to i8*
%4 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %2, i64 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.erase_info_user, %struct.erase_info_user* %2, i64 0, i32 0
store i32 8192, i32* %5
%6 = load i32, i32* @MEMERASE
%7 = call i64 @ioctl(i32 %0, i32 %6, %struct.erase_info_user* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %1
ret void
}