#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 */
scalar_t__ EOF;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, char const *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
void write_pin_to_path(const char *path, unsigned int pin) {
  FILE *out = fopen(path, "w");
  if (out == NULL) {
    error(3, errno, "could not open %s", path);
  }
  if (fprintf(out, "%u\n", pin) < 0) {
    error(4, errno, "could not write GPIO pin number to %s", path);
  }
  if (fclose(out) == EOF) {
    error(4, errno, "could not flush data to %s", path);
  }
}


x86 assembly (clang, -O0):
<write_pin_to_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <write_pin_to_path+0x4c>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    $0x3,%edi
lea    0xe7b(%rip),%rdx
call   1050 <error@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jge    11c7 <write_pin_to_path+0x87>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    $0x4,%edi
lea    0xe56(%rip),%rdx
call   1050 <error@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    11fe <write_pin_to_path+0xbe>
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    $0x4,%edi
lea    0xe45(%rip),%rdx
call   1050 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pin_to_path>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117a <write_pin_to_path+0x3a>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdx
mov    $0x3,%edi
mov    %r14,%rcx
call   1050 <error@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
test   %rax,%rax
jns    11ad <write_pin_to_path+0x6d>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdx
mov    $0x4,%edi
mov    %r14,%rcx
call   1050 <error@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jne    11e2 <write_pin_to_path+0xa2>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdx
mov    $0x4,%edi
mov    %r14,%rcx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <error@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"could not open %s\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [38 x i8] c"could not write GPIO pin number to %s\00"
@EOF = global i64 0
@.str.4 = [27 x i8] c"could not flush data to %s\00"
define void @write_pin_to_path(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = load i8*, i8** %3
%13 = call i32 @error(i32 3, i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %2
%15 = load i32*, i32** %5
%16 = load i32, i32* %4
%17 = call i64 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = load i8*, i8** %3
%22 = call i32 @error(i32 4, i32 %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %14
%24 = load i32*, i32** %5
%25 = call i64 @fclose(i32* %24)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @errno
%30 = load i8*, i8** %3
%31 = call i32 @error(i32 4, i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %28, %23
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"could not open %s\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [38 x i8] c"could not write GPIO pin number to %s\00"
@EOF = global i64 0
@.str.4 = [27 x i8] c"could not flush data to %s\00"
define void @write_pin_to_path(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @error(i32 3, i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %5, %2
%9 = tail call i64 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = tail call i32 @error(i32 4, i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %11, %8
%15 = tail call i64 @fclose(i32* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = tail call i32 @error(i32 4, i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %18, %14
ret void
}