#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 *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strcat(char *, char *);
int SetPinDirt(int GPIO_num, char *GPIO_InOut) {
  FILE *GPIO_fp_addr;
  char GPIO_way[15];
  char GPIO_addr[50] = "/sys/class/gpio/gpio";
  sprintf(GPIO_way, "%i", GPIO_num);
  strcat(GPIO_addr, strcat(GPIO_way, "/direction"));
  GPIO_fp_addr = fopen(GPIO_addr, "w");
  if (GPIO_fp_addr == NULL)
    printf("Direction failed to open\n");
  fseek(GPIO_fp_addr, 0, SEEK_SET);
  fprintf(GPIO_fp_addr, "%s", GPIO_InOut);
  fflush(GPIO_fp_addr);
  fclose(GPIO_fp_addr);
  return 0;
}


x86 assembly (clang, -O0):
<SetPinDirt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x27(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe70(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x27(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x68(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
lea    -0x60(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1216 <SetPinDirt+0x86>
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPinDirt>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %edi,%edx
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe43(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
lea    0xe62(%rip),%rsi
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movabs $0x697463657269642f,%rcx
63 74 69
mov    %rcx,0x1(%rsp,%rax,1)
movl   $0x6e6f69,0x8(%rsp,%rax,1)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
lea    0xe2d(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    122f <SetPinDirt+0x9f>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fputs@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    %r15
ret

LLVM IR (-O0):
@__const.SetPinDirt.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 = [11 x i8] c"/direction\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"Direction failed to open\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @SetPinDirt(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [15 x i8]
%7 = alloca [50 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = bitcast [50 x i8]* %7 to i8*
%9 = getelementptr inbounds [15 x i8], [15 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 [15 x i8], [15 x i8]* %6, i64 0, i64 0
%14 = call i8* @strcat(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 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 ([26 x i8], [26 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 i8*, i8** %4
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %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.SetPinDirt.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 = [11 x i8] c"/direction\00"
@.str.2 = [2 x i8] c"w\00"
@SEEK_SET = global i32 0
@str = [25 x i8] c"Direction failed to open\00"
define i32 @SetPinDirt(i32 %0, i8* nocapture %1) {
%3 = alloca [15 x i8]
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [15 x i8], [15 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 [15 x i8], [15 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 ([25 x i8], [25 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 @fputs(i8* %1, i32* %11)
%19 = call i32 @fflush(i32* %11)
%20 = call i32 @fclose(i32* %11)
ret i32 0
}