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


x86 assembly (clang, -O0):
<I2CReadReg8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x4(%rbp)
mov    %cl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
mov    %al,-0xe(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
call   1030 <setI2cAddress@plt>
mov    -0x4(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     118e <I2CReadReg8+0x4e>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x8,%eax
je     11b4 <I2CReadReg8+0x74>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
movzbl -0x16(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CReadReg8>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %dl,0x8(%rsp)
call   1030 <setI2cAddress@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    1183 <I2CReadReg8+0x43>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x8,%eax
jne    1191 <I2CReadReg8+0x51>
mov    (%rsp),%al
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
jmp    1166 <I2CReadReg8+0x26>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
jmp    117a <I2CReadReg8+0x3a>

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

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