#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;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, int const *, unsigned int);
int realtek_mst_i2c_spi_write_data(int, int, int *, unsigned int);
int realtek_mst_i2c_spi_write_page(int fd, uint8_t reg, const uint8_t *buf,
                                   unsigned int len) {
  uint8_t wbuf[256 + 1] = {0x70};
  if (len > 256)
    return -1;
  memcpy(&wbuf[1], buf, len);
  return realtek_mst_i2c_spi_write_data(fd, (0x94 >> 1), wbuf, len + 1);
}


x86 assembly (clang, -O0):
<realtek_mst_i2c_spi_write_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x404,%edx
call   1040 <memset@plt>
movl   $0x70,-0x420(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jbe    117e <realtek_mst_i2c_spi_write_page+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <realtek_mst_i2c_spi_write_page+0x82>
lea    -0x420(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    $0x4a,%esi
call   1030 <realtek_mst_i2c_spi_write_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

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

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

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