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


x86 assembly (clang, -O0):
<I2CWriteReg8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %edi,-0x4(%rbp)
mov    %dl,-0x5(%rbp)
mov    %cl,-0x6(%rbp)
mov    %al,-0x7(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
call   1030 <setI2cAddress@plt>
mov    -0x6(%rbp),%al
mov    %al,-0xf(%rbp)
mov    -0x7(%rbp),%al
mov    %al,-0xe(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     1189 <I2CWriteReg8+0x59>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWriteReg8>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %edi,%ebx
call   1030 <setI2cAddress@plt>
mov    %bpl,0x8(%rsp)
mov    %r14b,0x9(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
jne    116f <I2CWriteReg8+0x3f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    1164 <I2CWriteReg8+0x34>

LLVM IR (-O0):
@.str = [12 x i8] c"Write Error\00"
define i32 @I2CWriteReg8(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca [8 x i8]
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i8 %3, i8* %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 i8, i8* %8
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 1
store i8 %15, i8* %16
%17 = load i32, i32* %5
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 2)
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %4
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Write Error\00"
define i32 @I2CWriteReg8(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %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 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
store i8 %3, i8* %8
%9 = call i32 @write(i32 %0, i8* %6, i32 2)
%10 = icmp eq i32 %9, 2
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
ret i32 0
}