#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 const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char const *);
int sysfs_gpio_write_number(const char *filename, int number) {
  FILE *export = NULL;
  int byteswritten;
  do
    if ((export = fopen(filename, "w")) == NULL)
      goto error;
  while (0);
  do
    if ((fprintf(export, "%d", number)) < 0)
      goto error;
  while (0);
  fclose(export);
  return 0;
error:
  perror(filename);
  if (export != NULL)
    fclose(export);
  return -1;
}


x86 assembly (clang, -O0):
<sysfs_gpio_write_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117a <sysfs_gpio_write_number+0x3a>
jmp    11c0 <sysfs_gpio_write_number+0x80>
jmp    117f <sysfs_gpio_write_number+0x3f>
jmp    1184 <sysfs_gpio_write_number+0x44>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jge    11a6 <sysfs_gpio_write_number+0x66>
jmp    11c0 <sysfs_gpio_write_number+0x80>
jmp    11ab <sysfs_gpio_write_number+0x6b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <sysfs_gpio_write_number+0xa4>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
cmpq   $0x0,-0x20(%rbp)
je     11dd <sysfs_gpio_write_number+0x9d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_gpio_write_number>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1182 <sysfs_gpio_write_number+0x42>
mov    %rax,%rbx
lea    0xe9e(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
test   %rax,%rax
js     118c <sysfs_gpio_write_number+0x4c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <perror@plt>
jmp    119c <sysfs_gpio_write_number+0x5c>
mov    %r14,%rdi
call   1060 <perror@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
jmp    117d <sysfs_gpio_write_number+0x3d>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @sysfs_gpio_write_number(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* null, i32** %6
br label %8
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %8
br label %25
13: ; preds = %8
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14
%16 = load i32*, i32** %6
%17 = load i32, i32* %5
%18 = call i64 @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %3
br label %34
25: ; preds = %20, %12
%26 = load i8*, i8** %4
%27 = call i32 @perror(i8* %26)
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30, %25
store i32 -1, i32* %3
br label %34
34: ; preds = %33, %22
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @sysfs_gpio_write_number(i8* nocapture %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 %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* %0)
br label %15
7: ; preds = %2
%8 = tail call i64 @fprintf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @fclose(i32* %3)
br label %15
12: ; preds = %7
%13 = tail call i32 @perror(i8* %0)
%14 = tail call i32 @fclose(i32* %3)
br label %15
15: ; preds = %5, %12, %10
%16 = phi i32 [ 0, %10 ], [ -1, %12 ], [ -1, %5 ]
ret i32 %16
}