#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void writeValueToGPIO(int value, char *nom) {
  FILE *file;
  char path[255];
  if (nom != NULL) {
    sprintf(path, "/sys/class/gpio/gpio%s/value", nom);
    file = fopen(path, "w");
    if (file != NULL) {
      fprintf(file, "%d", value);
      fclose(file);
    } else
      printf("Error during openning %s to write value %d\n", path, value);
  }
}


x86 assembly (clang, -O0):
<writeValueToGPIO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e2 <writeValueToGPIO+0x92>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c7 <writeValueToGPIO+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11dd <writeValueToGPIO+0x8d>
lea    -0x120(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
jmp    11e2 <writeValueToGPIO+0x92>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeValueToGPIO>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
test   %rsi,%rsi
je     11bf <writeValueToGPIO+0x6f>
mov    %rsi,%rdx
mov    %edi,%ebp
lea    0xe96(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ae <writeValueToGPIO+0x5e>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe6d(%rip),%rdi
mov    %rsp,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [44 x i8] c"Error during openning %s to write value %d\0A\00"
define void @writeValueToGPIO(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [255 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %28
9: ; preds = %2
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %3
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %5
%22 = call i32 @fclose(i32* %21)
br label %27
23: ; preds = %9
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %24, i32 %25)
br label %27
27: ; preds = %23, %17
br label %28
28: ; preds = %27, %2
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [44 x i8] c"Error during openning %s to write value %d\0A\00"
define void @writeValueToGPIO(i32 %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%12 = tail call i32 @fclose(i32* %8)
br label %15
13: ; preds = %6
%14 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %0)
br label %15
15: ; preds = %10, %13, %2
ret void
}