#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 O_CREAT;
int O_RDONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void createFile() {
  int fd;
  if ((fd = open("./newfile", O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {
    fprintf(stderr, "Unable to create './newfile': %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("'./newfile' created. File descriptor is: %d\n", fd);
}


x86 assembly (clang, -O0):
<createFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    0x2e5e(%rip),%rax
or     (%rax),%edx
lea    0xe7d(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11ce <createFile+0x7e>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createFile>:
push   %rbx
mov    0x2e88(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e46(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe84(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1195 <createFile+0x45>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1030 <printf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe57(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"./newfile\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Unable to create './newfile': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [45 x i8] c"'./newfile' created. File descriptor is: %d\0A\00"
define void @createFile() {
%1 = alloca i32
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %2, %3
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %7)
store i32 %8, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %17
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = load i32, i32* %1
%19 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"./newfile\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Unable to create './newfile': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [45 x i8] c"'./newfile' created. File descriptor is: %d\0A\00"
define void @createFile() {
%1 = load i32, i32* @O_RDONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %7)
ret void
}