#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
char const *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ print_tests(char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void extract(const char *filename) {
  FILE *file;
  size_t len;
  const char *cont;
  file = fopen(filename, "r");
  if (!file) {
    fprintf(stderr, "Could not open file `%s'\n", filename);
    return;
  }
  fseek(file, 0, SEEK_END);
  len = ftell(file);
  cont = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fileno(file), 0);
  if (cont == MAP_FAILED) {
    fclose(file);
    do {
      fprintf(stderr,
              "mmap failed: `%s'"
              "\n",
              strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  }
  print_tests(cont);
  munmap((void *)cont, len);
  fclose(file);
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f9 <extract+0x49>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12d6 <extract+0x126>
mov    -0x10(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fileno@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
jne    12b7 <extract+0x107>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd78(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <print_tests@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1252 <extract+0xa2>
mov    %rax,%r15
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2e01(%rip),%rax
mov    (%rax),%ebx
mov    0x2db8(%rip),%rax
mov    (%rax),%ebp
mov    %r15,%rdi
call   1070 <fileno@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2d88(%rip),%rax
cmp    (%rax),%rbx
je     1274 <extract+0xc4>
mov    %rbx,%rdi
call   10b0 <print_tests@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <munmap@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd82(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not open file `%s'\0A\00"
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [19 x i8] c"mmap failed: `%s'\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @extract(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %48
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %3
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @MAP_PRIVATE
%23 = load i32*, i32** %3
%24 = call i32 @fileno(i32* %23)
%25 = call i8* @mmap(i32* null, i64 %20, i32 %21, i32 %22, i32 %24, i32 0)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = load i8*, i8** @MAP_FAILED
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %40
29: ; preds = %14
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; No predecessors!
br label %40
40: ; preds = %39, %14
%41 = load i8*, i8** %5
%42 = call i32 @print_tests(i8* %41)
%43 = load i8*, i8** %5
%44 = load i64, i64* %4
%45 = call i32 @munmap(i8* %43, i64 %44)
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %40, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Could not open file `%s'\0A\00"
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [19 x i8] c"mmap failed: `%s'\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @extract(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %29
7: ; preds = %1
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %2, i32 0, i32 %8)
%10 = tail call i64 @ftell(i32* %2)
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_PRIVATE
%13 = tail call i32 @fileno(i32* %2)
%14 = tail call i8* @mmap(i32* null, i64 %10, i32 %11, i32 %12, i32 %13, i32 0)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %25
17: ; preds = %7
%18 = tail call i32 @fclose(i32* %2)
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %7
%26 = tail call i32 @print_tests(i8* %14)
%27 = tail call i32 @munmap(i8* %14, i64 %10)
%28 = tail call i32 @fclose(i32* %2)
br label %29
29: ; preds = %25, %4
ret void
}