#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*/ printf(char *);
int write(int, int *, int);
int write_i2c_reg(int file_i2c, uint8_t reg, uint16_t data) {
  uint8_t writebuffer[3];
  writebuffer[0] = reg;
  writebuffer[1] = (data >> 8);
  writebuffer[2] = data;
  if (write(file_i2c, writebuffer, 3) != 3) {
    printf("Failed to write to the i2c bus.\n");
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<write_i2c_reg>:
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
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     1178 <write_i2c_reg+0x58>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <write_i2c_reg+0x5f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_i2c_reg>:
sub    $0x18,%rsp
mov    %esi,0xc(%rsp)
mov    %edx,%eax
sar    $0x8,%eax
mov    %eax,0x10(%rsp)
mov    %edx,0x14(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
je     115e <write_i2c_reg+0x3e>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Failed to write to the i2c bus.\0A\00"
define i32 @write_i2c_reg(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
store i32 %9, i32* %10
%11 = load i32, i32* %7
%12 = ashr i32 %11, 8
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
store i32 %12, i32* %13
%14 = load i32, i32* %7
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
store i32 %14, i32* %15
%16 = load i32, i32* %5
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%18 = call i32 @write(i32 %16, i32* %17, i32 3)
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %23
22: ; preds = %3
store i32 0, i32* %4
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@str = [32 x i8] c"Failed to write to the i2c bus.\00"
define i32 @write_i2c_reg(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 = ashr i32 %2, 8
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
store i32 %7, i32* %8
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
store i32 %2, i32* %9
%10 = call i32 @write(i32 %0, i32* %6, i32 3)
%11 = icmp eq i32 %10, 3
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %3, %12
%15 = phi i32 [ -1, %12 ], [ 0, %3 ]
ret i32 %15
}