#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  struct stat buf;
  if (0 > stat("/dev/sydbox/off", &buf)) {
    fprintf(stderr, "%s: failed to set sydbox off\n", argv[0]);
    return EXIT_FAILURE;
  }
  fd = open("arnold.layne", O_WRONLY);
  if (0 > fd) {
    fprintf(stderr, "%s: failed to open arnold.layne: %s\n", argv[0],
            strerror(errno));
    return EXIT_FAILURE;
  }
  if (0 > write(fd, "hello arnold layne!", 20)) {
    fprintf(stderr, "%s: failed to write to arnold.layne: %s\n", argv[0],
            strerror(errno));
    return EXIT_FAILURE;
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11c3 <main+0x63>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b8 <main+0x158>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jle    1234 <main+0xd4>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b8 <main+0x158>
mov    -0x14(%rbp),%edi
lea    0xe22(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    12a4 <main+0x144>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b8 <main+0x158>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11bd <main+0x5d>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11d9 <main+0x79>
mov    %eax,%ebp
lea    0xec4(%rip),%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1030 <write@plt>
test   %rax,%rax
js     11fc <main+0x9c>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2e0d(%rip),%rax
jmp    1233 <main+0xd3>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    122c <main+0xcc>
mov    0x2e00(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe41(%rip),%rsi
jmp    121d <main+0xbd>
mov    0x2ddd(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe57(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/dev/sydbox/off\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"%s: failed to set sydbox off\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"arnold.layne\00"
@O_WRONLY = global i32 0
@.str.3 = [37 x i8] c"%s: failed to open arnold.layne: %s\0A\00"
@errno = global i32 0
@.str.4 = [20 x i8] c"hello arnold layne!\00"
@.str.5 = [41 x i8] c"%s: failed to write to arnold.layne: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.stat* %7)
%9 = icmp sgt i64 0, %8
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %48
17: ; preds = %2
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sgt i32 0, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %48
31: ; preds = %17
%32 = load i32, i32* %6
%33 = call i64 @write(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 20)
%34 = icmp sgt i64 0, %33
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %39, i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %48
44: ; preds = %31
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %35, %22, %10
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/dev/sydbox/off\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"%s: failed to set sydbox off\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [13 x i8] c"arnold.layne\00"
@O_WRONLY = global i32 0
@.str.3 = [37 x i8] c"%s: failed to open arnold.layne: %s\0A\00"
@errno = global i32 0
@.str.4 = [20 x i8] c"hello arnold layne!\00"
@.str.5 = [41 x i8] c"%s: failed to write to arnold.layne: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %32
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %19)
br label %32
21: ; preds = %11
%22 = call i64 @write(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 20)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %26, i8* %28)
br label %32
30: ; preds = %21
%31 = call i32 @close(i32 %13)
br label %32
32: ; preds = %30, %24, %15, %7
%33 = phi i32* [ @EXIT_FAILURE, %7 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %30 ]
%34 = load i32, i32* %33
ret i32 %34
}