#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;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read_pci_config(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
uint8_t wait_for_i2c(void) {
  int timeout;
  uint8_t status;
  for (timeout = 0; timeout < 10; timeout++) {
    status = read_pci_config(0xb3);
    if (!(status & 0x08)) {
      fprintf(stderr, "no serial EEPROM detected\n");
      exit(1);
    }
    if (status & 0x10)
      usleep(100000);
    else if (status & 0x20)
      usleep(1000);
    else
      break;
  }
  if (status & (0x10 | 0x20)) {
    fprintf(stderr, "timeout: EEPROM is busy\n");
    exit(1);
  }
  return status;
}


x86 assembly (clang, -O0):
<wait_for_i2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    11ed <wait_for_i2c+0xad>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    1194 <wait_for_i2c+0x54>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11b2 <wait_for_i2c+0x72>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
jmp    11da <wait_for_i2c+0x9a>
mov    -0x8(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11d0 <wait_for_i2c+0x90>
mov    $0x3e8,%edi
call   1060 <usleep@plt>
jmp    11d5 <wait_for_i2c+0x95>
jmp    11ed <wait_for_i2c+0xad>
jmp    11da <wait_for_i2c+0x9a>
jmp    11df <wait_for_i2c+0x9f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <wait_for_i2c+0xf>
mov    -0x8(%rbp),%eax
and    $0x30,%eax
cmp    $0x0,%eax
je     121b <wait_for_i2c+0xdb>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_i2c>:
push   %rbx
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    116e <wait_for_i2c+0x2e>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    11a0 <wait_for_i2c+0x60>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    11d2 <wait_for_i2c+0x92>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    1204 <wait_for_i2c+0xc4>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    1236 <wait_for_i2c+0xf6>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    1268 <wait_for_i2c+0x128>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    129a <wait_for_i2c+0x15a>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    12c4 <wait_for_i2c+0x184>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    12ee <wait_for_i2c+0x1ae>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
mov    $0xb3,%edi
call   1030 <read_pci_config@plt>
mov    %eax,%ebx
test   $0x8,%bl
je     1326 <wait_for_i2c+0x1e6>
mov    $0x186a0,%edi
test   $0x10,%bl
jne    1318 <wait_for_i2c+0x1d8>
mov    $0x3e8,%edi
test   $0x20,%bl
je     131d <wait_for_i2c+0x1dd>
call   1060 <usleep@plt>
test   $0x30,%bl
jne    1338 <wait_for_i2c+0x1f8>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
jmp    1348 <wait_for_i2c+0x208>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xcd3(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"no serial EEPROM detected\0A\00"
@.str.1 = [25 x i8] c"timeout: EEPROM is busy\0A\00"
define i32 @wait_for_i2c() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %30, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 10
br i1 %5, label %6, label %33
6: ; preds = %3
%7 = call i32 @read_pci_config(i32 179)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = and i32 %8, 8
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %6
%16 = load i32, i32* %2
%17 = and i32 %16, 16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @usleep(i32 100000)
br label %29
21: ; preds = %15
%22 = load i32, i32* %2
%23 = and i32 %22, 32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @usleep(i32 1000)
br label %28
27: ; preds = %21
br label %33
28: ; preds = %25
br label %29
29: ; preds = %28, %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
br label %3
33: ; preds = %27, %3
%34 = load i32, i32* %2
%35 = and i32 %34, 48
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"no serial EEPROM detected\0A\00"
@.str.1 = [25 x i8] c"timeout: EEPROM is busy\0A\00"
define i32 @wait_for_i2c() {
%1 = tail call i32 @read_pci_config(i32 179)
%2 = and i32 %1, 8
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %110, %98, %86, %74, %62, %50, %38, %26, %14, %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = and i32 %1, 16
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = and i32 %1, 32
%13 = icmp eq i32 %12, 0
br i1 %13, label %125, label %14
14: ; preds = %11, %8
%15 = phi i32 [ 100000, %8 ], [ 1000, %11 ]
%16 = tail call i32 @usleep(i32 %15)
%17 = tail call i32 @read_pci_config(i32 179)
%18 = and i32 %17, 8
%19 = icmp eq i32 %18, 0
br i1 %19, label %4, label %20
20: ; preds = %14
%21 = and i32 %17, 16
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = and i32 %17, 32
%25 = icmp eq i32 %24, 0
br i1 %25, label %125, label %26
26: ; preds = %23, %20
%27 = phi i32 [ 100000, %20 ], [ 1000, %23 ]
%28 = tail call i32 @usleep(i32 %27)
%29 = tail call i32 @read_pci_config(i32 179)
%30 = and i32 %29, 8
%31 = icmp eq i32 %30, 0
br i1 %31, label %4, label %32
32: ; preds = %26
%33 = and i32 %29, 16
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = and i32 %29, 32
%37 = icmp eq i32 %36, 0
br i1 %37, label %125, label %38
38: ; preds = %35, %32
%39 = phi i32 [ 100000, %32 ], [ 1000, %35 ]
%40 = tail call i32 @usleep(i32 %39)
%41 = tail call i32 @read_pci_config(i32 179)
%42 = and i32 %41, 8
%43 = icmp eq i32 %42, 0
br i1 %43, label %4, label %44
44: ; preds = %38
%45 = and i32 %41, 16
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = and i32 %41, 32
%49 = icmp eq i32 %48, 0
br i1 %49, label %125, label %50
50: ; preds = %47, %44
%51 = phi i32 [ 100000, %44 ], [ 1000, %47 ]
%52 = tail call i32 @usleep(i32 %51)
%53 = tail call i32 @read_pci_config(i32 179)
%54 = and i32 %53, 8
%55 = icmp eq i32 %54, 0
br i1 %55, label %4, label %56
56: ; preds = %50
%57 = and i32 %53, 16
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = and i32 %53, 32
%61 = icmp eq i32 %60, 0
br i1 %61, label %125, label %62
62: ; preds = %59, %56
%63 = phi i32 [ 100000, %56 ], [ 1000, %59 ]
%64 = tail call i32 @usleep(i32 %63)
%65 = tail call i32 @read_pci_config(i32 179)
%66 = and i32 %65, 8
%67 = icmp eq i32 %66, 0
br i1 %67, label %4, label %68
68: ; preds = %62
%69 = and i32 %65, 16
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = and i32 %65, 32
%73 = icmp eq i32 %72, 0
br i1 %73, label %125, label %74
74: ; preds = %71, %68
%75 = phi i32 [ 100000, %68 ], [ 1000, %71 ]
%76 = tail call i32 @usleep(i32 %75)
%77 = tail call i32 @read_pci_config(i32 179)
%78 = and i32 %77, 8
%79 = icmp eq i32 %78, 0
br i1 %79, label %4, label %80
80: ; preds = %74
%81 = and i32 %77, 16
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = and i32 %77, 32
%85 = icmp eq i32 %84, 0
br i1 %85, label %125, label %86
86: ; preds = %83, %80
%87 = phi i32 [ 100000, %80 ], [ 1000, %83 ]
%88 = tail call i32 @usleep(i32 %87)
%89 = tail call i32 @read_pci_config(i32 179)
%90 = and i32 %89, 8
%91 = icmp eq i32 %90, 0
br i1 %91, label %4, label %92
92: ; preds = %86
%93 = and i32 %89, 16
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = and i32 %89, 32
%97 = icmp eq i32 %96, 0
br i1 %97, label %125, label %98
98: ; preds = %95, %92
%99 = phi i32 [ 100000, %92 ], [ 1000, %95 ]
%100 = tail call i32 @usleep(i32 %99)
%101 = tail call i32 @read_pci_config(i32 179)
%102 = and i32 %101, 8
%103 = icmp eq i32 %102, 0
br i1 %103, label %4, label %104
104: ; preds = %98
%105 = and i32 %101, 16
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = and i32 %101, 32
%109 = icmp eq i32 %108, 0
br i1 %109, label %125, label %110
110: ; preds = %107, %104
%111 = phi i32 [ 100000, %104 ], [ 1000, %107 ]
%112 = tail call i32 @usleep(i32 %111)
%113 = tail call i32 @read_pci_config(i32 179)
%114 = and i32 %113, 8
%115 = icmp eq i32 %114, 0
br i1 %115, label %4, label %116
116: ; preds = %110
%117 = and i32 %113, 16
%118 = icmp eq i32 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %116
%120 = and i32 %113, 32
%121 = icmp eq i32 %120, 0
br i1 %121, label %125, label %122
122: ; preds = %119, %116
%123 = phi i32 [ 100000, %116 ], [ 1000, %119 ]
%124 = tail call i32 @usleep(i32 %123)
br label %125
125: ; preds = %122, %119, %107, %95, %83, %71, %59, %47, %35, %23, %11
%126 = phi i32 [ %1, %11 ], [ %17, %23 ], [ %29, %35 ], [ %41, %47 ], [ %53, %59 ], [ %65, %71 ], [ %77, %83 ], [ %89, %95 ], [ %101, %107 ], [ %113, %119 ], [ %113, %122 ]
%127 = and i32 %126, 48
%128 = icmp eq i32 %127, 0
br i1 %128, label %133, label %129
129: ; preds = %125
%130 = load i32, i32* @stderr
%131 = tail call i32 @fprintf(i32 %130, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%132 = tail call i32 @exit(i32 1)
unreachable
133: ; preds = %125
ret i32 %126
}