#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 */
unsigned int _i2c_get(int);
int /*<<< orphan*/ _i2c_set(int, int);
int /*<<< orphan*/ _i2c_stop();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
void _i2c_wait(void) {
  int i, num_ready;
  unsigned int tmp;
  _i2c_set(0x7d30, (1 << 3));
  for (i = 0, num_ready = 0; num_ready < 3; i++) {
    tmp = _i2c_get(0x7d30);
    if (tmp == (1 << 0)) {
      num_ready++;
    } else if (tmp != (1 << 3)) {
      _i2c_stop();
    }
    if (i == 10) {
      fprintf(stderr, "i2c timeout\n");
      exit(1);
    }
    usleep(1000);
  }
  _i2c_set(0x7d30, (1 << 0));
}


x86 assembly (clang, -O0):
<_i2c_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x7d30,%edi
mov    $0x8,%esi
call   1070 <_i2c_set@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    120b <_i2c_wait+0xab>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11b4 <_i2c_wait+0x54>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <_i2c_wait+0x6a>
cmpl   $0x8,-0xc(%rbp)
je     11c5 <_i2c_wait+0x65>
mov    $0x0,%al
call   1030 <_i2c_stop@plt>
jmp    11ca <_i2c_wait+0x6a>
cmpl   $0xa,-0x4(%rbp)
jne    11f3 <_i2c_wait+0x93>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <_i2c_wait+0x25>
mov    $0x7d30,%edi
mov    $0x1,%esi
call   1070 <_i2c_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_i2c_wait>:
push   %rbx
mov    $0x7d30,%edi
mov    $0x8,%esi
call   1070 <_i2c_set@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x8,%eax
je     118b <_i2c_wait+0x2b>
cmp    $0x1,%eax
jne    118f <_i2c_wait+0x2f>
mov    $0x1,%ebx
jmp    1198 <_i2c_wait+0x38>
xor    %ebx,%ebx
jmp    1198 <_i2c_wait+0x38>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x8,%eax
je     11c2 <_i2c_wait+0x62>
cmp    $0x1,%eax
jne    11bb <_i2c_wait+0x5b>
add    $0x1,%ebx
jmp    11c2 <_i2c_wait+0x62>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     11f3 <_i2c_wait+0x93>
cmp    $0x8,%eax
je     11e7 <_i2c_wait+0x87>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
jmp    1209 <_i2c_wait+0xa9>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     127a <_i2c_wait+0x11a>
cmp    $0x8,%eax
je     1224 <_i2c_wait+0xc4>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     1292 <_i2c_wait+0x132>
cmp    $0x8,%eax
je     1249 <_i2c_wait+0xe9>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     12aa <_i2c_wait+0x14a>
cmp    $0x8,%eax
je     126e <_i2c_wait+0x10e>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
jmp    12c0 <_i2c_wait+0x160>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
jmp    122e <_i2c_wait+0xce>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
jmp    1253 <_i2c_wait+0xf3>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     130c <_i2c_wait+0x1ac>
cmp    $0x8,%eax
je     12db <_i2c_wait+0x17b>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     1320 <_i2c_wait+0x1c0>
cmp    $0x8,%eax
je     1300 <_i2c_wait+0x1a0>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
jmp    1332 <_i2c_wait+0x1d2>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
jmp    12e5 <_i2c_wait+0x185>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     1385 <_i2c_wait+0x225>
cmp    $0x8,%eax
je     134d <_i2c_wait+0x1ed>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
jne    1399 <_i2c_wait+0x239>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
jbe    13af <_i2c_wait+0x24f>
mov    $0x7d30,%edi
mov    $0x1,%esi
pop    %rbx
jmp    1070 <_i2c_set@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
cmp    $0x1,%ebx
ja     1375 <_i2c_wait+0x215>
add    $0x1,%ebx
jmp    1357 <_i2c_wait+0x1f7>
cmp    $0x8,%eax
je     13a5 <_i2c_wait+0x245>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    $0x7d30,%edi
call   1040 <_i2c_get@plt>
cmp    $0x1,%eax
je     13ca <_i2c_wait+0x26a>
cmp    $0x8,%eax
je     13ca <_i2c_wait+0x26a>
xor    %eax,%eax
call   1030 <_i2c_stop@plt>
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
lea    0xc26(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"i2c timeout\0A\00"
define void @_i2c_wait() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @_i2c_set(i32 32048, i32 8)
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %30, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %33
8: ; preds = %5
%9 = call i32 @_i2c_get(i32 32048)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %21
15: ; preds = %8
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 8
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (...) @_i2c_stop()
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20, %12
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i32 @usleep(i32 1000)
br label %30
30: ; preds = %28
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
br label %5
33: ; preds = %5
%34 = call i32 @_i2c_set(i32 32048, i32 1)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"i2c timeout\0A\00"
define void @_i2c_wait() {
%1 = tail call i32 @_i2c_set(i32 32048, i32 8)
%2 = tail call i32 @_i2c_get(i32 32048)
switch i32 %2, label %4 [
i32 1, label %3
i32 8, label %10
]
3: ; preds = %0
br label %10
4: ; preds = %0
%5 = tail call i32 (...) @_i2c_stop()
br label %10
6: ; preds = %106, %108, %106
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3, %4, %0
%11 = phi i32 [ 1, %3 ], [ 0, %4 ], [ 0, %0 ]
%12 = tail call i32 @usleep(i32 1000)
%13 = tail call i32 @_i2c_get(i32 32048)
switch i32 %13, label %16 [
i32 1, label %14
i32 8, label %18
]
14: ; preds = %10
%15 = add nuw nsw i32 %11, 1
br label %18
16: ; preds = %10
%17 = tail call i32 (...) @_i2c_stop()
br label %18
18: ; preds = %10, %14, %16
%19 = phi i32 [ %15, %14 ], [ %11, %16 ], [ %11, %10 ]
%20 = tail call i32 @usleep(i32 1000)
%21 = tail call i32 @_i2c_get(i32 32048)
switch i32 %21, label %22 [
i32 1, label %26
i32 8, label %24
]
22: ; preds = %18
%23 = tail call i32 (...) @_i2c_stop()
br label %24
24: ; preds = %22, %18
%25 = tail call i32 @usleep(i32 1000)
br label %30
26: ; preds = %18
%27 = add nuw nsw i32 %19, 1
%28 = tail call i32 @usleep(i32 1000)
%29 = icmp ult i32 %19, 2
br i1 %29, label %30, label %110
30: ; preds = %24, %26
%31 = phi i32 [ %19, %24 ], [ %27, %26 ]
%32 = tail call i32 @_i2c_get(i32 32048)
switch i32 %32, label %33 [
i32 1, label %37
i32 8, label %35
]
33: ; preds = %30
%34 = tail call i32 (...) @_i2c_stop()
br label %35
35: ; preds = %33, %30
%36 = tail call i32 @usleep(i32 1000)
br label %41
37: ; preds = %30
%38 = add nuw nsw i32 %31, 1
%39 = tail call i32 @usleep(i32 1000)
%40 = icmp ult i32 %31, 2
br i1 %40, label %41, label %110
41: ; preds = %35, %37
%42 = phi i32 [ %31, %35 ], [ %38, %37 ]
%43 = tail call i32 @_i2c_get(i32 32048)
switch i32 %43, label %44 [
i32 1, label %48
i32 8, label %46
]
44: ; preds = %41
%45 = tail call i32 (...) @_i2c_stop()
br label %46
46: ; preds = %44, %41
%47 = tail call i32 @usleep(i32 1000)
br label %52
48: ; preds = %41
%49 = add nuw nsw i32 %42, 1
%50 = tail call i32 @usleep(i32 1000)
%51 = icmp ult i32 %42, 2
br i1 %51, label %52, label %110
52: ; preds = %46, %48
%53 = phi i32 [ %42, %46 ], [ %49, %48 ]
%54 = tail call i32 @_i2c_get(i32 32048)
switch i32 %54, label %55 [
i32 1, label %59
i32 8, label %57
]
55: ; preds = %52
%56 = tail call i32 (...) @_i2c_stop()
br label %57
57: ; preds = %55, %52
%58 = tail call i32 @usleep(i32 1000)
br label %63
59: ; preds = %52
%60 = add nuw nsw i32 %53, 1
%61 = tail call i32 @usleep(i32 1000)
%62 = icmp ult i32 %53, 2
br i1 %62, label %63, label %110
63: ; preds = %57, %59
%64 = phi i32 [ %53, %57 ], [ %60, %59 ]
%65 = tail call i32 @_i2c_get(i32 32048)
switch i32 %65, label %66 [
i32 1, label %70
i32 8, label %68
]
66: ; preds = %63
%67 = tail call i32 (...) @_i2c_stop()
br label %68
68: ; preds = %66, %63
%69 = tail call i32 @usleep(i32 1000)
br label %74
70: ; preds = %63
%71 = add nuw nsw i32 %64, 1
%72 = tail call i32 @usleep(i32 1000)
%73 = icmp ult i32 %64, 2
br i1 %73, label %74, label %110
74: ; preds = %68, %70
%75 = phi i32 [ %64, %68 ], [ %71, %70 ]
%76 = tail call i32 @_i2c_get(i32 32048)
switch i32 %76, label %77 [
i32 1, label %81
i32 8, label %79
]
77: ; preds = %74
%78 = tail call i32 (...) @_i2c_stop()
br label %79
79: ; preds = %77, %74
%80 = tail call i32 @usleep(i32 1000)
br label %85
81: ; preds = %74
%82 = add nuw nsw i32 %75, 1
%83 = tail call i32 @usleep(i32 1000)
%84 = icmp ult i32 %75, 2
br i1 %84, label %85, label %110
85: ; preds = %79, %81
%86 = phi i32 [ %75, %79 ], [ %82, %81 ]
%87 = tail call i32 @_i2c_get(i32 32048)
switch i32 %87, label %88 [
i32 1, label %92
i32 8, label %90
]
88: ; preds = %85
%89 = tail call i32 (...) @_i2c_stop()
br label %90
90: ; preds = %88, %85
%91 = tail call i32 @usleep(i32 1000)
br label %96
92: ; preds = %85
%93 = add nuw nsw i32 %86, 1
%94 = tail call i32 @usleep(i32 1000)
%95 = icmp ult i32 %86, 2
br i1 %95, label %96, label %110
96: ; preds = %90, %92
%97 = phi i32 [ %86, %90 ], [ %93, %92 ]
%98 = tail call i32 @_i2c_get(i32 32048)
switch i32 %98, label %99 [
i32 1, label %103
i32 8, label %101
]
99: ; preds = %96
%100 = tail call i32 (...) @_i2c_stop()
br label %101
101: ; preds = %99, %96
%102 = tail call i32 @usleep(i32 1000)
br label %106
103: ; preds = %96
%104 = tail call i32 @usleep(i32 1000)
%105 = icmp ult i32 %97, 2
br i1 %105, label %106, label %110
106: ; preds = %101, %103
%107 = tail call i32 @_i2c_get(i32 32048)
switch i32 %107, label %108 [
i32 1, label %6
i32 8, label %6
]
108: ; preds = %106
%109 = tail call i32 (...) @_i2c_stop()
br label %6
110: ; preds = %103, %92, %81, %70, %59, %48, %37, %26
%111 = tail call i32 @_i2c_set(i32 32048, i32 1)
ret void
}