#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 /*<<< orphan*/ perror(char *);
int write(int, int /*<<< orphan*/ *, int);
int i2c_write_byte(int file, uint8_t reg_addr, uint8_t data) {
  int res;
  uint8_t buf[2] = {reg_addr, data};
  if ((res = write(file, buf, 2)) < 0) {
    perror("write() register address / data failed");
    return res;
  }
  return 0;
}


x86 assembly (clang, -O0):
<i2c_write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1171 <i2c_write_byte+0x51>
lea    0xe9f(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <i2c_write_byte+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_byte>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,0x8(%rsp)
mov    %edx,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
js     114a <i2c_write_byte+0x2a>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xeaf(%rip),%rdi
call   1040 <perror@plt>
mov    %ebx,%eax
jmp    1144 <i2c_write_byte+0x24>

LLVM IR (-O0):
@.str = [39 x i8] c"write() register address / data failed\00"
define i32 @i2c_write_byte(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%11 = load i32, i32* %6
store i32 %11, i32* %10
%12 = getelementptr inbounds i32, i32* %10, i64 1
%13 = load i32, i32* %7
store i32 %13, i32* %12
%14 = load i32, i32* %5
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%16 = call i32 @write(i32 %14, i32* %15, i32 2)
store i32 %16, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %8
store i32 %20, i32* %4
br label %22
21: ; preds = %3
store i32 0, i32* %4
br label %22
22: ; preds = %21, %18
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [39 x i8] c"write() register address / data failed\00"
define i32 @i2c_write_byte(i32 %0, i32 %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 %1, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 %2, i32* %7
%8 = call i32 @write(i32 %0, i32* %6, i32 2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %3, %10
%13 = phi i32 [ %8, %10 ], [ 0, %3 ]
ret i32 %13
}