#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*/ O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ open_rdonly(char *);
int /*<<< orphan*/ open_rdwr(char *);
int execute_open() {
  open_rdonly("syscalls.txt");
  open_rdwr("syscalls2.txt");
  open("hopefully_no_such_filename_exists.txt", O_RDONLY,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
  return 0;
}


x86 assembly (clang, -O0):
<execute_open>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
call   1030 <open_rdonly@plt>
lea    0xec6(%rip),%rdi
call   1040 <open_rdwr@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    0x2e73(%rip),%rax
or     (%rax),%edx
mov    0x2e5a(%rip),%rax
or     (%rax),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
mov    0x2e40(%rip),%rax
or     (%rax),%edx
lea    0xe92(%rip),%rdi
call   1050 <open@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_open>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <open_rdonly@plt>
lea    0xec9(%rip),%rdi
call   1040 <open_rdwr@plt>
mov    0x2e68(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
mov    0x2e7d(%rip),%rax
mov    0x2e6e(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e43(%rip),%rax
or     (%rax),%edx
lea    0xe95(%rip),%rdi
call   1050 <open@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [14 x i8] c"syscalls2.txt\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
define i32 @execute_open() {
%1 = call i32 @open_rdonly(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @open_rdwr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IWGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [14 x i8] c"syscalls2.txt\00"
@.str.2 = [38 x i8] c"hopefully_no_such_filename_exists.txt\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
define i32 @execute_open() {
%1 = tail call i32 @open_rdonly(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @open_rdwr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IWGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %12)
ret i32 0
}