#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_SLAVE;
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned char);
int write(int, unsigned char *, int);
int I2CSensor_Write(int *bus, unsigned char I2CAddress, unsigned char registry,
                    unsigned char value) {
  unsigned char tbuffer[2] = {registry, value};
  if (ioctl(*bus, I2C_SLAVE, I2CAddress) < 0)
    return 4;
  if (write(*bus, tbuffer, 2) != 2)
    return 4;
  return 0;
}


x86 assembly (clang, -O0):
<I2CSensor_Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %cl,-0x12(%rbp)
mov    %al,-0x13(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
movzbl -0x11(%rbp),%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1176 <I2CSensor_Write+0x56>
movl   $0x4,-0x4(%rbp)
jmp    11a6 <I2CSensor_Write+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x15(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     119f <I2CSensor_Write+0x7f>
movl   $0x4,-0x4(%rbp)
jmp    11a6 <I2CSensor_Write+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CSensor_Write>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %rdi,%rbx
mov    %dl,0xe(%rsp)
mov    %cl,0xf(%rsp)
mov    (%rdi),%edi
mov    0x2ead(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1169 <I2CSensor_Write+0x49>
mov    (%rbx),%edi
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
setne  %al
shl    $0x2,%eax
jmp    116e <I2CSensor_Write+0x4e>
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@I2C_SLAVE = global i32 0
define i32 @I2CSensor_Write(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 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%12 = load i8, i8* %8
store i8 %12, i8* %11
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = load i8, i8* %9
store i8 %14, i8* %13
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = load i32, i32* @I2C_SLAVE
%18 = load i8, i8* %7
%19 = call i64 @ioctl(i32 %16, i32 %17, i8 zeroext %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 4, i32* %5
br label %30
22: ; preds = %4
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 2)
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 4, i32* %5
br label %30
29: ; preds = %22
store i32 0, i32* %5
br label %30
30: ; preds = %29, %28, %21
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@I2C_SLAVE = global i32 0
define i32 @I2CSensor_Write(i32* nocapture %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
store i8 %2, i8* %6
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %3, i8* %7
%8 = load i32, i32* %0
%9 = load i32, i32* @I2C_SLAVE
%10 = tail call i64 @ioctl(i32 %8, i32 %9, i8 zeroext %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = load i32, i32* %0
%14 = call i32 @write(i32 %13, i8* %6, i32 2)
%15 = icmp eq i32 %14, 2
%16 = select i1 %15, i32 0, i32 4
br label %17
17: ; preds = %12, %4
%18 = phi i32 [ 4, %4 ], [ %16, %12 ]
ret i32 %18
}