#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 EXIT_FAILURE;
int EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, size_t, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int munmap(void *, size_t);
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
size_t strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char *text = "Take a Walk on the Wild Side (Lou Reed)";
  void *fmem;
  int fin;
  size_t len = strlen(text);
  if ((fin = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {
    fprintf(stderr, "Usage: %s file\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (lseek(fin, len, SEEK_SET) == -1) {
    fprintf(stderr, "Err.(%d) lseek() - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (write(fin, "", 1) == -1) {
    fprintf(stderr, "Err.(%d) write() - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  fmem = mmap(0, len, PROT_WRITE, MAP_SHARED, fin, 0);
  if (fmem == MAP_FAILED) {
    fprintf(stderr, "Err.(%d) mmap() - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  close(fin);
  sprintf((char *)fmem, "%s", text);
  if (munmap(fmem, len) == -1) {
    fprintf(stderr, "Err.(%d) munmap() - %s\n", errno, strerror(errno));
    exit(EXIT_SUCCESS);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2e02(%rip),%rax
or     (%rax),%esi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    0x2dc8(%rip),%rax
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1247 <main+0x97>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    12b0 <main+0x100>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%edi
lea    0xd7d(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1318 <main+0x168>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edx
mov    0x2cbc(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c3c(%rip),%rcx
cmp    (%rcx),%rax
jne    13a0 <main+0x1f0>
mov    0x2c64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xcc5(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <munmap@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x26d>
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2b6c(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e36(%rip),%rax
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de4(%rip),%rax
mov    0x2e15(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     128e <main+0xfe>
mov    %eax,%ebp
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    $0x27,%esi
mov    %ebp,%edi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12aa <main+0x11a>
lea    0xe43(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12cc <main+0x13c>
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
mov    0x2dcf(%rip),%rax
mov    (%rax),%ecx
mov    $0x27,%esi
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2d51(%rip),%rax
cmp    (%rax),%rbx
je     12ee <main+0x15e>
mov    %ebp,%edi
call   1060 <close@plt>
movabs $0x29646565522075,%rax
mov    %rax,0x20(%rbx)
movups 0xda4(%rip),%xmm0
movups %xmm0,(%rbx)
movups 0xdaa(%rip),%xmm0
movups %xmm0,0x10(%rbx)
mov    $0x27,%esi
mov    %rbx,%rdi
call   1080 <munmap@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x19a>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd87(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    131c <main+0x18c>
mov    0x2d0f(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfe(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd6e(%rip),%rsi
jmp    130e <main+0x17e>
mov    0x2ced(%rip),%rax
mov    (%rax),%ebx
mov    0x2cdc(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd63(%rip),%rsi
jmp    130e <main+0x17e>
mov    0x2ccb(%rip),%rax
mov    (%rax),%ebx
mov    0x2cba(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd58(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%ebx
mov    0x2c7e(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd32(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"Take a Walk on the Wild Side (Lou Reed)\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Usage: %s file\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"Err.(%d) lseek() - %s\0A\00"
@errno = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [23 x i8] c"Err.(%d) write() - %s\0A\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [22 x i8] c"Err.(%d) mmap() - %s\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [24 x i8] c"Err.(%d) munmap() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %9
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %18, %19
%21 = call i32 @open(i8* %14, i32 %17, i32 %20)
store i32 %21, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %31
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
%32 = load i32, i32* %8
%33 = load i64, i64* %9
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @lseek(i32 %32, i64 %33, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %45
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %39, i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %31
%46 = load i32, i32* %8
%47 = call i32 @write(i32 %46, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %51, i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %45
%58 = load i64, i64* %9
%59 = load i32, i32* @PROT_WRITE
%60 = load i32, i32* @MAP_SHARED
%61 = load i32, i32* %8
%62 = call i8* @mmap(i32 0, i64 %58, i32 %59, i32 %60, i32 %61, i32 0)
store i8* %62, i8** %7
%63 = load i8*, i8** %7
%64 = load i8*, i8** @MAP_FAILED
%65 = icmp eq i8* %63, %64
br i1 %65, label %66, label %74
66: ; preds = %57
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %68, i8* %70)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %57
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
%77 = load i8*, i8** %7
%78 = load i8*, i8** %6
%79 = call i32 @sprintf(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %78)
%80 = load i8*, i8** %7
%81 = load i64, i64* %9
%82 = call i32 @munmap(i8* %80, i64 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %92
84: ; preds = %74
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %86, i8* %88)
%90 = load i32, i32* @EXIT_SUCCESS
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %74
%93 = load i32, i32* @EXIT_SUCCESS
ret i32 %93
}

LLVM IR (-O2):
@.str = [40 x i8] c"Take a Walk on the Wild Side (Lou Reed)\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Usage: %s file\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"Err.(%d) lseek() - %s\0A\00"
@errno = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [23 x i8] c"Err.(%d) write() - %s\0A\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [22 x i8] c"Err.(%d) mmap() - %s\0A\00"
@.str.7 = [24 x i8] c"Err.(%d) munmap() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %4, i32 %7, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @lseek(i32 %11, i64 39, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %35, i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
%41 = load i32, i32* @PROT_WRITE
%42 = load i32, i32* @MAP_SHARED
%43 = tail call i8* @mmap(i32 0, i64 39, i32 %41, i32 %42, i32 %11, i32 0)
%44 = load i8*, i8** @MAP_FAILED
%45 = icmp eq i8* %43, %44
br i1 %45, label %46, label %53
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = tail call i8* @strerror(i32 %48)
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %48, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %40
%54 = tail call i32 @close(i32 %11)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(40) %43, i8* align 1 dereferenceable(40) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i64 40, i1 false)
%55 = tail call i32 @munmap(i8* %43, i64 39)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %64
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = tail call i8* @strerror(i32 %59)
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %59, i8* %60)
%62 = load i32, i32* @EXIT_SUCCESS
%63 = tail call i32 @exit(i32 %62)
unreachable
64: ; preds = %53
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}