#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 */

/* Variables and functions */
int /*<<< orphan*/ i2c_set_address(int, unsigned char);
int write(int, unsigned char *, int);
int i2c_write_byte(int device, unsigned char device_addr,
                   unsigned char reg_addr, unsigned char byte) {
  unsigned char buf[2];
  i2c_set_address(device, device_addr);
  buf[0] = reg_addr;
  buf[1] = byte;
  if (write(device, buf, 2) != 2)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<i2c_write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %edi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%edi
movzbl -0x9(%rbp),%esi
call   1040 <i2c_set_address@plt>
mov    -0xa(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1179 <i2c_write_byte+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <i2c_write_byte+0x60>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_byte>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %edi,%ebx
call   1040 <i2c_set_address@plt>
mov    %bpl,0xe(%rsp)
mov    %r14b,0xf(%rsp)
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @i2c_write_byte(i32 %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca [2 x i8]
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @i2c_set_address(i32 %0, i8 zeroext %1)
store i8 %2, i8* %6
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %3, i8* %8
%9 = call i32 @write(i32 %0, i8* %6, i32 2)
%10 = icmp ne i32 %9, 2
%11 = sext i1 %10 to i32
ret i32 %11
}