#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int lspcon_i2c_spi_write_data(int, int, int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          unsigned int);
int lspcon_i2c_spi_write_page(int fd, const uint8_t *buf, unsigned int len) {
  uint8_t write_buffer[256 + 1] = {0};
  if (len > 256)
    return -1;
  memcpy(&write_buffer[1], buf, len);
  return lspcon_i2c_spi_write_data(fd, (0x9e >> 1), write_buffer, len + 1);
}


x86 assembly (clang, -O0):
<lspcon_i2c_spi_write_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x404,%edx
call   1030 <memset@plt>
cmpl   $0x100,-0x14(%rbp)
jbe    1171 <lspcon_i2c_spi_write_page+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <lspcon_i2c_spi_write_page+0x75>
lea    -0x420(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rdx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    $0x4f,%esi
call   1040 <lspcon_i2c_spi_write_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lspcon_i2c_spi_write_page>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x404,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0xffffffff,%eax
cmp    $0x100,%ebx
ja     1183 <lspcon_i2c_spi_write_page+0x53>
lea    0x4(%rsp),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    $0x1,%ebx
mov    %rsp,%rdx
mov    %r14d,%edi
mov    $0x4f,%esi
mov    %ebx,%ecx
call   1040 <lspcon_i2c_spi_write_data@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lspcon_i2c_spi_write_page(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [257 x i32]
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = bitcast [257 x i32]* %8 to i8*
%10 = load i32, i32* %7
%11 = icmp ugt i32 %10, 256
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %23
13: ; preds = %3
%14 = getelementptr inbounds [257 x i32], [257 x i32]* %8, i64 0, i64 1
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = call i32 @memcpy(i32* %14, i32* %15, i32 %16)
%18 = load i32, i32* %5
%19 = getelementptr inbounds [257 x i32], [257 x i32]* %8, i64 0, i64 0
%20 = load i32, i32* %7
%21 = add i32 %20, 1
%22 = call i32 @lspcon_i2c_spi_write_data(i32 %18, i32 79, i32* %19, i32 %21)
store i32 %22, i32* %4
br label %23
23: ; preds = %13, %12
%24 = load i32, i32* %4
ret i32 %24
}

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