#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;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int write(int, int *, int);
int i2c_write_byte(int file, uint8_t reg_addr, uint16_t data) {
  int res;
  uint8_t buf[3] = {reg_addr, (data >> 8), (data & 0xff)};
  if ((res = write(file, buf, 3)) < 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,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    117f <i2c_write_byte+0x5f>
lea    0xe91(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <i2c_write_byte+0x66>
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,0x4(%rsp)
movzbl %dl,%eax
sar    $0x8,%edx
mov    %edx,0x8(%rsp)
mov    %eax,0xc(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
js     1154 <i2c_write_byte+0x34>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xea5(%rip),%rdi
call   1040 <perror@plt>
mov    %ebx,%eax
jmp    114e <i2c_write_byte+0x2e>

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 [3 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = getelementptr inbounds [3 x i32], [3 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
%14 = ashr i32 %13, 8
store i32 %14, i32* %12
%15 = getelementptr inbounds i32, i32* %12, i64 1
%16 = load i32, i32* %7
%17 = and i32 %16, 255
store i32 %17, i32* %15
%18 = load i32, i32* %5
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%20 = call i32 @write(i32 %18, i32* %19, i32 3)
store i32 %20, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %26
25: ; preds = %3
store i32 0, i32* %4
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %4
ret i32 %27
}

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 [3 x i32]
%5 = bitcast [3 x i32]* %4 to i8*
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
store i32 %1, i32* %6
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%8 = ashr i32 %2, 8
store i32 %8, i32* %7
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%10 = and i32 %2, 255
store i32 %10, i32* %9
%11 = call i32 @write(i32 %0, i32* %6, i32 3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %3, %13
%16 = phi i32 [ %11, %13 ], [ 0, %3 ]
ret i32 %16
}