#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 EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int set_pin_value(unsigned int pin, unsigned int val) {
  FILE *pin_file;
  char pin_direction_path[128];
  char pin_value_path[128];
  snprintf(pin_direction_path, 128,
           "/sys/class/gpio/"
           "gpio%d/direction",
           pin);
  snprintf(pin_value_path, 128,
           "/sys/class/gpio/"
           "gpio%d/value",
           pin);
  pin_file = fopen(pin_direction_path, "a");
  if (pin_file == NULL) {
    return 300;
  }
  fputs("high", pin_file);
  fclose(pin_file);
  pin_file = fopen(pin_value_path, "a");
  if (pin_file == NULL) {
    return 400;
  }
  fprintf(pin_file, "%d", (val) ? 1 : 0);
  fclose(pin_file);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<set_pin_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x80,%esi
lea    0xe89(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x80,%esi
lea    0xe8f(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <set_pin_value+0x75>
movl   $0x12c,-0x4(%rbp)
jmp    1241 <set_pin_value+0xf1>
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x120(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120c <set_pin_value+0xbc>
movl   $0x190,-0x4(%rbp)
jmp    1241 <set_pin_value+0xf1>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
lea    0xe1e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pin_value>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0xe99(%rip),%rdx
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
lea    0xe9c(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
lea    0xea3(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     120d <set_pin_value+0xbd>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe6b(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1214 <set_pin_value+0xc4>
mov    %rax,%rbx
xor    %edx,%edx
test   %r14d,%r14d
setne  %dl
lea    0xe53(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
jmp    1219 <set_pin_value+0xc9>
mov    $0x12c,%eax
jmp    1219 <set_pin_value+0xc9>
mov    $0x190,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.1 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [5 x i8] c"high\00"
@.str.4 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @set_pin_value(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i32 @snprintf(i8* %9, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%13 = load i32, i32* %4
%14 = call i32 @snprintf(i8* %12, i32 128, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, 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** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 300, i32* %3
br label %40
20: ; preds = %2
%21 = load i32*, i32** %6
%22 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %21)
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 400, i32* %3
br label %40
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 1, i32 0
%36 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* @EXIT_SUCCESS
store i32 %39, i32* %3
br label %40
40: ; preds = %30, %29, %19
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [33 x i8] c"/sys/class/gpio/gpio%d/direction\00"
@.str.1 = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [5 x i8] c"high\00"
@.str.4 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @set_pin_value(i32 %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %9)
%13 = call i32 @fclose(i32* %9)
%14 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %22, label %16
16: ; preds = %11
%17 = icmp ne i32 %1, 0
%18 = zext i1 %17 to i32
%19 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @fclose(i32* %14)
%21 = load i32, i32* @EXIT_SUCCESS
br label %22
22: ; preds = %11, %2, %16
%23 = phi i32 [ %21, %16 ], [ 300, %2 ], [ 400, %11 ]
ret i32 %23
}