#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 /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned int);
int write(int, unsigned char *, unsigned int);
int ee24c02_write_page(int file, unsigned char address, unsigned char *data,
                       unsigned int len) {
  unsigned char buffer[9];
  if (len > 8)
    return -1;
  buffer[0] = address;
  memcpy(buffer + 1, data, len);
  return write(file, buffer, len + 1) - 1;
}


x86 assembly (clang, -O0):
<ee24c02_write_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jbe    114e <ee24c02_write_page+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <ee24c02_write_page+0x60>
mov    -0x9(%rbp),%al
mov    %al,-0x25(%rbp)
lea    -0x25(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1030 <write@plt>
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ee24c02_write_page>:
mov    $0xffffffff,%eax
cmp    $0x8,%ecx
ja     1162 <ee24c02_write_page+0x42>
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edi,%ebp
mov    %sil,0xf(%rsp)
lea    0x10(%rsp),%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1040 <memcpy@plt>
add    $0x1,%ebx
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <write@plt>
add    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ee24c02_write_page(i32 %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [9 x i8]
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = icmp ugt i32 %11, 8
br i1 %12, label %13, label %14
13: ; preds = %4
store i32 -1, i32* %5
br label %28
14: ; preds = %4
%15 = load i8, i8* %7
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
store i8 %15, i8* %16
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %6
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%24 = load i32, i32* %9
%25 = add i32 %24, 1
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %5
br label %28
28: ; preds = %14, %13
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @ee24c02_write_page(i32 %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca [9 x i8]
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%7 = icmp ugt i32 %3, 8
br i1 %7, label %14, label %8
8: ; preds = %4
store i8 %1, i8* %6
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 1
%10 = call i32 @memcpy(i8* %9, i8* %2, i32 %3)
%11 = add nuw nsw i32 %3, 1
%12 = call i32 @write(i32 %0, i8* %6, i32 %11)
%13 = add nsw i32 %12, -1
br label %14
14: ; preds = %4, %8
%15 = phi i32 [ %13, %8 ], [ -1, %4 ]
ret i32 %15
}