#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 /*<<< orphan*/ buff;

/* Variables and functions */
int errno;
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ usleep(int);
int write(int, int *, int);
int write_byte(int fd, uint8_t address, uint8_t data) {
  uint8_t buff[2];
  buff[0] = address;
  buff[1] = data;
  if (write(fd, buff, sizeof(buff)) != 2) {
    printf("Failed to write to I2C Slave 0x%x @ register 0x%x "
           "[write_byte():write %d]",
           0x00, address, errno);
    usleep(5000);
  } else {
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1190 <write_byte+0x60>
mov    -0x8(%rbp),%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
lea    0xe86(%rip),%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    $0x1388,%edi
call   1050 <usleep@plt>
jmp    1195 <write_byte+0x65>
jmp    1195 <write_byte+0x65>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_byte>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %esi,0x8(%rsp)
mov    %edx,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1176 <write_byte+0x46>
mov    0x2e86(%rip),%rax
mov    (%rax),%ecx
lea    0xe9d(%rip),%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
mov    $0x1388,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [74 x i8] c"Failed to write to I2C Slave 0x%x @ register 0x%x [write_byte():write %d]\00"
@errno = global i32 0
define i32 @write_byte(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %8, i32* %9
%10 = load i32, i32* %6
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %10, i32* %11
%12 = load i32, i32* %4
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%14 = call i32 @write(i32 %12, i32* %13, i32 8)
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* @errno
%19 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 0, i32 %17, i32 %18)
%20 = call i32 @usleep(i32 5000)
br label %22
21: ; preds = %3
br label %22
22: ; preds = %21, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [74 x i8] c"Failed to write to I2C Slave 0x%x @ register 0x%x [write_byte():write %d]\00"
@errno = global i32 0
define i32 @write_byte(i32 %0, i32 %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 %1, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 %2, i32* %7
%8 = call i32 @write(i32 %0, i32* %6, i32 8)
%9 = icmp eq i32 %8, 2
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 0, i32 %1, i32 %11)
%13 = tail call i32 @usleep(i32 5000)
br label %14
14: ; preds = %3, %10
ret i32 0
}