#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*/ perror(char *);
int /*<<< orphan*/ setI2cAddress(int, unsigned char);
int write(int, unsigned char *, int);
unsigned int I2CWriteReg16(int fd, unsigned char i2cAddress,
                           unsigned char i2cReg, unsigned int data) {
  unsigned char I2C_WR_Buf[8];
  setI2cAddress(fd, i2cAddress);
  I2C_WR_Buf[0] = i2cReg;
  I2C_WR_Buf[1] = (data >> 8) & 0xff;
  I2C_WR_Buf[2] = data & 0xff;
  if (write(fd, I2C_WR_Buf, 3) != 3) {
    perror("Write Error");
  }
  return 0;
}


x86 assembly (clang, -O0):
<I2CWriteReg16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %edi,-0x4(%rbp)
mov    %dl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    %ecx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
call   1030 <setI2cAddress@plt>
mov    -0x6(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
cmp    $0x3,%eax
je     119a <I2CWriteReg16+0x6a>
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWriteReg16>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %edi,%ebp
call   1030 <setI2cAddress@plt>
mov    %r14b,0x8(%rsp)
mov    %bh,0x9(%rsp)
mov    %bl,0xa(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3,%edx
call   1040 <write@plt>
cmp    $0x3,%eax
jne    1172 <I2CWriteReg16+0x42>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
jmp    1167 <I2CWriteReg16+0x37>

LLVM IR (-O0):
@.str = [12 x i8] c"Write Error\00"
define i32 @I2CWriteReg16(i32 %0, i8 zeroext %1, i8 zeroext %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca [8 x i8]
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i8, i8* %6
%12 = call i32 @setI2cAddress(i32 %10, i8 zeroext %11)
%13 = load i8, i8* %7
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i32, i32* %8
%16 = lshr i32 %15, 8
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 1
store i8 %18, i8* %19
%20 = load i32, i32* %8
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 2
store i8 %22, i8* %23
%24 = load i32, i32* %5
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 3)
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %30
28: ; preds = %4
%29 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %4
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Write Error\00"
define i32 @I2CWriteReg16(i32 %0, i8 zeroext %1, i8 zeroext %2, i32 %3) {
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @setI2cAddress(i32 %0, i8 zeroext %1)
store i8 %2, i8* %6
%8 = lshr i32 %3, 8
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
store i8 %9, i8* %10
%11 = trunc i32 %3 to i8
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 2
store i8 %11, i8* %12
%13 = call i32 @write(i32 %0, i8* %6, i32 3)
%14 = icmp eq i32 %13, 3
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
ret i32 0
}