#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_registers(int fd, int num, unsigned char starting_addr,
                       unsigned char *buff_Ptr) {
  int ret = 0;
  if (i2c_write(fd, starting_addr) == -1) {
    perror("I2C: Failed to write |");
    return -1;
  }
  ret = read(fd, buff_Ptr, num);
  if (ret == -1)
    perror("I2C: Failed to read |");
  if (ret == 0)
    perror("I2C: End of FILE |");
  return (ret);
}


x86 assembly (clang, -O0):
<i2c_read_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
movzbl -0xd(%rbp),%esi
call   1040 <i2c_write@plt>
cmp    $0xffffffff,%eax
jne    117b <i2c_read_registers+0x4b>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <i2c_read_registers+0x8f>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a3 <i2c_read_registers+0x73>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11b9 <i2c_read_registers+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_registers>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
mov    %edx,%esi
call   1040 <i2c_write@plt>
cmp    $0xffffffff,%eax
je     1165 <i2c_read_registers+0x35>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1173 <i2c_read_registers+0x43>
test   %ebx,%ebx
je     117c <i2c_read_registers+0x4c>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%ebx
lea    0xe8f(%rip),%rdi
jmp    1185 <i2c_read_registers+0x55>
lea    0xe9d(%rip),%rdi
jmp    1185 <i2c_read_registers+0x55>
xor    %ebx,%ebx
lea    0xea8(%rip),%rdi
call   1050 <perror@plt>
jmp    115e <i2c_read_registers+0x2e>

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_registers(i32 %0, i32 %1, i8 zeroext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i32 0, i32* %10
%11 = load i32, i32* %6
%12 = load i8, i8* %8
%13 = call i32 @i2c_write(i32 %11, i8 zeroext %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %33
17: ; preds = %4
%18 = load i32, i32* %6
%19 = load i8*, i8** %9
%20 = load i32, i32* %7
%21 = call i32 @read(i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %10
store i32 %32, i32* %5
br label %33
33: ; preds = %31, %15
%34 = load i32, i32* %5
ret i32 %34
}

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_registers(i32 %0, i32 %1, i8 zeroext %2, i8* nocapture %3) {
%5 = tail call i32 @i2c_write(i32 %0, i8 zeroext %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @read(i32 %0, i8* %3, i32 %1)
switch i32 %8, label %14 [
i32 -1, label %10
i32 0, label %9
]
9: ; preds = %7
br label %10
10: ; preds = %7, %4, %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), %4 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %7 ]
%12 = phi i32 [ 0, %9 ], [ -1, %4 ], [ %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
}