#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_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void fileClosed() {
  int fd = open("hi.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600);
  if (fd != -1) {
    char buffer[256];
    write(fd, buffer, strlen(buffer));
    close(fd);
  }
}


x86 assembly (clang, -O0):
<fileClosed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e9d(%rip),%rax
or     (%rax),%esi
mov    0x2e8c(%rip),%rax
or     (%rax),%esi
lea    0xe93(%rip),%rdi
mov    $0x180,%edx
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     11c3 <fileClosed+0x83>
mov    -0x4(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x11c(%rbp),%edi
mov    -0x118(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileClosed>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    0x2e77(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8d(%rip),%rax
or     (%rax),%esi
lea    0xe94(%rip),%rdi
mov    $0x180,%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     119b <fileClosed+0x5b>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"hi.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @fileClosed() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i32 384)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = load i32, i32* %1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 %12, i8* %13, i32 %15)
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %11, %0
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"hi.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @fileClosed() {
%1 = alloca [256 x i8]
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i32 384)
%8 = icmp eq i32 %7, -1
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write(i32 %7, i8* %10, i32 %11)
%13 = call i32 @close(i32 %7)
br label %14
14: ; preds = %9, %0
ret void
}