#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 EXIT_FAILURE;
int /*<<< orphan*/ close(int);
scalar_t__ gpio_set_mode(int, char *);
scalar_t__ gpio_set_value(int, int /*<<< orphan*/);
int open_analog_device(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read_analog_device_value(int);
float read_voltage_scale(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main(void) {
  if (gpio_set_mode(37, "out") < 0) {
    printf("Can't Set GPIO Mux Pin Mode\n");
    return EXIT_FAILURE;
  }
  if (gpio_set_value(37, 0) < 0) {
    printf("Can't Set GPIO Mux Pin Value\n");
    return EXIT_FAILURE;
  }
  printf("Pin Mux Successful\n");
  float v_scale = read_voltage_scale(0);
  printf("Voltage Scale is %f\n", v_scale);
  int analog = open_analog_device(0);
  if (analog > -1) {
    printf("Analog IO File Opened Successfully\n");
  }
  while (1) {
    printf("Voltage : %d \n", read_analog_device_value(analog));
    usleep(1000 * 1000);
  }
  close(analog);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x25,%edi
lea    0xe75(%rip),%rsi
call   1040 <gpio_set_mode@plt>
cmp    $0x0,%rax
jge    11b9 <main+0x49>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126d <main+0xfd>
mov    $0x25,%edi
xor    %esi,%esi
call   1070 <gpio_set_value@plt>
cmp    $0x0,%rax
jge    11ee <main+0x7e>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126d <main+0xfd>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <read_voltage_scale@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <open_analog_device@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jle    1241 <main+0xd1>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1246 <main+0xd6>
mov    -0xc(%rbp),%edi
call   1060 <read_analog_device_value@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
jmp    1246 <main+0xd6>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%rsi
mov    $0x25,%edi
call   1050 <gpio_set_mode@plt>
test   %rax,%rax
js     120f <main+0x8f>
mov    $0x25,%edi
xor    %esi,%esi
call   1080 <gpio_set_value@plt>
test   %rax,%rax
js     1218 <main+0x98>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <read_voltage_scale@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <open_analog_device@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11e9 <main+0x69>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
lea    0xe29(%rip),%r14
mov    %ebx,%edi
call   1070 <read_analog_device_value@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xf4240,%edi
call   10a0 <usleep@plt>
jmp    11f0 <main+0x70>
lea    0xe65(%rip),%rdi
jmp    121f <main+0x9f>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"out\00"
@.str.1 = [29 x i8] c"Can't Set GPIO Mux Pin Mode\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [30 x i8] c"Can't Set GPIO Mux Pin Value\0A\00"
@.str.3 = [20 x i8] c"Pin Mux Successful\0A\00"
@.str.4 = [21 x i8] c"Voltage Scale is %f\0A\00"
@.str.5 = [36 x i8] c"Analog IO File Opened Successfully\0A\00"
@.str.6 = [15 x i8] c"Voltage : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @gpio_set_mode(i32 37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
store i32 %8, i32* %1
br label %32
9: ; preds = %0
%10 = call i64 @gpio_set_value(i32 37, i32 0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %1
br label %32
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%17 = call float @read_voltage_scale(i32 0)
store float %17, float* %2
%18 = load float, float* %2
%19 = fpext float %18 to double
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %19)
%21 = call i32 @open_analog_device(i32 0)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %15
br label %27
27: ; preds = %26, %27
%28 = load i32, i32* %3
%29 = call i32 @read_analog_device_value(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = call i32 @usleep(i32 1000000)
br label %27
32: ; preds = %12, %6
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [4 x i8] c"out\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [21 x i8] c"Voltage Scale is %f\0A\00"
@.str.6 = [15 x i8] c"Voltage : %d \0A\00"
@str = [19 x i8] c"Pin Mux Successful\00"
@str.7 = [35 x i8] c"Analog IO File Opened Successfully\00"
@str.8 = [29 x i8] c"Can't Set GPIO Mux Pin Value\00"
@str.9 = [28 x i8] c"Can't Set GPIO Mux Pin Mode\00"
define i32 @main() {
%1 = tail call i64 @gpio_set_mode(i32 37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i64 %1, 0
br i1 %2, label %20, label %3
3: ; preds = %0
%4 = tail call i64 @gpio_set_value(i32 37, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%8 = tail call float @read_voltage_scale(i32 0)
%9 = fpext float %8 to double
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %9)
%11 = tail call i32 @open_analog_device(i32 0)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.7, i64 0, i64 0))
br label %15
15: ; preds = %13, %6
br label %16
16: ; preds = %15, %16
%17 = tail call i32 @read_analog_device_value(i32 %11)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%19 = tail call i32 @usleep(i32 1000000)
br label %16
20: ; preds = %3, %0
%21 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0), %0 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0), %3 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = load i32, i32* @EXIT_FAILURE
ret i32 %23
}