#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
double getVoltageforInput(int aPin) {
  float rawValue;
  double voltLevel;
  char ain_path[200];
  FILE *fh;
  sprintf(ain_path, "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw", aPin);
  fh = fopen(ain_path, "r");
  if (fh == NULL) {
    printf("Unable to open file.\n exiting...\n");
    exit(1);
  }
  fseek(fh, 0, SEEK_SET);
  fscanf(fh, "%f", &rawValue);
  fclose(fh);
  voltLevel = ((rawValue * 1.8) + 1.0) / 4096;
  voltLevel *= 9.611111;
  return voltLevel;
}


x86 assembly (clang, -O0):
<getVoltageforInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe91(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0xe8(%rbp)
jne    11d2 <getVoltageforInput+0x62>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xe8(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0xe8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0xe8(%rbp),%rdi
call   1030 <fclose@plt>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdef(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdd3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xdba(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVoltageforInput>:
push   %rbx
sub    $0xe0,%rsp
mov    %edi,%edx
lea    0xe9f(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1207 <getVoltageforInput+0x97>
mov    %rax,%rbx
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
lea    0xe95(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe1a(%rip),%xmm0
addsd  0xe1a(%rip),%xmm0
mulsd  0xe1a(%rip),%xmm0
mulsd  0xe1a(%rip),%xmm0
add    $0xe0,%rsp
pop    %rbx
ret
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage%d_raw\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Unable to open file.\0A exiting...\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%f\00"
define double @getVoltageforInput(i32 %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca double
%5 = alloca [200 x i8]
%6 = alloca i32*
store i32 %0, i32* %2
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i32*, i32** %6
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %6
%22 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = load float, float* %3
%26 = fpext float %25 to double
%27 = call double @llvm.fmuladd.f64(double %26, double 1.800000e+00, double 1.000000e+00)
%28 = fdiv double %27, 4.096000e+03
store double %28, double* %4
%29 = load double, double* %4
%30 = fmul double %29, 0x402338E38A7E73A3
store double %30, double* %4
%31 = load double, double* %4
ret double %31
}

LLVM IR (-O2):
@.str = [50 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage%d_raw\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%f\00"
@str = [33 x i8] c"Unable to open file.\0A exiting...\00"
define double @getVoltageforInput(i32 %0) {
%2 = alloca float
%3 = alloca [200 x i8]
%4 = bitcast float* %2 to i8*
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%16 = call i32 @fclose(i32* %7)
%17 = load float, float* %2
%18 = fpext float %17 to double
%19 = call double @llvm.fmuladd.f64(double %18, double 1.800000e+00, double 1.000000e+00)
%20 = fmul double %19, 0x3F30000000000000
%21 = fmul double %20, 0x402338E38A7E73A3
ret double %21
}