#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ __rbeu08(int *);
int i2c_transact(int, int, int *, int, int);
int i2c_read_beuint08(int fd, int chip_addr, int reg, uint8_t *value) {
  uint8_t data[sizeof(uint8_t)];
  data[0] = reg;
  int err = i2c_transact(fd, chip_addr, data, 1, sizeof(uint8_t));
  if (err == sizeof(uint8_t))
    *value = (uint8_t)__rbeu08(data);
  return err;
}


x86 assembly (clang, -O0):
<i2c_read_beuint08>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdx
mov    $0x1,%ecx
mov    $0x4,%r8d
call   1030 <i2c_transact@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x4,%rax
jne    1177 <i2c_read_beuint08+0x57>
lea    -0x30(%rbp),%rdi
call   1040 <__rbeu08@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read_beuint08>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,(%rsp)
mov    %rsp,%rdx
mov    $0x1,%ecx
mov    $0x4,%r8d
call   1030 <i2c_transact@plt>
mov    %eax,%ebp
cmp    $0x4,%eax
jne    1150 <i2c_read_beuint08+0x30>
mov    %rsp,%rdi
call   1040 <__rbeu08@plt>
mov    %eax,(%rbx)
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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