#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 enable_i2c_clocls();
int /*<<< orphan*/ i2c_init(int, int);
int i2c_reg_read(int, int /*<<< orphan*/);
int /*<<< orphan*/ i2c_uninit();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  size_t i;
  int version;
  int res = enable_i2c_clocls();
  if (res) {
    printf("Error enabling I2C clocks: %i\n", res);
    return res;
  }
  i2c_init(100000, 1);
  printf("I2C-2 initialized\n");
  usleep(100 * 1000);
  for (i = 0; i < 100; ++i) {
    version = i2c_reg_read((0xE6 >> 1), 0);
    printf("Sonar firmware version: %i\n", version);
    version = 0;
    usleep(500 * 1000);
  }
  i2c_uninit();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <enable_i2c_clocls@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11a6 <main+0x46>
mov    -0x20(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1230 <main+0xd0>
mov    $0x186a0,%edi
mov    $0x1,%esi
call   1030 <i2c_init@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x64,-0x18(%rbp)
jae    1222 <main+0xc2>
mov    $0x73,%edi
xor    %esi,%esi
call   1060 <i2c_reg_read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x7a120,%edi
call   1080 <usleep@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11d5 <main+0x75>
mov    $0x0,%al
call   1050 <i2c_uninit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <enable_i2c_clocls@plt>
test   %eax,%eax
je     1193 <main+0x23>
mov    %eax,%ebx
lea    0xe78(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1201 <main+0x91>
mov    $0x186a0,%edi
mov    $0x1,%esi
call   1030 <i2c_init@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    $0x64,%ebx
lea    0xe5b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x73,%edi
xor    %esi,%esi
call   1070 <i2c_reg_read@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
add    $0xffffffffffffffff,%rbx
jne    11d0 <main+0x60>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <i2c_uninit@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Error enabling I2C clocks: %i\0A\00"
@.str.1 = [19 x i8] c"I2C-2 initialized\0A\00"
@.str.2 = [28 x i8] c"Sonar firmware version: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @enable_i2c_clocls()
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %8
store i32 %15, i32* %3
br label %33
16: ; preds = %2
%17 = call i32 @i2c_init(i32 100000, i32 1)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @usleep(i32 100000)
store i64 0, i64* %6
br label %20
20: ; preds = %28, %16
%21 = load i64, i64* %6
%22 = icmp ult i64 %21, 100
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = call i32 @i2c_reg_read(i32 115, i32 0)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %25)
store i32 0, i32* %7
%27 = call i32 @usleep(i32 500000)
br label %28
28: ; preds = %23
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %20
31: ; preds = %20
%32 = call i32 (...) @i2c_uninit()
store i32 0, i32* %3
br label %33
33: ; preds = %31, %12
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [31 x i8] c"Error enabling I2C clocks: %i\0A\00"
@.str.2 = [28 x i8] c"Sonar firmware version: %i\0A\00"
@str = [18 x i8] c"I2C-2 initialized\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @enable_i2c_clocls()
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %20
7: ; preds = %2
%8 = tail call i32 @i2c_init(i32 100000, i32 1)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @usleep(i32 100000)
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %16, %11 ]
%13 = tail call i32 @i2c_reg_read(i32 115, i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 @usleep(i32 500000)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 100
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = tail call i32 (...) @i2c_uninit()
br label %20
20: ; preds = %18, %5
%21 = phi i32 [ %3, %5 ], [ 0, %18 ]
ret i32 %21
}