#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(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 SetPinValue(int GPIO_num, int GPIO_value) {
  FILE *GPIO_fp_addr;
  char GPIO_val[10];
  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, "w");
  if (GPIO_fp_addr == NULL)
    printf("Value failed to open\n");
  fseek(GPIO_fp_addr, 0, SEEK_SET);
  fprintf(GPIO_fp_addr, "%d", GPIO_value);
  fflush(GPIO_fp_addr);
  fclose(GPIO_fp_addr);
  return 0;
}


x86 assembly (clang, -O0):
<SetPinValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe71(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x1a(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1215 <SetPinValue+0x85>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPinValue>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %esi,%r14d
mov    %edi,%edx
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe60(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe44(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe63(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movl   $0x6c61762f,0x6(%rsp,%rax,1)
6c
movl   $0x65756c,0x9(%rsp,%rax,1)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
lea    0xe31(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <SetPinValue+0x97>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.SetPinValue.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"w\00"
@.str.3 = [22 x i8] c"Value failed to open\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
define i32 @SetPinValue(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [10 x i8]
%7 = alloca [50 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [50 x i8]* %7 to i8*
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = call i8* @strcat(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = call i8* @strcat(i8* %12, i8* %14)
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32*, i32** %5
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %5
%27 = load i32, i32* %4
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %5
%30 = call i32 @fflush(i32* %29)
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@__const.SetPinValue.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"w\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@str = [21 x i8] c"Value failed to open\00"
define i32 @SetPinValue(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i64 @strlen(i8* %5)
%9 = getelementptr [10 x i8], [10 x i8]* %3, i64 0, i64 %8
%10 = call i8* @strcat(i8* %6, i8* %5)
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %11, i32 0, i32 %16)
%18 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%19 = call i32 @fflush(i32* %11)
%20 = call i32 @fclose(i32* %11)
ret i32 0
}