#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 SMBWrite(int, int /*<<< orphan*/, int, unsigned char *, unsigned int);
int writeRam(int address, unsigned int size, unsigned char *buf) {
  int status, i;
  unsigned char block[0xFF];
  block[0] = 0x16;
  block[1] = 0xFD;
  block[2] = address & 0xFF;
  block[3] = (address >> 8) & 0xFF;
  block[4] = (address >> 16) & 0xFF;
  block[5] = size & 0xFF;
  block[6] = (size >> 8) & 0xFF;
  status = SMBWrite(1, 0, 0, block, 7);
  if (status < 0)
    return status;
  status = SMBWrite(0, 0, 1, buf, size);
  return status;
}


x86 assembly (clang, -O0):
<writeRam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x16,-0x120(%rbp)
movb   $0xfd,-0x11f(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11e(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x11d(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x11c(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11b(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x11a(%rbp)
lea    -0x120(%rbp),%rcx
mov    $0x1,%edi
xor    %edx,%edx
mov    $0x7,%r8d
mov    %edx,%esi
call   1030 <SMBWrite@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b5 <writeRam+0xa5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <writeRam+0xc4>
mov    -0x18(%rbp),%rcx
mov    -0xc(%rbp),%r8d
xor    %esi,%esi
mov    $0x1,%edx
mov    %esi,%edi
call   1030 <SMBWrite@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeRam>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%eax
movw   $0xfd16,(%rsp)
mov    %al,0x2(%rsp)
mov    %ah,0x3(%rsp)
shr    $0x10,%eax
mov    %al,0x4(%rsp)
mov    %bl,0x5(%rsp)
mov    %bh,0x6(%rsp)
mov    %rsp,%rcx
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x7,%r8d
call   1030 <SMBWrite@plt>
test   %eax,%eax
js     116d <writeRam+0x5d>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
call   1030 <SMBWrite@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @writeRam(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [255 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
store i8 22, i8* %11
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 1
store i8 -3, i8* %12
%13 = load i32, i32* %5
%14 = and i32 %13, 255
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 2
store i8 %15, i8* %16
%17 = load i32, i32* %5
%18 = ashr i32 %17, 8
%19 = and i32 %18, 255
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 3
store i8 %20, i8* %21
%22 = load i32, i32* %5
%23 = ashr i32 %22, 16
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 4
store i8 %25, i8* %26
%27 = load i32, i32* %6
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 5
store i8 %29, i8* %30
%31 = load i32, i32* %6
%32 = lshr i32 %31, 8
%33 = and i32 %32, 255
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 6
store i8 %34, i8* %35
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%37 = call i32 @SMBWrite(i32 1, i32 0, i32 0, i8* %36, i32 7)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %3
%41 = load i32, i32* %8
store i32 %41, i32* %4
br label %47
42: ; preds = %3
%43 = load i8*, i8** %7
%44 = load i32, i32* %6
%45 = call i32 @SMBWrite(i32 0, i32 0, i32 1, i8* %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
store i32 %46, i32* %4
br label %47
47: ; preds = %42, %40
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @writeRam(i32 %0, i32 %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
store i8 22, i8* %5
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 1
store i8 -3, i8* %6
%7 = trunc i32 %0 to i8
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 2
store i8 %7, i8* %8
%9 = lshr i32 %0, 8
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 3
store i8 %10, i8* %11
%12 = lshr i32 %0, 16
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 4
store i8 %13, i8* %14
%15 = trunc i32 %1 to i8
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 5
store i8 %15, i8* %16
%17 = lshr i32 %1, 8
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 6
store i8 %18, i8* %19
%20 = call i32 @SMBWrite(i32 1, i32 0, i32 0, i8* %5, i32 7)
%21 = icmp slt i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %3
%23 = call i32 @SMBWrite(i32 0, i32 0, i32 1, i8* %2, i32 %1)
br label %24
24: ; preds = %3, %22
%25 = phi i32 [ %23, %22 ], [ %20, %3 ]
ret i32 %25
}