#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 SMBWriteBlock(int, int, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int writeProgramBlock(int blockNr, unsigned char *buf) {
  int status;
  unsigned char block[0x62];
  block[0] = blockNr & 0xFF;
  block[1] = (blockNr >> 8) & 0xFF;
  memcpy(block + 2, buf, 0x60);
  status = SMBWriteBlock(0x16, 0x5, block, 0x62);
  usleep(200000);
  return (status > 0 ? status - 2 : status);
}


x86 assembly (clang, -O0):
<writeProgramBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x80(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x7f(%rbp)
lea    -0x80(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x60,%edx
call   1040 <memcpy@plt>
lea    -0x80(%rbp),%rdx
mov    $0x16,%edi
mov    $0x5,%esi
mov    $0x62,%ecx
call   1030 <SMBWriteBlock@plt>
mov    %eax,-0x14(%rbp)
mov    $0x30d40,%edi
call   1050 <usleep@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11b1 <writeProgramBlock+0x81>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x84(%rbp)
jmp    11ba <writeProgramBlock+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeProgramBlock>:
push   %rbx
sub    $0x70,%rsp
mov    %di,(%rsp)
lea    0x2(%rsp),%rdi
mov    $0x60,%edx
call   1040 <memcpy@plt>
mov    %rsp,%rdx
mov    $0x16,%edi
mov    $0x5,%esi
mov    $0x62,%ecx
call   1030 <SMBWriteBlock@plt>
mov    %eax,%ebx
mov    $0x30d40,%edi
call   1050 <usleep@plt>
lea    -0x2(%rbx),%eax
test   %ebx,%ebx
cmovle %ebx,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @writeProgramBlock(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [98 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = and i32 %7, 255
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [98 x i8], [98 x i8]* %6, i64 0, i64 0
store i8 %9, i8* %10
%11 = load i32, i32* %3
%12 = ashr i32 %11, 8
%13 = and i32 %12, 255
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [98 x i8], [98 x i8]* %6, i64 0, i64 1
store i8 %14, i8* %15
%16 = getelementptr inbounds [98 x i8], [98 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8*, i8** %4
%19 = call i32 @memcpy(i8* %17, i8* %18, i32 96)
%20 = getelementptr inbounds [98 x i8], [98 x i8]* %6, i64 0, i64 0
%21 = call i32 @SMBWriteBlock(i32 22, i32 5, i8* %20, i32 98)
store i32 %21, i32* %5
%22 = call i32 @usleep(i32 200000)
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 2
br label %30
28: ; preds = %2
%29 = load i32, i32* %5
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ %27, %25 ], [ %29, %28 ]
ret i32 %31
}

LLVM IR (-O2):
define i32 @writeProgramBlock(i32 %0, i8* %1) {
%3 = alloca [98 x i8]
%4 = getelementptr inbounds [98 x i8], [98 x i8]* %3, i64 0, i64 0
%5 = trunc i32 %0 to i8
store i8 %5, i8* %4
%6 = lshr i32 %0, 8
%7 = trunc i32 %6 to i8
%8 = getelementptr inbounds [98 x i8], [98 x i8]* %3, i64 0, i64 1
store i8 %7, i8* %8
%9 = getelementptr inbounds [98 x i8], [98 x i8]* %3, i64 0, i64 2
%10 = call i32 @memcpy(i8* %9, i8* %1, i32 96)
%11 = call i32 @SMBWriteBlock(i32 22, i32 5, i8* %4, i32 98)
%12 = call i32 @usleep(i32 200000)
%13 = icmp sgt i32 %11, 0
%14 = add nsw i32 %11, -2
%15 = select i1 %13, i32 %14, i32 %11
ret i32 %15
}