#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 /*<<< orphan*/ close_labjack();
double getBatteryVoltage(int);
scalar_t__ init_labjack();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ query_labjack();
int /*<<< orphan*/ sleep(int);
int main() {
  printf("MAIN: Labjack Test Program\n");
  if (init_labjack()) {
    printf("MAIN: Labjack is initialized.\n");
    while (1) {
      query_labjack();
      printf("MAIN: AIN 0 %f (V)\n", getBatteryVoltage(0));
      printf("MAIN: AIN 1 %f (V)\n", getBatteryVoltage(1));
      printf("MAIN: AIN 3 %f (V)\n", getBatteryVoltage(2));
      printf("MAIN: AIN 4 %f (V)\n", getBatteryVoltage(3));
      if (getBatteryVoltage(3) > 2.0) {
        printf("MAIN: Warning!!! Water IS detected.\n");
      } else {
        printf("MAIN: Water not detected.\n");
      }
      sleep(1);
    }
  } else {
    printf("MAIN: WARNING!!! Labjack not initialized.\n");
  }
  close_labjack();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <init_labjack@plt>
cmp    $0x0,%rax
je     124c <main+0xec>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <query_labjack@plt>
xor    %edi,%edi
call   1050 <getBatteryVoltage@plt>
lea    0xe92(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <getBatteryVoltage@plt>
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1050 <getBatteryVoltage@plt>
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   1050 <getBatteryVoltage@plt>
lea    0xe86(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   1050 <getBatteryVoltage@plt>
movsd  0xdee(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    122f <main+0xcf>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123d <main+0xdd>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    119c <main+0x3c>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <close_labjack@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xed6(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <init_labjack@plt>
test   %rax,%rax
je     124e <main+0xde>
lea    0xeff(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5e(%rip),%r14
lea    0xe6b(%rip),%r15
lea    0xe78(%rip),%r12
lea    0xe85(%rip),%r13
lea    0xf0f(%rip),%rbx
lea    0xeee(%rip),%rbp
nopl   (%rax)
xor    %eax,%eax
call   1070 <query_labjack@plt>
xor    %edi,%edi
call   1060 <getBatteryVoltage@plt>
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <getBatteryVoltage@plt>
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x2,%edi
call   1060 <getBatteryVoltage@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x3,%edi
call   1060 <getBatteryVoltage@plt>
mov    %r13,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x3,%edi
call   1060 <getBatteryVoltage@plt>
ucomisd 0xdca(%rip),%xmm0
mov    %rbp,%rdi
cmova  %rbx,%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11d0 <main+0x60>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <close_labjack@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"MAIN: Labjack Test Program\0A\00"
@.str.1 = [31 x i8] c"MAIN: Labjack is initialized.\0A\00"
@.str.2 = [20 x i8] c"MAIN: AIN 0 %f (V)\0A\00"
@.str.3 = [20 x i8] c"MAIN: AIN 1 %f (V)\0A\00"
@.str.4 = [20 x i8] c"MAIN: AIN 3 %f (V)\0A\00"
@.str.5 = [20 x i8] c"MAIN: AIN 4 %f (V)\0A\00"
@.str.6 = [37 x i8] c"MAIN: Warning!!! Water IS detected.\0A\00"
@.str.7 = [27 x i8] c"MAIN: Water not detected.\0A\00"
@.str.8 = [43 x i8] c"MAIN: WARNING!!! Labjack not initialized.\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%3 = call i64 (...) @init_labjack()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %25
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %23
%8 = call i32 (...) @query_labjack()
%9 = call double @getBatteryVoltage(i32 0)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %9)
%11 = call double @getBatteryVoltage(i32 1)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %11)
%13 = call double @getBatteryVoltage(i32 2)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %13)
%15 = call double @getBatteryVoltage(i32 3)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), double %15)
%17 = call double @getBatteryVoltage(i32 3)
%18 = fcmp ogt double %17, 2.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
br label %23
21: ; preds = %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = call i32 @sleep(i32 1)
br label %7
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %25
%28 = call i32 (...) @close_labjack()
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"MAIN: AIN 0 %f (V)\0A\00"
@.str.3 = [20 x i8] c"MAIN: AIN 1 %f (V)\0A\00"
@.str.4 = [20 x i8] c"MAIN: AIN 3 %f (V)\0A\00"
@.str.5 = [20 x i8] c"MAIN: AIN 4 %f (V)\0A\00"
@str = [27 x i8] c"MAIN: Labjack Test Program\00"
@str.9 = [42 x i8] c"MAIN: WARNING!!! Labjack not initialized.\00"
@str.10 = [30 x i8] c"MAIN: Labjack is initialized.\00"
@str.11 = [26 x i8] c"MAIN: Water not detected.\00"
@str.12 = [36 x i8] c"MAIN: Warning!!! Water IS detected.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @init_labjack()
%3 = icmp eq i64 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
br label %6
6: ; preds = %4, %6
%7 = tail call i32 (...) @query_labjack()
%8 = tail call double @getBatteryVoltage(i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %8)
%10 = tail call double @getBatteryVoltage(i32 1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %10)
%12 = tail call double @getBatteryVoltage(i32 2)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %12)
%14 = tail call double @getBatteryVoltage(i32 3)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), double %14)
%16 = tail call double @getBatteryVoltage(i32 3)
%17 = fcmp ogt double %16, 2.000000e+00
%18 = select i1 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str.12, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0)
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
%20 = tail call i32 @sleep(i32 1)
br label %6
21: ; preds = %0
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.9, i64 0, i64 0))
%23 = tail call i32 (...) @close_labjack()
ret i32 0
}