#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 */
scalar_t__ i2c_read(unsigned char *, int);
scalar_t__ i2c_write(unsigned char *, int);
int register_read(unsigned char reg, unsigned char *data) {
  int rc = -1;
  unsigned char bite[4];
  bite[0] = reg;
  if (i2c_write(bite, 1) == 0) {
    if (i2c_read(bite, 1) == 0) {
      *data = bite[0];
      rc = 0;
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<register_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <i2c_write@plt>
cmp    $0x0,%rax
jne    1184 <register_read+0x64>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <i2c_read@plt>
cmp    $0x0,%rax
jne    117f <register_read+0x5f>
mov    -0x18(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x0,-0x14(%rbp)
jmp    1184 <register_read+0x64>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %dil,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
call   1040 <i2c_write@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1160 <register_read+0x40>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
call   1030 <i2c_read@plt>
test   %rax,%rax
jne    1160 <register_read+0x40>
mov    0x4(%rsp),%al
mov    %al,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @register_read(i8 zeroext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4 x i8]
store i8 %0, i8* %3
store i8* %1, i8** %4
store i32 -1, i32* %5
%7 = load i8, i8* %3
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %7, i8* %8
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%10 = call i64 @i2c_write(i8* %9, i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%14 = call i64 @i2c_read(i8* %13, i32 1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%18 = load i8, i8* %17
%19 = load i8*, i8** %4
store i8 %18, i8* %19
store i32 0, i32* %5
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20, %2
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
define i32 @register_read(i8 zeroext %0, i8* nocapture writeonly %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
store i8 %0, i8* %4
%5 = call i64 @i2c_write(i8* %4, i32 1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = call i64 @i2c_read(i8* %4, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i8, i8* %4
store i8 %11, i8* %1
br label %12
12: ; preds = %7, %10, %2
%13 = phi i32 [ 0, %10 ], [ -1, %7 ], [ -1, %2 ]
ret i32 %13
}