#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 */

/* Variables and functions */
int O_SYNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ferr(char *, char const *);
int open(char const *, int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void gpio_output(const char *filename, char *buf) {
  int fd = open(filename, O_WRONLY | O_SYNC);
  if (fd == -1) {
    ferr("open", filename);
  }
  if (write(fd, buf, strlen(buf)) < 0) {
    close(fd);
    ferr("write", filename);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<gpio_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1198 <gpio_output+0x48>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1070 <ferr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11df <gpio_output+0x8f>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1070 <ferr@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_output>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e6f(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1187 <gpio_output+0x37>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
call   1070 <ferr@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    11b6 <gpio_output+0x66>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe57(%rip),%rdi
mov    %r14,%rsi
call   1070 <ferr@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"write\00"
define void @gpio_output(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_SYNC
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 @ferr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %2
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = call i64 @write(i32 %17, i8* %18, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i32, i32* %5
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %3
%27 = call i32 @ferr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %23, %16
%29 = load i32, i32* %5
%30 = call i32 @close(i32 %29)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"write\00"
define void @gpio_output(i8* %0, i8* %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_SYNC
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @ferr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @strlen(i8* %1)
%12 = tail call i64 @write(i32 %6, i8* %1, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @close(i32 %6)
%16 = tail call i32 @ferr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %14, %10
%18 = tail call i32 @close(i32 %6)
ret void
}