#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void main(int args, char *argv[]) {
  int en = 0;
  char *fname = "tuberia";
  int fd = open(fname, O_WRONLY);
  if (fd == -1) {
    en = errno;
    printf("open:\t%s\n", strerror(en));
    exit(EXIT_FAILURE);
  }
  int w = write(fd, argv[1], strlen(argv[1]));
  if (w == -1) {
    en = errno;
    printf("write:\t%s\n", strerror(en));
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11d1 <main+0x71>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    123c <main+0xdc>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
jne    1197 <main+0x37>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe73(%rip),%rdi
jmp    11cb <main+0x6b>
mov    %eax,%ebp
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11e1 <main+0x81>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"tuberia\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.1 = [10 x i8] c"open:\09%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"write:\09%s\0A\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @errno
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32, i32* %7
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 %22, i8* %25, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %40
33: ; preds = %21
%34 = load i32, i32* @errno
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %21
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"tuberia\00"
@O_WRONLY = global i32 0
@errno = global i32 0
@.str.1 = [10 x i8] c"open:\09%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"write:\09%s\0A\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = tail call i32 @write(i32 %4, i8* %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = load i32, i32* @EXIT_SUCCESS
%26 = tail call i32 @exit(i32 %25)
unreachable
}