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

/* Variables and functions */
int read(int, void *, int);
int write(int, int /*<<< orphan*/ *, int);
int I2C_readTransaction(int i2c_fd, uint8_t command, void *rx_buffer,
                        int n_bytes) {
  int ret;
  ret = write(i2c_fd, &command, 1);
  if (ret < 0)
    return ret;
  ret = read(i2c_fd, rx_buffer, n_bytes);
  if (ret < 0)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<I2C_readTransaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    115e <I2C_readTransaction+0x3e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <I2C_readTransaction+0x6c>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1185 <I2C_readTransaction+0x65>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <I2C_readTransaction+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2C_readTransaction>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %edi,%ebp
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %eax,%eax
js     115b <I2C_readTransaction+0x3b>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <read@plt>
mov    %eax,%ecx
sar    $0x1f,%eax
and    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @I2C_readTransaction(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = call i32 @write(i32 %11, i32* %7, i32 1)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i32, i32* %10
store i32 %16, i32* %5
br label %27
17: ; preds = %4
%18 = load i32, i32* %6
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = call i32 @read(i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %27
26: ; preds = %17
store i32 0, i32* %5
br label %27
27: ; preds = %26, %24, %15
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
define i32 @I2C_readTransaction(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
store i32 %1, i32* %5
%6 = call i32 @write(i32 %0, i32* %5, i32 1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i32 @read(i32 %0, i8* %2, i32 %3)
%10 = icmp slt i32 %9, 0
%11 = select i1 %10, i32 %9, i32 0
br label %12
12: ; preds = %8, %4
%13 = phi i32 [ %6, %4 ], [ %11, %8 ]
ret i32 %13
}