#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 mode_t;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int main() {
  int fd;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  char *filename = "./close.txt";
  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    0x2ea0(%rip),%rcx
or     (%rcx),%eax
mov    0x2e87(%rip),%rcx
or     (%rcx),%eax
mov    0x2e76(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
mov    0x2e79(%rip),%rax
or     (%rax),%esi
mov    -0x8(%rbp),%edx
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8e(%rip),%rax
or     (%rax),%edx
mov    0x2e7d(%rip),%rax
or     (%rax),%edx
mov    0x2e5c(%rip),%rax
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e92(%rip),%rax
or     (%rax),%esi
lea    0xe99(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%edi
call   1030 <close@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [12 x i8] c"./close.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%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_IROTH
%10 = or i32 %8, %9
store i32 %10, i32* %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %3
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = load i32, i32* %2
%18 = call i32 @open(i8* %11, i32 %16, i32 %17)
store i32 %18, i32* %1
%19 = load i32, i32* %1
%20 = call i32 @close(i32 %19)
ret i32 0
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [12 x i8] c"./close.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRGRP
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IROTH
%7 = or i32 %5, %6
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %7)
%14 = tail call i32 @close(i32 %13)
ret i32 0
}