#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*/ CloseDevices();
int OpenDevices();
int VersionDLL();
int VersionFirmware(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ test_PWM(int);
int /*<<< orphan*/ test_readAnalog(int);
int /*<<< orphan*/ test_readWriteDigital(int);
int main() {
  int devices;
  devices = OpenDevices();
  if (devices == 0) {
    printf("Driver error condition, exiting\n");
    fflush(stdout);
    return -1;
  } else if (devices == -1) {
    printf("No devices found on system, exiting\n");
    fflush(stdout);
    return -1;
  }
  int ver = VersionDLL();
  printf("DLL Version: %d.%d.%d.%d\n", (ver >> 24), (ver >> 16) & 0xFF,
         (ver >> 8) & 0xFF, ver & 0xFF);
  int amount = devices == 3 ? 2 : 1;
  printf("Opened %d device(s)\n", amount);
  if (devices & 1) {
    int fw = VersionFirmware(0);
    printf("Card0 FW: %d.%d.%d.%d\n", (fw >> 24), (fw >> 16) & 0xFF,
           (fw >> 8) & 0xFF, fw & 0xFF);
  }
  if (devices & 2) {
    int fw = VersionFirmware(1);
    printf("Card1 FW: %d.%d.%d.%d\n", (fw >> 24), (fw >> 16) & 0xFF,
           (fw >> 8) & 0xFF, fw & 0xFF);
  }
  fflush(stdout);
  sleep(1);
  if (devices & 1)
    test_readWriteDigital(0);
  if (devices & 2)
    test_readWriteDigital(1);
  if (devices & 1)
    test_readAnalog(0);
  if (devices & 2)
    test_readAnalog(1);
  if (devices & 1)
    test_PWM(0);
  if (devices & 2)
    test_PWM(1);
  CloseDevices();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10b0 <OpenDevices@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11eb <main+0x4b>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e0 <main+0x240>
cmpl   $0xffffffff,-0x8(%rbp)
jne    121d <main+0x7d>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e0 <main+0x240>
jmp    1222 <main+0x82>
mov    $0x0,%al
call   1030 <VersionDLL@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
sar    $0x18,%esi
mov    -0xc(%rbp),%edx
sar    $0x10,%edx
and    $0xff,%edx
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0xc(%rbp),%r8d
and    $0xff,%r8d
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x3,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12da <main+0x13a>
xor    %edi,%edi
call   1090 <VersionFirmware@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
sar    $0x18,%esi
mov    -0x14(%rbp),%edx
sar    $0x10,%edx
and    $0xff,%edx
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x14(%rbp),%r8d
and    $0xff,%r8d
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     132d <main+0x18d>
mov    $0x1,%edi
call   1090 <VersionFirmware@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
sar    $0x18,%esi
mov    -0x18(%rbp),%edx
sar    $0x10,%edx
and    $0xff,%edx
mov    -0x18(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%r8d
and    $0xff,%r8d
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     135b <main+0x1bb>
xor    %edi,%edi
call   10a0 <test_readWriteDigital@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1374 <main+0x1d4>
mov    $0x1,%edi
call   10a0 <test_readWriteDigital@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     138a <main+0x1ea>
xor    %edi,%edi
call   1080 <test_readAnalog@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     13a3 <main+0x203>
mov    $0x1,%edi
call   1080 <test_readAnalog@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     13b9 <main+0x219>
xor    %edi,%edi
call   1060 <test_PWM@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     13d2 <main+0x232>
mov    $0x1,%edi
call   1060 <test_PWM@plt>
mov    $0x0,%al
call   1040 <CloseDevices@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10c0 <OpenDevices@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x1c>
mov    %eax,%ebx
test   %eax,%eax
jne    11f0 <main+0x40>
lea    0xeb7(%rip),%rdi
jmp    11d3 <main+0x23>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%ebx
jmp    12db <main+0x12b>
xor    %eax,%eax
call   1040 <VersionDLL@plt>
mov    %eax,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
sar    $0x18,%eax
shr    $0x10,%edx
movzbl %dl,%edx
lea    0xdf0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %esi,%esi
cmp    $0x3,%ebx
sete   %sil
add    $0x1,%esi
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x1,%bl
je     1261 <main+0xb1>
xor    %edi,%edi
call   10a0 <VersionFirmware@plt>
mov    %eax,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
sar    $0x18,%eax
shr    $0x10,%edx
movzbl %dl,%edx
lea    0xdd7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x2,%bl
je     1292 <main+0xe2>
mov    $0x1,%edi
call   10a0 <VersionFirmware@plt>
mov    %eax,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
sar    $0x18,%eax
shr    $0x10,%edx
movzbl %dl,%edx
lea    0xdbd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
test   $0x1,%bl
jne    12df <main+0x12f>
test   $0x2,%bl
jne    12eb <main+0x13b>
test   $0x1,%bl
jne    12fa <main+0x14a>
test   $0x2,%bl
jne    1306 <main+0x156>
test   $0x1,%bl
jne    1315 <main+0x165>
test   $0x2,%bl
je     12d2 <main+0x122>
mov    $0x1,%edi
call   1070 <test_PWM@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <CloseDevices@plt>
mov    %ebx,%eax
pop    %rbx
ret
xor    %edi,%edi
call   10b0 <test_readWriteDigital@plt>
test   $0x2,%bl
je     12b4 <main+0x104>
mov    $0x1,%edi
call   10b0 <test_readWriteDigital@plt>
test   $0x1,%bl
je     12b9 <main+0x109>
xor    %edi,%edi
call   1090 <test_readAnalog@plt>
test   $0x2,%bl
je     12be <main+0x10e>
mov    $0x1,%edi
call   1090 <test_readAnalog@plt>
test   $0x1,%bl
je     12c3 <main+0x113>
xor    %edi,%edi
call   1070 <test_PWM@plt>
test   $0x2,%bl
jne    12c8 <main+0x118>
jmp    12d2 <main+0x122>

LLVM IR (-O0):
@.str = [33 x i8] c"Driver error condition, exiting\0A\00"
@stdout = global i32 0
@.str.1 = [37 x i8] c"No devices found on system, exiting\0A\00"
@.str.2 = [26 x i8] c"DLL Version: %d.%d.%d.%d\0A\00"
@.str.3 = [21 x i8] c"Opened %d device(s)\0A\00"
@.str.4 = [23 x i8] c"Card0 FW: %d.%d.%d.%d\0A\00"
@.str.5 = [23 x i8] c"Card1 FW: %d.%d.%d.%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @OpenDevices()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
store i32 -1, i32* %1
br label %115
14: ; preds = %0
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
store i32 -1, i32* %1
br label %115
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = call i32 (...) @VersionDLL()
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = ashr i32 %24, 24
%26 = load i32, i32* %3
%27 = ashr i32 %26, 16
%28 = and i32 %27, 255
%29 = load i32, i32* %3
%30 = ashr i32 %29, 8
%31 = and i32 %30, 255
%32 = load i32, i32* %3
%33 = and i32 %32, 255
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %28, i32 %31, i32 %33)
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, 3
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 2, i32 1
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %2
%42 = and i32 %41, 1
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %57
44: ; preds = %22
%45 = call i32 @VersionFirmware(i32 0)
store i32 %45, i32* %5
%46 = load i32, i32* %5
%47 = ashr i32 %46, 24
%48 = load i32, i32* %5
%49 = ashr i32 %48, 16
%50 = and i32 %49, 255
%51 = load i32, i32* %5
%52 = ashr i32 %51, 8
%53 = and i32 %52, 255
%54 = load i32, i32* %5
%55 = and i32 %54, 255
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %50, i32 %53, i32 %55)
br label %57
57: ; preds = %44, %22
%58 = load i32, i32* %2
%59 = and i32 %58, 2
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = call i32 @VersionFirmware(i32 1)
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = ashr i32 %63, 24
%65 = load i32, i32* %6
%66 = ashr i32 %65, 16
%67 = and i32 %66, 255
%68 = load i32, i32* %6
%69 = ashr i32 %68, 8
%70 = and i32 %69, 255
%71 = load i32, i32* %6
%72 = and i32 %71, 255
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %64, i32 %67, i32 %70, i32 %72)
br label %74
74: ; preds = %61, %57
%75 = load i32, i32* @stdout
%76 = call i32 @fflush(i32 %75)
%77 = call i32 @sleep(i32 1)
%78 = load i32, i32* %2
%79 = and i32 %78, 1
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 @test_readWriteDigital(i32 0)
br label %83
83: ; preds = %81, %74
%84 = load i32, i32* %2
%85 = and i32 %84, 2
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @test_readWriteDigital(i32 1)
br label %89
89: ; preds = %87, %83
%90 = load i32, i32* %2
%91 = and i32 %90, 1
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @test_readAnalog(i32 0)
br label %95
95: ; preds = %93, %89
%96 = load i32, i32* %2
%97 = and i32 %96, 2
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @test_readAnalog(i32 1)
br label %101
101: ; preds = %99, %95
%102 = load i32, i32* %2
%103 = and i32 %102, 1
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = call i32 @test_PWM(i32 0)
br label %107
107: ; preds = %105, %101
%108 = load i32, i32* %2
%109 = and i32 %108, 2
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = call i32 @test_PWM(i32 1)
br label %113
113: ; preds = %111, %107
%114 = call i32 (...) @CloseDevices()
store i32 0, i32* %1
br label %115
115: ; preds = %113, %17, %10
%116 = load i32, i32* %1
ret i32 %116
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.2 = [26 x i8] c"DLL Version: %d.%d.%d.%d\0A\00"
@.str.3 = [21 x i8] c"Opened %d device(s)\0A\00"
@.str.4 = [23 x i8] c"Card0 FW: %d.%d.%d.%d\0A\00"
@.str.5 = [23 x i8] c"Card1 FW: %d.%d.%d.%d\0A\00"
@str = [36 x i8] c"No devices found on system, exiting\00"
@str.6 = [32 x i8] c"Driver error condition, exiting\00"
define i32 @main() {
%1 = tail call i32 (...) @OpenDevices()
switch i32 %1, label %10 [
i32 0, label %2
i32 -1, label %6
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
br label %68
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
br label %68
10: ; preds = %0
%11 = tail call i32 (...) @VersionDLL()
%12 = ashr i32 %11, 24
%13 = lshr i32 %11, 16
%14 = and i32 %13, 255
%15 = lshr i32 %11, 8
%16 = and i32 %15, 255
%17 = and i32 %11, 255
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %14, i32 %16, i32 %17)
%19 = icmp eq i32 %1, 3
%20 = select i1 %19, i32 2, i32 1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = and i32 %1, 1
%23 = icmp eq i32 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %10
%25 = tail call i32 @VersionFirmware(i32 0)
%26 = ashr i32 %25, 24
%27 = lshr i32 %25, 16
%28 = and i32 %27, 255
%29 = lshr i32 %25, 8
%30 = and i32 %29, 255
%31 = and i32 %25, 255
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %28, i32 %30, i32 %31)
br label %33
33: ; preds = %24, %10
%34 = and i32 %1, 2
%35 = icmp eq i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %33
%37 = tail call i32 @VersionFirmware(i32 1)
%38 = ashr i32 %37, 24
%39 = lshr i32 %37, 16
%40 = and i32 %39, 255
%41 = lshr i32 %37, 8
%42 = and i32 %41, 255
%43 = and i32 %37, 255
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %38, i32 %40, i32 %42, i32 %43)
br label %45
45: ; preds = %36, %33
%46 = load i32, i32* @stdout
%47 = tail call i32 @fflush(i32 %46)
%48 = tail call i32 @sleep(i32 1)
br i1 %23, label %51, label %49
49: ; preds = %45
%50 = tail call i32 @test_readWriteDigital(i32 0)
br label %51
51: ; preds = %49, %45
br i1 %35, label %54, label %52
52: ; preds = %51
%53 = tail call i32 @test_readWriteDigital(i32 1)
br label %54
54: ; preds = %52, %51
br i1 %23, label %57, label %55
55: ; preds = %54
%56 = tail call i32 @test_readAnalog(i32 0)
br label %57
57: ; preds = %55, %54
br i1 %35, label %60, label %58
58: ; preds = %57
%59 = tail call i32 @test_readAnalog(i32 1)
br label %60
60: ; preds = %58, %57
br i1 %23, label %63, label %61
61: ; preds = %60
%62 = tail call i32 @test_PWM(i32 0)
br label %63
63: ; preds = %61, %60
br i1 %35, label %66, label %64
64: ; preds = %63
%65 = tail call i32 @test_PWM(i32 1)
br label %66
66: ; preds = %64, %63
%67 = tail call i32 (...) @CloseDevices()
br label %68
68: ; preds = %66, %6, %2
%69 = phi i32 [ -1, %2 ], [ -1, %6 ], [ 0, %66 ]
ret i32 %69
}