#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 uint8_t;
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 /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void pinMode(uint8_t bPin, uint8_t bMode) {
  FILE *pfileDir;
  char abT[34];
  sprintf(abT, "/sys/class/gpio/gpio%d/direction", bPin);
  pfileDir = fopen(abT, "w");
  if (pfileDir == NULL) {
    FILE *pfileExport = fopen("/sys/class/gpio/export", "w");
    if (pfileExport == NULL) {
      printf("Unable to open export.\n");
      return;
    }
    fseek(pfileExport, 0, SEEK_SET);
    fprintf(pfileExport, "%d", bPin);
    fflush(pfileExport);
    fclose(pfileExport);
    pfileDir = fopen(abT, "w");
    if (pfileDir == NULL) {
      printf("Error opening: %s\n", abT);
      return;
    }
  }
  fseek(pfileDir, 0, SEEK_SET);
  switch (bMode) {
  case 0x0:
    fprintf(pfileDir, "in");
    break;
  case 0x1:
    fprintf(pfileDir, "out");
    break;
  case 0x2:
    fprintf(pfileDir, "in");
    break;
  }
  fflush(pfileDir);
  fclose(pfileDir);
}


x86 assembly (clang, -O0):
<pinMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    125b <pinMode+0xeb>
lea    0xe6c(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11e5 <pinMode+0x75>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f6 <pinMode+0x186>
mov    -0x48(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x48(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x40(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1256 <pinMode+0xe6>
lea    -0x40(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f6 <pinMode+0x186>
jmp    125b <pinMode+0xeb>
mov    -0x10(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
test   %eax,%eax
je     12a4 <pinMode+0x134>
jmp    1282 <pinMode+0x112>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
je     12bb <pinMode+0x14b>
jmp    1293 <pinMode+0x123>
mov    -0x4c(%rbp),%eax
sub    $0x2,%eax
je     12d2 <pinMode+0x162>
jmp    12e4 <pinMode+0x174>
mov    -0x10(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12e4 <pinMode+0x174>
mov    -0x10(%rbp),%rdi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12e4 <pinMode+0x174>
mov    -0x10(%rbp),%rdi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pinMode>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe5c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1205 <pinMode+0x75>
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x2,%r14d
je     11f4 <pinMode+0x64>
cmp    $0x1,%r14d
je     128f <pinMode+0xff>
test   %r14d,%r14d
jne    12a8 <pinMode+0x118>
lea    0xe55(%rip),%rdi
mov    $0x2,%esi
jmp    129b <pinMode+0x10b>
lea    0xe17(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c0 <pinMode+0x130>
mov    %rax,%rbx
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0xdfc(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdc0(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c8 <pinMode+0x38>
lea    0xdc1(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdbd(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xd90(%rip),%rdi
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"/sys/class/gpio/export\00"
@.str.3 = [24 x i8] c"Unable to open export.\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [19 x i8] c"Error opening: %s\0A\00"
@.str.6 = [3 x i8] c"in\00"
@.str.7 = [4 x i8] c"out\00"
define void @pinMode(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [34 x i8]
%7 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [34 x i8], [34 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [34 x i8], [34 x i8]* %6, 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** %5
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %40
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %59
21: ; preds = %15
%22 = load i32*, i32** %7
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %7
%26 = load i32, i32* %3
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %7
%29 = call i32 @fflush(i32* %28)
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = getelementptr inbounds [34 x i8], [34 x i8]* %6, i64 0, i64 0
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %5
%34 = load i32*, i32** %5
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %21
%37 = getelementptr inbounds [34 x i8], [34 x i8]* %6, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %37)
br label %59
39: ; preds = %21
br label %40
40: ; preds = %39, %2
%41 = load i32*, i32** %5
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %41, i32 0, i32 %42)
%44 = load i32, i32* %4
switch i32 %44, label %54 [
i32 0, label %45
i32 1, label %48
i32 2, label %51
]
45: ; preds = %40
%46 = load i32*, i32** %5
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %54
48: ; preds = %40
%49 = load i32*, i32** %5
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %54
51: ; preds = %40
%52 = load i32*, i32** %5
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %40, %51, %48, %45
%55 = load i32*, i32** %5
%56 = call i32 @fflush(i32* %55)
%57 = load i32*, i32** %5
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %54, %36, %19
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"/sys/class/gpio/export\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [19 x i8] c"Error opening: %s\0A\00"
@.str.6 = [3 x i8] c"in\00"
@.str.7 = [4 x i8] c"out\00"
@str = [23 x i8] c"Unable to open export.\00"
define void @pinMode(i32 %0, i32 %1) {
%3 = alloca [34 x i8]
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %23
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %36
13: ; preds = %8
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %9, i32 0, i32 %14)
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%17 = tail call i32 @fflush(i32* %9)
%18 = tail call i32 @fclose(i32* %9)
%19 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %36
23: ; preds = %13, %2
%24 = phi i32* [ %6, %2 ], [ %19, %13 ]
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %24, i32 0, i32 %25)
switch i32 %1, label %33 [
i32 0, label %27
i32 1, label %29
i32 2, label %31
]
27: ; preds = %23
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %24)
br label %33
29: ; preds = %23
%30 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 3, i64 1, i32* %24)
br label %33
31: ; preds = %23
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %24)
br label %33
33: ; preds = %23, %31, %29, %27
%34 = tail call i32 @fflush(i32* %24)
%35 = tail call i32 @fclose(i32* %24)
br label %36
36: ; preds = %21, %11, %33
ret void
}