#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 i2c_read16(int);
int /*<<< orphan*/ i2c_set_slave(int);
scalar_t__ i2c_setup(int);
int /*<<< orphan*/ i2c_write(int, int);
int /*<<< orphan*/ i2c_write8(int, int, int);
int /*<<< orphan*/ print(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ usleep(int);
int main(void) {
  int xh, xl, yh, yl, zh, zl, x, y, z;
  int addr = 0x05;
  int d = 800;
  if (i2c_setup(addr) < 0) {
    print("err setup");
  }
  i2c_set_slave(0x13);
  i2c_write8(0x13, 0x80, 0x08);
  usleep(50000);
  i2c_write(0x13, 0x80);
  usleep(10000);
  i2c_write(0x13, 0x87);
  printf("vcnl %u", i2c_read16(0x13));
  i2c_set_slave(addr);
  i2c_write(addr, 0x10);
  while (d > 92) {
    i2c_write(0x70, 0x51);
    usleep(65000);
    d = i2c_read16(0x70);
    printf(" %u\n", d);
  }
  i2c_write(addr, 0x00);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x2c(%rbp)
movl   $0x320,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <i2c_setup@plt>
cmp    $0x0,%rax
jge    11bb <main+0x3b>
lea    0xe4a(%rip),%rdi
call   1040 <print@plt>
mov    $0x13,%edi
call   1080 <i2c_set_slave@plt>
mov    $0x13,%edi
mov    $0x80,%esi
mov    $0x8,%edx
call   1060 <i2c_write8@plt>
mov    $0xc350,%edi
call   1090 <usleep@plt>
mov    $0x13,%edi
mov    $0x80,%esi
call   1050 <i2c_write@plt>
mov    $0x2710,%edi
call   1090 <usleep@plt>
mov    $0x13,%edi
mov    $0x87,%esi
call   1050 <i2c_write@plt>
mov    $0x13,%edi
call   10a0 <i2c_read16@plt>
mov    %eax,%esi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <i2c_set_slave@plt>
mov    -0x2c(%rbp),%edi
mov    $0x10,%esi
call   1050 <i2c_write@plt>
cmpl   $0x5c,-0x30(%rbp)
jle    127c <main+0xfc>
mov    $0x70,%edi
mov    $0x51,%esi
call   1050 <i2c_write@plt>
mov    $0xfde8,%edi
call   1090 <usleep@plt>
mov    $0x70,%edi
call   10a0 <i2c_read16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xda0(%rip),%rdi
call   1030 <printf@plt>
jmp    1238 <main+0xb8>
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
call   1050 <i2c_write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x5,%edi
call   1070 <i2c_setup@plt>
test   %rax,%rax
jns    119e <main+0x1e>
lea    0xe67(%rip),%rdi
call   1040 <print@plt>
mov    $0x13,%edi
call   1080 <i2c_set_slave@plt>
mov    $0x13,%edi
mov    $0x80,%esi
mov    $0x8,%edx
call   1060 <i2c_write8@plt>
mov    $0xc350,%edi
call   1090 <usleep@plt>
mov    $0x13,%edi
mov    $0x80,%esi
call   1050 <i2c_write@plt>
mov    $0x2710,%edi
call   1090 <usleep@plt>
mov    $0x13,%edi
mov    $0x87,%esi
call   1050 <i2c_write@plt>
mov    $0x13,%edi
call   10a0 <i2c_read16@plt>
lea    0xe0b(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1080 <i2c_set_slave@plt>
mov    $0x5,%edi
mov    $0x10,%esi
call   1050 <i2c_write@plt>
lea    0xdec(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x70,%edi
mov    $0x51,%esi
call   1050 <i2c_write@plt>
mov    $0xfde8,%edi
call   1090 <usleep@plt>
mov    $0x70,%edi
call   10a0 <i2c_read16@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
cmp    $0x5c,%ebp
jg     1230 <main+0xb0>
mov    $0x5,%edi
xor    %esi,%esi
call   1050 <i2c_write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"err setup\00"
@.str.1 = [8 x i8] c"vcnl %u\00"
@.str.2 = [5 x i8] c" %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %11
store i32 800, i32* %12
%13 = load i32, i32* %11
%14 = call i64 @i2c_setup(i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = call i32 @i2c_set_slave(i32 19)
%20 = call i32 @i2c_write8(i32 19, i32 128, i32 8)
%21 = call i32 @usleep(i32 50000)
%22 = call i32 @i2c_write(i32 19, i32 128)
%23 = call i32 @usleep(i32 10000)
%24 = call i32 @i2c_write(i32 19, i32 135)
%25 = call i32 @i2c_read16(i32 19)
%26 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %11
%28 = call i32 @i2c_set_slave(i32 %27)
%29 = load i32, i32* %11
%30 = call i32 @i2c_write(i32 %29, i32 16)
br label %31
31: ; preds = %34, %18
%32 = load i32, i32* %12
%33 = icmp sgt i32 %32, 92
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = call i32 @i2c_write(i32 112, i32 81)
%36 = call i32 @usleep(i32 65000)
%37 = call i32 @i2c_read16(i32 112)
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %31
40: ; preds = %31
%41 = load i32, i32* %11
%42 = call i32 @i2c_write(i32 %41, i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"err setup\00"
@.str.1 = [8 x i8] c"vcnl %u\00"
@.str.2 = [5 x i8] c" %u\0A\00"
define i32 @main() {
%1 = tail call i64 @i2c_setup(i32 5)
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @i2c_set_slave(i32 19)
%7 = tail call i32 @i2c_write8(i32 19, i32 128, i32 8)
%8 = tail call i32 @usleep(i32 50000)
%9 = tail call i32 @i2c_write(i32 19, i32 128)
%10 = tail call i32 @usleep(i32 10000)
%11 = tail call i32 @i2c_write(i32 19, i32 135)
%12 = tail call i32 @i2c_read16(i32 19)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @i2c_set_slave(i32 5)
%15 = tail call i32 @i2c_write(i32 5, i32 16)
br label %16
16: ; preds = %5, %16
%17 = tail call i32 @i2c_write(i32 112, i32 81)
%18 = tail call i32 @usleep(i32 65000)
%19 = tail call i32 @i2c_read16(i32 112)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = icmp sgt i32 %19, 92
br i1 %21, label %16, label %22
22: ; preds = %16
%23 = tail call i32 @i2c_write(i32 5, i32 0)
ret i32 0
}