#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 i2c_write(int, unsigned char);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char **, int);
int i2c_read_register(int fd, unsigned char read_addr,
                      unsigned char *read_data) {
  int ret = 0;
  if (i2c_write(fd, read_addr) == -1) {
    perror("I2C: Failed to write |");
    return -1;
  }
  ret = read(fd, &read_data, 1);
  if (ret == -1)
    perror("I2C: Failed to read |");
  if (ret == 0)
    perror("I2C: End of FILE |");
  return (ret);
}


x86 assembly (clang, -O0):
<i2c_read_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%esi
call   1040 <i2c_write@plt>
cmp    $0xffffffff,%eax
jne    1179 <i2c_read_register+0x49>
lea    0xe98(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <i2c_read_register+0x8f>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a3 <i2c_read_register+0x73>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11b9 <i2c_read_register+0x89>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read_register>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rdx,0x8(%rsp)
call   1040 <i2c_write@plt>
cmp    $0xffffffff,%eax
je     116a <i2c_read_register+0x3a>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1178 <i2c_read_register+0x48>
test   %ebx,%ebx
je     1181 <i2c_read_register+0x51>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0xffffffff,%ebx
lea    0xe8a(%rip),%rdi
jmp    118a <i2c_read_register+0x5a>
lea    0xe98(%rip),%rdi
jmp    118a <i2c_read_register+0x5a>
xor    %ebx,%ebx
lea    0xea3(%rip),%rdi
call   1050 <perror@plt>
jmp    1162 <i2c_read_register+0x32>

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

LLVM IR (-O2):
@.str = [23 x i8] c"I2C: Failed to write |\00"
@.str.1 = [22 x i8] c"I2C: Failed to read |\00"
@.str.2 = [19 x i8] c"I2C: End of FILE |\00"
define i32 @i2c_read_register(i32 %0, i8 zeroext %1, i8* %2) {
%4 = alloca i8*
store i8* %2, i8** %4
%5 = tail call i32 @i2c_write(i32 %0, i8 zeroext %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = call i32 @read(i32 %0, i8** %4, i32 1)
switch i32 %8, label %14 [
i32 -1, label %10
i32 0, label %9
]
9: ; preds = %7
br label %10
10: ; preds = %7, %3, %9
%11 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %7 ]
%12 = phi i32 [ 0, %9 ], [ -1, %3 ], [ %8, %7 ]
%13 = tail call i32 @perror(i8* %11)
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ %8, %7 ], [ %12, %10 ]
ret i32 %15
}