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

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[] = "Let's go!\n";
  fd = open("data.txt", O_CREAT | O_WRONLY | O_TRUNC);
  if (fd == -1)
    error_handling("open() error");
  printf("file descriptor: %d \n", fd);
  if (write(fd, buf, sizeof(buf)) == -1)
    error_handling("write() error!");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x17(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x15(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c5 <main+0x75>
lea    0xe54(%rip),%rdi
call   1060 <error_handling@plt>
mov    -0x14(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x1f(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11fa <main+0xaa>
lea    0xe42(%rip),%rdi
call   1060 <error_handling@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0x6f6720732774654c,%rax
20 67 6f
mov    %rax,(%rsp)
mov    0x2e8e(%rip),%rax
mov    0x2e57(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movl   $0xa216f,0x7(%rsp)
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11a5 <main+0x55>
lea    0xe74(%rip),%rdi
call   1060 <error_handling@plt>
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11d3 <main+0x83>
lea    0xe69(%rip),%rdi
call   1060 <error_handling@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.buf = [11 x i8] c"Let's go!\0A\00"
@.str = [9 x i8] c"data.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [13 x i8] c"open() error\00"
@.str.2 = [22 x i8] c"file descriptor: %d \0A\00"
@.str.3 = [15 x i8] c"write() error!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [11 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [11 x i8]* %7 to i8*
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%24 = call i32 @write(i32 %22, i8* %23, i32 11)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %19
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [11 x i8] c"Let's go!\0A\00"
@.str = [9 x i8] c"data.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [13 x i8] c"open() error\00"
@.str.2 = [22 x i8] c"file descriptor: %d \0A\00"
@.str.3 = [15 x i8] c"write() error!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%16 = call i32 @write(i32 %10, i8* %4, i32 11)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @close(i32 %10)
ret i32 0
}