#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int getVoltage0Reading() {
  FILE *f = fopen("/sys/bus/iio/devices/iio:device0/in_voltage0_raw", "r");
  if (!f) {
    printf("ERROR: Unable to open voltage input file. Cape loaded?\n");
    printf("try: echo BB-ADC > /sys/devices/platform/bone_capemgr/slots\n");
    exit(-1);
  }
  int a2dReading = 0;
  int itemsRead = fscanf(f, "%d", &a2dReading);
  if (itemsRead <= 0) {
    printf("ERROR: Unable to read values from voltage input file.\n");
    exit(-1);
  }
  fclose(f);
  return a2dReading;
}


x86 assembly (clang, -O0):
<getVoltage0Reading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119c <getVoltage0Reading+0x4c>
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xefa(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     11da <getVoltage0Reading+0x8a>
lea    0xee0(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVoltage0Reading>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xece(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a2 <getVoltage0Reading+0x52>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
lea    0xeb4(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
test   %eax,%eax
jle    11b7 <getVoltage0Reading+0x67>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
jmp    11be <getVoltage0Reading+0x6e>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage0_raw\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [56 x i8] c"ERROR: Unable to open voltage input file. Cape loaded?\0A\00"
@.str.3 = [61 x i8] c"try: echo BB-ADC > /sys/devices/platform/bone_capemgr/slots\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [55 x i8] c"ERROR: Unable to read values from voltage input file.\0A\00"
define i32 @getVoltage0Reading() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
store i32 0, i32* %2
%12 = load i32*, i32** %1
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %11
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [49 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage0_raw\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [55 x i8] c"ERROR: Unable to open voltage input file. Cape loaded?\00"
@str.6 = [60 x i8] c"try: echo BB-ADC > /sys/devices/platform/bone_capemgr/slots\00"
@str.7 = [54 x i8] c"ERROR: Unable to read values from voltage input file.\00"
define i32 @getVoltage0Reading() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %0
%9 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%10 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.7, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %8
%16 = call i32 @fclose(i32* %2)
%17 = load i32, i32* %1
ret i32 %17
}