#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strcat(char *, char *);
int GetPinValue(int GPIO_num) {
  FILE *GPIO_fp_addr;
  int GPIO_value;
  char GPIO_val[5];
  char GPIO_addr[50] = "/sys/class/gpio/gpio";
  sprintf(GPIO_val, "%i", GPIO_num);
  strcat(GPIO_addr, strcat(GPIO_val, "/value"));
  GPIO_fp_addr = fopen(GPIO_addr, "r");
  if (GPIO_fp_addr == NULL)
    printf("Input value failed to open\n");
  fseek(GPIO_fp_addr, 0, SEEK_SET);
  fscanf(GPIO_fp_addr, "%d", &GPIO_value);
  fclose(GPIO_fp_addr);
  return GPIO_value;
}


x86 assembly (clang, -O0):
<GetPinValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x19(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe84(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x19(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1202 <GetPinValue+0x82>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPinValue>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%edx
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe77(%rip),%rsi
lea    0x7(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movl   $0x6c61762f,0x7(%rsp,%rax,1)
6c
movl   $0x65756c,0xa(%rsp,%rax,1)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
lea    0xe45(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1213 <GetPinValue+0x93>
lea    0xe33(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
lea    0xe11(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.GetPinValue.GPIO_addr = [50 x i8] c"/sys/class/gpio/gpio\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"%i\00"
@.str.1 = [7 x i8] c"/value\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"Input value failed to open\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
define i32 @GetPinValue(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [5 x i8]
%6 = alloca [50 x i8]
store i32 %0, i32* %2
%7 = bitcast [50 x i8]* %6 to i8*
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = call i8* @strcat(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i8* @strcat(i8* %11, i8* %13)
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %1
%22 = load i32*, i32** %3
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %3
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@__const.GetPinValue.GPIO_addr = [50 x i8] c"/sys/class/gpio/gpio\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"%i\00"
@.str.1 = [7 x i8] c"/value\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@str = [27 x i8] c"Input value failed to open\00"
define i32 @GetPinValue(i32 %0) {
%2 = alloca i32
%3 = alloca [5 x i8]
%4 = alloca [50 x i8]
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = call i64 @strlen(i8* %6)
%10 = getelementptr [5 x i8], [5 x i8]* %3, i64 0, i64 %9
%11 = call i8* @strcat(i8* %7, i8* %6)
%12 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %12, i32 0, i32 %17)
%19 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%20 = call i32 @fclose(i32* %12)
%21 = load i32, i32* %2
ret i32 %21
}