#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  char filename[] = "non_existent_file";
  int fd;
  fd = open(filename, O_CREAT | O_WRONLY);
  fd = write(fd, filename, strlen(filename));
  close(fd);
  unlink(filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe94(%rip),%ax
mov    %ax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
lea    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movaps 0xea3(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x65,0x10(%rsp)
mov    0x2e89(%rip),%rax
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.filename = [18 x i8] c"non_existent_file\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [18 x i8]* %2 to i8*
%5 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @write(i32 %10, i8* %11, i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%18 = call i32 @unlink(i8* %17)
ret i32 0
}

LLVM IR (-O2):
@__const.main.filename = [18 x i8] c"non_existent_file\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca [18 x i8]
%2 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = call i32 @open(i8* %2, i32 %5)
%7 = call i32 @strlen(i8* %2)
%8 = call i32 @write(i32 %6, i8* %2, i32 %7)
%9 = call i32 @close(i32 %8)
%10 = call i32 @unlink(i8* %2)
ret i32 0
}