#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 dgt3000Mode25();
scalar_t__ dgt3000SetCC();
int /*<<< orphan*/ dgt3000Wake();
int /*<<< orphan*/ i2cReset();
int /*<<< orphan*/ usleep(int);
int dgt3000Configure() {
  int e;
  int wakeCount = 0;
  int setCCCount = 0;
  int resetCount = 0;
  while (1) {
    e = dgt3000Mode25();
    if (e == -1) {
      while (1) {
        setCCCount++;
        if (setCCCount > 3) {
          return -3;
        }
        if (dgt3000SetCC() == 0)
          break;
      }
    } else if (e == -2) {
      resetCount++;
      if (resetCount > 1) {
        return -2;
      }
      i2cReset();
      continue;
    } else if (e == -3) {
      continue;
    } else if (e == -7) {
      wakeCount++;
      if (wakeCount > 3) {
        return -3;
      }
      dgt3000Wake();
      continue;
    } else {
      usleep(5000);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <dgt3000Mode25@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c5 <dgt3000Configure+0x75>
jmp    1186 <dgt3000Configure+0x36>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jle    11a5 <dgt3000Configure+0x55>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1259 <dgt3000Configure+0x109>
mov    $0x0,%al
call   1050 <dgt3000SetCC@plt>
cmp    $0x0,%rax
jne    11bb <dgt3000Configure+0x6b>
jmp    11c0 <dgt3000Configure+0x70>
jmp    1186 <dgt3000Configure+0x36>
jmp    124d <dgt3000Configure+0xfd>
cmpl   $0xfffffffe,-0x8(%rbp)
jne    11fa <dgt3000Configure+0xaa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11ee <dgt3000Configure+0x9e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1259 <dgt3000Configure+0x109>
mov    $0x0,%al
call   1040 <i2cReset@plt>
jmp    116d <dgt3000Configure+0x1d>
cmpl   $0xfffffffd,-0x8(%rbp)
jne    1209 <dgt3000Configure+0xb9>
jmp    116d <dgt3000Configure+0x1d>
cmpl   $0xfffffff9,-0x8(%rbp)
jne    123e <dgt3000Configure+0xee>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jle    1232 <dgt3000Configure+0xe2>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1259 <dgt3000Configure+0x109>
mov    $0x0,%al
call   1030 <dgt3000Wake@plt>
jmp    116d <dgt3000Configure+0x1d>
mov    $0x1388,%edi
call   1070 <usleep@plt>
jmp    1252 <dgt3000Configure+0x102>
jmp    116d <dgt3000Configure+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <dgt3000Mode25@plt>
cmp    $0xfffffffd,%eax
je     1160 <dgt3000Configure+0x10>
cmp    $0xfffffff9,%eax
je     11c1 <dgt3000Configure+0x71>
cmp    $0xfffffffe,%eax
je     11a9 <dgt3000Configure+0x59>
cmp    $0xffffffff,%eax
jne    1305 <dgt3000Configure+0x1b5>
cmp    $0x4,%ebx
mov    $0x3,%ebp
cmovge %ebx,%ebp
add    $0x1,%ebp
nopl   (%rax)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1313 <dgt3000Configure+0x1c3>
xor    %eax,%eax
call   1050 <dgt3000SetCC@plt>
test   %rax,%rax
jne    1190 <dgt3000Configure+0x40>
jmp    1160 <dgt3000Configure+0x10>
test   %r14d,%r14d
jne    131d <dgt3000Configure+0x1cd>
xor    %eax,%eax
call   1040 <i2cReset@plt>
mov    $0x1,%r14d
jmp    1160 <dgt3000Configure+0x10>
xor    %eax,%eax
call   1030 <dgt3000Wake@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <dgt3000Mode25@plt>
cmp    $0xfffffffd,%eax
je     11d0 <dgt3000Configure+0x80>
cmp    $0xffffffff,%eax
je     11fe <dgt3000Configure+0xae>
cmp    $0xfffffffe,%eax
jne    1229 <dgt3000Configure+0xd9>
test   %r14d,%r14d
jne    131d <dgt3000Configure+0x1cd>
xor    %eax,%eax
call   1040 <i2cReset@plt>
mov    $0x1,%r14d
jmp    11d0 <dgt3000Configure+0x80>
cmp    $0x4,%ebx
mov    $0x3,%ebp
cmovge %ebx,%ebp
add    $0x1,%ebp
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1313 <dgt3000Configure+0x1c3>
xor    %eax,%eax
call   1050 <dgt3000SetCC@plt>
test   %rax,%rax
jne    1210 <dgt3000Configure+0xc0>
jmp    11d0 <dgt3000Configure+0x80>
cmp    $0xfffffff9,%eax
jne    1305 <dgt3000Configure+0x1b5>
xor    %eax,%eax
call   1030 <dgt3000Wake@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <dgt3000Mode25@plt>
cmp    $0xfffffffd,%eax
je     1240 <dgt3000Configure+0xf0>
cmp    $0xffffffff,%eax
je     126e <dgt3000Configure+0x11e>
cmp    $0xfffffffe,%eax
jne    1299 <dgt3000Configure+0x149>
test   %r14d,%r14d
jne    131d <dgt3000Configure+0x1cd>
xor    %eax,%eax
call   1040 <i2cReset@plt>
mov    $0x1,%r14d
jmp    1240 <dgt3000Configure+0xf0>
cmp    $0x4,%ebx
mov    $0x3,%ebp
cmovge %ebx,%ebp
add    $0x1,%ebp
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1313 <dgt3000Configure+0x1c3>
xor    %eax,%eax
call   1050 <dgt3000SetCC@plt>
test   %rax,%rax
jne    1280 <dgt3000Configure+0x130>
jmp    1240 <dgt3000Configure+0xf0>
cmp    $0xfffffff9,%eax
jne    1305 <dgt3000Configure+0x1b5>
xor    %eax,%eax
call   1030 <dgt3000Wake@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <dgt3000Mode25@plt>
cmp    $0xfffffffd,%eax
je     12b0 <dgt3000Configure+0x160>
cmp    $0xfffffff9,%eax
je     1313 <dgt3000Configure+0x1c3>
cmp    $0xffffffff,%eax
je     12df <dgt3000Configure+0x18f>
cmp    $0xfffffffe,%eax
jne    1305 <dgt3000Configure+0x1b5>
test   %r14d,%r14d
jne    131d <dgt3000Configure+0x1cd>
xor    %eax,%eax
call   1040 <i2cReset@plt>
mov    $0x1,%r14d
jmp    12b0 <dgt3000Configure+0x160>
cmp    $0x4,%ebx
mov    $0x3,%ebp
cmovge %ebx,%ebp
add    $0x1,%ebp
nopl   (%rax)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1313 <dgt3000Configure+0x1c3>
xor    %eax,%eax
call   1050 <dgt3000SetCC@plt>
test   %rax,%rax
jne    12f0 <dgt3000Configure+0x1a0>
jmp    12b0 <dgt3000Configure+0x160>
mov    $0x1388,%edi
call   1070 <usleep@plt>
xor    %eax,%eax
jmp    1318 <dgt3000Configure+0x1c8>
mov    $0xfffffffd,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xfffffffe,%eax
jmp    1318 <dgt3000Configure+0x1c8>

LLVM IR (-O0):
define i32 @dgt3000Configure() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %0, %32, %37, %47, %51
%7 = call i32 (...) @dgt3000Mode25()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %23
10: ; preds = %6
br label %11
11: ; preds = %10, %21
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 3
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 -3, i32* %1
br label %53
17: ; preds = %11
%18 = call i64 (...) @dgt3000SetCC()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %22
21: ; preds = %17
br label %11
22: ; preds = %20
br label %51
23: ; preds = %6
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, -2
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -2, i32* %1
br label %53
32: ; preds = %26
%33 = call i32 (...) @i2cReset()
br label %6
34: ; preds = %23
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, -3
br i1 %36, label %37, label %38
37: ; preds = %34
br label %6
38: ; preds = %34
%39 = load i32, i32* %2
%40 = icmp eq i32 %39, -7
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = icmp sgt i32 %44, 3
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 -3, i32* %1
br label %53
47: ; preds = %41
%48 = call i32 (...) @dgt3000Wake()
br label %6
49: ; preds = %38
%50 = call i32 @usleep(i32 5000)
br label %52
51: ; preds = %22
br label %6
52: ; preds = %49
store i32 0, i32* %1
br label %53
53: ; preds = %52, %46, %31, %16
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
define i32 @dgt3000Configure() {
br label %1
1: ; preds = %14, %0
%2 = phi i32 [ 0, %0 ], [ %12, %14 ]
%3 = phi i32 [ 0, %0 ], [ %5, %14 ]
br label %4
4: ; preds = %1, %19
%5 = phi i32 [ %3, %1 ], [ 1, %19 ]
br label %6
6: ; preds = %4, %6
%7 = tail call i32 (...) @dgt3000Mode25()
switch i32 %7, label %87 [
i32 -1, label %8
i32 -2, label %17
i32 -3, label %6
i32 -7, label %21
]
8: ; preds = %6
%9 = call i32 @llvm.smax.i32(i32 %2, i32 3)
br label %10
10: ; preds = %8, %14
%11 = phi i32 [ %12, %14 ], [ %2, %8 ]
%12 = add nsw i32 %11, 1
%13 = icmp eq i32 %11, %9
br i1 %13, label %89, label %14
14: ; preds = %10
%15 = tail call i64 (...) @dgt3000SetCC()
%16 = icmp eq i64 %15, 0
br i1 %16, label %1, label %10
17: ; preds = %6
%18 = icmp eq i32 %5, 0
br i1 %18, label %19, label %89
19: ; preds = %17
%20 = tail call i32 (...) @i2cReset()
br label %4
21: ; preds = %6
%22 = tail call i32 (...) @dgt3000Wake()
br label %23
23: ; preds = %42, %21
%24 = phi i32 [ %2, %21 ], [ %40, %42 ]
%25 = phi i32 [ %5, %21 ], [ %27, %42 ]
br label %26
26: ; preds = %34, %23
%27 = phi i32 [ %25, %23 ], [ 1, %34 ]
br label %28
28: ; preds = %28, %26
%29 = tail call i32 (...) @dgt3000Mode25()
switch i32 %29, label %87 [
i32 -1, label %36
i32 -2, label %32
i32 -3, label %28
i32 -7, label %30
]
30: ; preds = %28
%31 = tail call i32 (...) @dgt3000Wake()
br label %45
32: ; preds = %28
%33 = icmp eq i32 %27, 0
br i1 %33, label %34, label %89
34: ; preds = %32
%35 = tail call i32 (...) @i2cReset()
br label %26
36: ; preds = %28
%37 = call i32 @llvm.smax.i32(i32 %24, i32 3)
br label %38
38: ; preds = %42, %36
%39 = phi i32 [ %40, %42 ], [ %24, %36 ]
%40 = add nsw i32 %39, 1
%41 = icmp eq i32 %39, %37
br i1 %41, label %89, label %42
42: ; preds = %38
%43 = tail call i64 (...) @dgt3000SetCC()
%44 = icmp eq i64 %43, 0
br i1 %44, label %23, label %38
45: ; preds = %64, %30
%46 = phi i32 [ %24, %30 ], [ %62, %64 ]
%47 = phi i32 [ %27, %30 ], [ %49, %64 ]
br label %48
48: ; preds = %56, %45
%49 = phi i32 [ %47, %45 ], [ 1, %56 ]
br label %50
50: ; preds = %50, %48
%51 = tail call i32 (...) @dgt3000Mode25()
switch i32 %51, label %87 [
i32 -1, label %58
i32 -2, label %54
i32 -3, label %50
i32 -7, label %52
]
52: ; preds = %50
%53 = tail call i32 (...) @dgt3000Wake()
br label %67
54: ; preds = %50
%55 = icmp eq i32 %49, 0
br i1 %55, label %56, label %89
56: ; preds = %54
%57 = tail call i32 (...) @i2cReset()
br label %48
58: ; preds = %50
%59 = call i32 @llvm.smax.i32(i32 %46, i32 3)
br label %60
60: ; preds = %64, %58
%61 = phi i32 [ %62, %64 ], [ %46, %58 ]
%62 = add nsw i32 %61, 1
%63 = icmp eq i32 %61, %59
br i1 %63, label %89, label %64
64: ; preds = %60
%65 = tail call i64 (...) @dgt3000SetCC()
%66 = icmp eq i64 %65, 0
br i1 %66, label %45, label %60
67: ; preds = %84, %52
%68 = phi i32 [ %46, %52 ], [ %82, %84 ]
%69 = phi i32 [ %49, %52 ], [ %71, %84 ]
br label %70
70: ; preds = %76, %67
%71 = phi i32 [ %69, %67 ], [ 1, %76 ]
br label %72
72: ; preds = %72, %70
%73 = tail call i32 (...) @dgt3000Mode25()
switch i32 %73, label %87 [
i32 -1, label %78
i32 -2, label %74
i32 -3, label %72
i32 -7, label %89
]
74: ; preds = %72
%75 = icmp eq i32 %71, 0
br i1 %75, label %76, label %89
76: ; preds = %74
%77 = tail call i32 (...) @i2cReset()
br label %70
78: ; preds = %72
%79 = call i32 @llvm.smax.i32(i32 %68, i32 3)
br label %80
80: ; preds = %84, %78
%81 = phi i32 [ %82, %84 ], [ %68, %78 ]
%82 = add nsw i32 %81, 1
%83 = icmp eq i32 %81, %79
br i1 %83, label %89, label %84
84: ; preds = %80
%85 = tail call i64 (...) @dgt3000SetCC()
%86 = icmp eq i64 %85, 0
br i1 %86, label %67, label %80
87: ; preds = %6, %28, %50, %72
%88 = tail call i32 @usleep(i32 5000)
br label %89
89: ; preds = %17, %10, %32, %38, %54, %60, %74, %80, %72, %87
%90 = phi i32 [ 0, %87 ], [ -3, %72 ], [ -3, %80 ], [ -2, %74 ], [ -3, %60 ], [ -2, %54 ], [ -3, %38 ], [ -2, %32 ], [ -3, %10 ], [ -2, %17 ]
ret i32 %90
}