#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_RDWR;
int /*<<< orphan*/ close(int);
int modify_file_using_mmap(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  int fd = open("t9-14.txt", O_RDWR);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  int ret = modify_file_using_mmap(fd);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1189 <main+0x49>
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <main+0x62>
mov    -0x8(%rbp),%edi
call   1060 <modify_file_using_mmap@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     1177 <main+0x37>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <modify_file_using_mmap@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1170 <main+0x30>

LLVM IR (-O0):
@.str = [10 x i8] c"t9-14.txt\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %16
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @modify_file_using_mmap(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %3
store i32 %15, i32* %1
br label %16
16: ; preds = %10, %8
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [10 x i8] c"t9-14.txt\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %9
6: ; preds = %0
%7 = tail call i32 @modify_file_using_mmap(i32 %2)
%8 = tail call i32 @close(i32 %2)
br label %9
9: ; preds = %6, %4
%10 = phi i32 [ -1, %4 ], [ %7, %6 ]
ret i32 %10
}