#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_APPEND;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *gnu_get_libc_version();
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  printf("The GLIBC version present is %s\n", gnu_get_libc_version());
  int fd = open("startup", O_RDONLY);
  if (fd == -1) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  fd = open("myfile", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  fd =
      open("w.log", O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    perror("open");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <gnu_get_libc_version@plt>
mov    %rax,%rsi
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11ac <main+0x5c>
lea    0xe90(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    0x2df1(%rip),%rax
or     (%rax),%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    120e <main+0xbe>
lea    0xe2e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
mov    0x2dda(%rip),%rax
or     (%rax),%esi
mov    0x2dc9(%rip),%rax
or     (%rax),%esi
mov    0x2d68(%rip),%rax
or     (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
mov    0x2d86(%rip),%rax
or     (%rax),%edx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1279 <main+0x129>
lea    0xdc3(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <gnu_get_libc_version@plt>
lea    0xe9a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1211 <main+0xc1>
mov    0x2e43(%rip),%rax
mov    0x2e5c(%rip),%rbx
mov    (%rbx),%esi
or     (%rax),%esi
mov    0x2e49(%rip),%r15
or     (%r15),%esi
mov    0x2dff(%rip),%r14
mov    0x2e10(%rip),%r12
mov    (%r12),%edx
or     (%r14),%edx
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1211 <main+0xc1>
mov    0x2dc7(%rip),%rax
mov    (%rbx),%esi
or     (%rax),%esi
or     (%r15),%esi
mov    0x2db1(%rip),%rax
or     (%rax),%esi
mov    (%r12),%edx
or     (%r14),%edx
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1211 <main+0xc1>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe11(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"The GLIBC version present is %s\0A\00"
@.str.1 = [8 x i8] c"startup\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"myfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [6 x i8] c"w.log\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = call i8* (...) @gnu_get_libc_version()
%3 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i32, i32* @O_RDONLY
%5 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %13, %14
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %18, %19
%21 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %20)
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %12
%29 = load i32, i32* @O_WRONLY
%30 = load i32, i32* @O_CREAT
%31 = or i32 %29, %30
%32 = load i32, i32* @O_TRUNC
%33 = or i32 %31, %32
%34 = load i32, i32* @O_APPEND
%35 = or i32 %33, %34
%36 = load i32, i32* @S_IRUSR
%37 = load i32, i32* @S_IWUSR
%38 = or i32 %36, %37
%39 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %38)
store i32 %39, i32* %1
%40 = load i32, i32* %1
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %28
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"The GLIBC version present is %s\0A\00"
@.str.1 = [8 x i8] c"startup\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [7 x i8] c"myfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [6 x i8] c"w.log\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
define i32 @main() {
%1 = tail call i8* (...) @gnu_get_libc_version()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %17, %16
%19 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %10
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %10
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = load i32, i32* @O_TRUNC
%30 = or i32 %28, %29
%31 = load i32, i32* @O_APPEND
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %34, %33
%36 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %25
%39 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %25
ret i32 0
}