#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*/ clearLastError();
int pintoGPIO(int);
int readIntValueFromFile(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
int getGPIOValue(int pin) {
  clearLastError();
  int gpio = pintoGPIO(pin);
  char fileName[255] = {0};
  sprintf(fileName, "/sys/class/gpio/gpio%d/%s", gpio, "value");
  return readIntValueFromFile(fileName);
}


x86 assembly (clang, -O0):
<getGPIOValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <clearLastError@plt>
mov    -0x4(%rbp),%edi
call   1030 <pintoGPIO@plt>
mov    %eax,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe6c(%rip),%rsi
lea    0xe7f(%rip),%rcx
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <readIntValueFromFile@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getGPIOValue>:
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <clearLastError@plt>
mov    %ebx,%edi
call   1030 <pintoGPIO@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe37(%rip),%rsi
lea    0xe4a(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <readIntValueFromFile@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/sys/class/gpio/gpio%d/%s\00"
@.str.1 = [6 x i8] c"value\00"
define i32 @getGPIOValue(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
store i32 %0, i32* %2
%5 = call i32 (...) @clearLastError()
%6 = load i32, i32* %2
%7 = call i32 @pintoGPIO(i32 %6)
store i32 %7, i32* %3
%8 = bitcast [255 x i8]* %4 to i8*
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%13 = call i32 @readIntValueFromFile(i8* %12)
ret i32 %13
}

LLVM IR (-O2):
@.str = [26 x i8] c"/sys/class/gpio/gpio%d/%s\00"
@.str.1 = [6 x i8] c"value\00"
define i32 @getGPIOValue(i32 %0) {
%2 = alloca [255 x i8]
%3 = tail call i32 (...) @clearLastError()
%4 = tail call i32 @pintoGPIO(i32 %0)
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @readIntValueFromFile(i8* %5)
ret i32 %7
}