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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int const);
unsigned analogRead(const unsigned pin) {
  FILE *f;
  char buf[128];
  unsigned value;
  snprintf(buf, sizeof(buf), "/sys/bus/platform/devices/tsc/ain%u", (pin + 1));
  if ((f = fopen(buf, "r")) != NULL) {
    fscanf(f, "%u", &value);
    fclose(f);
    return value;
  }
  perror("Cannot access analog pin");
  assert(0);
}


x86 assembly (clang, -O0):
<analogRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
mov    $0x80,%esi
lea    0xe79(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11db <analogRead+0x7b>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x94(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <analogRead+0x8e>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<analogRead>:
push   %rbx
sub    $0x90,%rsp
lea    0x1(%rdi),%ecx
lea    0xe8e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1040 <snprintf@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c4 <analogRead+0x64>
mov    %rax,%rbx
lea    0xe7f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x90,%rsp
pop    %rbx
ret
lea    0xe5b(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1060 <assert@plt>
jmp    11bb <analogRead+0x5b>

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/bus/platform/devices/tsc/ain%u\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [25 x i8] c"Cannot access analog pin\00"
define i32 @analogRead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %3
%9 = add i32 %8, 1
%10 = call i32 @snprintf(i8* %7, i32 128, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i32*, i32** %4
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = load i32, i32* %6
store i32 %19, i32* %2
br label %23
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @assert(i32 0)
br label %23
23: ; preds = %20, %14
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/bus/platform/devices/tsc/ain%u\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [25 x i8] c"Cannot access analog pin\00"
define i32 @analogRead(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = add i32 %0, 1
%7 = call i32 @snprintf(i8* %4, i32 128, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = call i32 @fclose(i32* %8)
%13 = load i32, i32* %3
br label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @assert(i32 0)
br label %17
17: ; preds = %14, %10
%18 = phi i32 [ %13, %10 ], [ undef, %14 ]
ret i32 %18
}