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


x86 assembly (clang, -O0):
<fileNotClosed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    0x2ead(%rip),%rax
or     (%rax),%esi
mov    0x2e9c(%rip),%rax
or     (%rax),%esi
lea    0xea3(%rip),%rdi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     11ab <fileNotClosed+0x7b>
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>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileNotClosed>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    0x2e87(%rip),%rax
mov    0x2eb0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e9d(%rip),%rax
or     (%rax),%esi
lea    0xea4(%rip),%rdi
mov    $0x180,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1184 <fileNotClosed+0x54>
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>
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 @fileNotClosed() {
%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 %17
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)
br label %17
17: ; 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 @fileNotClosed() {
%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 %13, 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)
br label %13
13: ; preds = %9, %0
ret void
}