#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*/ I2CStart();
int /*<<< orphan*/ I2CStop();
int /*<<< orphan*/ I2CWriteAck(unsigned char);
unsigned char I2CWriteByte(unsigned char device_addr, unsigned char reg_addr,
                           unsigned char data) {
  unsigned char error = 0;
  I2CStart();
  error += !I2CWriteAck((device_addr << 1) | 0);
  error += !I2CWriteAck(reg_addr);
  error += !I2CWriteAck(data);
  I2CStop();
  return error;
}


x86 assembly (clang, -O0):
<I2CWriteByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <I2CStart@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
or     $0x0,%eax
movzbl %al,%edi
call   1050 <I2CWriteAck@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
movzbl -0x4(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x4(%rbp)
movzbl -0x2(%rbp),%edi
call   1050 <I2CWriteAck@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
movzbl -0x4(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x4(%rbp)
movzbl -0x3(%rbp),%edi
call   1050 <I2CWriteAck@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
movzbl -0x4(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x4(%rbp)
mov    $0x0,%al
call   1030 <I2CStop@plt>
movzbl -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWriteByte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <I2CStart@plt>
add    %bl,%bl
movzbl %bl,%edi
call   1050 <I2CWriteAck@plt>
mov    %eax,%ebp
mov    %r15d,%edi
call   1050 <I2CWriteAck@plt>
test   %eax,%eax
sete   %bl
cmp    $0x1,%ebp
adc    $0x0,%bl
mov    %r14d,%edi
call   1050 <I2CWriteAck@plt>
cmp    $0x1,%eax
adc    $0x0,%bl
xor    %eax,%eax
call   1030 <I2CStop@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @I2CWriteByte(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
store i8 0, i8* %7
%8 = call i32 (...) @I2CStart()
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = shl i32 %10, 1
%12 = or i32 %11, 0
%13 = trunc i32 %12 to i8
%14 = call i32 @I2CWriteAck(i8 zeroext %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
%18 = load i8, i8* %7
%19 = zext i8 %18 to i32
%20 = add nsw i32 %19, %17
%21 = trunc i32 %20 to i8
store i8 %21, i8* %7
%22 = load i8, i8* %5
%23 = call i32 @I2CWriteAck(i8 zeroext %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
%27 = load i8, i8* %7
%28 = zext i8 %27 to i32
%29 = add nsw i32 %28, %26
%30 = trunc i32 %29 to i8
store i8 %30, i8* %7
%31 = load i8, i8* %6
%32 = call i32 @I2CWriteAck(i8 zeroext %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
%36 = load i8, i8* %7
%37 = zext i8 %36 to i32
%38 = add nsw i32 %37, %35
%39 = trunc i32 %38 to i8
store i8 %39, i8* %7
%40 = call i32 (...) @I2CStop()
%41 = load i8, i8* %7
ret i8 %41
}

LLVM IR (-O2):
define zeroext i8 @I2CWriteByte(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = tail call i32 (...) @I2CStart()
%5 = shl i8 %0, 1
%6 = tail call i32 @I2CWriteAck(i8 zeroext %5)
%7 = icmp eq i32 %6, 0
%8 = tail call i32 @I2CWriteAck(i8 zeroext %1)
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i8
%11 = zext i1 %7 to i8
%12 = add nuw nsw i8 %10, %11
%13 = tail call i32 @I2CWriteAck(i8 zeroext %2)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i8
%16 = add nuw nsw i8 %12, %15
%17 = tail call i32 (...) @I2CStop()
ret i8 %16
}