#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 */
struct stat {
  long st_size;
};

/* Variables and functions */
int EX_OK;
int EX_OSERR;
int /*<<< orphan*/ EX_USAGE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *map_file(char *, struct stat *);
int /*<<< orphan*/ munmap(char *const, long);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ warnx(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 2)
    errx(EX_USAGE, "error: no arguments");
  else if (argc > 2)
    errx(EX_USAGE, "error: too many arguments");
  struct stat main_file_st;
  char *const main_file = map_file(argv[1], &main_file_st);
  if (main_file == NULL) {
    warnx("error: cannot read main file %s", argv[1]);
    return EX_OSERR;
  }
  for (long i = 0; i < main_file_st.st_size; i++)
    putc(main_file[i], stdout);
  fflush(stdout);
  (void)munmap(main_file, main_file_st.st_size);
  return EX_OK;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <main+0x3a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <errx@plt>
jmp    11be <main+0x5e>
cmpl   $0x2,-0x8(%rbp)
jle    11b9 <main+0x59>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1040 <errx@plt>
jmp    11be <main+0x5e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <map_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe41(%rip),%rdi
call   1050 <warnx@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126d <main+0x10d>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1246 <main+0xe6>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    0x2dad(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <putc@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120b <main+0xab>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <munmap@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jge    117a <main+0x1a>
lea    0xe88(%rip),%rsi
jmp    1183 <main+0x23>
je     1191 <main+0x31>
lea    0xe91(%rip),%rsi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1040 <errx@plt>
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%rsi
call   1030 <map_file@plt>
test   %rax,%rax
je     11fc <main+0x9c>
mov    %rax,%r15
cmpq   $0x0,0x8(%rsp)
jle    11d8 <main+0x78>
xor    %ebx,%ebx
mov    0x2e20(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
mov    (%r14),%esi
call   1060 <putc@plt>
add    $0x1,%rbx
cmp    0x8(%rsp),%rbx
jl     11c0 <main+0x60>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1080 <munmap@plt>
mov    0x2dd6(%rip),%rax
jmp    1213 <main+0xb3>
mov    0x8(%r14),%rsi
lea    0xe27(%rip),%rdi
call   1050 <warnx@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@EX_USAGE = global i32 0
@.str = [20 x i8] c"error: no arguments\00"
@.str.1 = [26 x i8] c"error: too many arguments\00"
@.str.2 = [32 x i8] c"error: cannot read main file %s\00"
@EX_OSERR = global i32 0
@stdout = global i32 0
@EX_OK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @EX_USAGE
%13 = call i32 @errx(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %21
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EX_USAGE
%19 = call i32 @errx(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %11
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @map_file(i8* %24, %struct.stat* %6)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EX_OSERR
store i32 %33, i32* %3
br label %58
34: ; preds = %21
store i64 0, i64* %8
br label %35
35: ; preds = %47, %34
%36 = load i64, i64* %8
%37 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp slt i64 %36, %38
br i1 %39, label %40, label %50
40: ; preds = %35
%41 = load i8*, i8** %7
%42 = load i64, i64* %8
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* @stdout
%46 = call i32 @putc(i8 signext %44, i32 %45)
br label %47
47: ; preds = %40
%48 = load i64, i64* %8
%49 = add nsw i64 %48, 1
store i64 %49, i64* %8
br label %35
50: ; preds = %35
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
%53 = load i8*, i8** %7
%54 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%55 = load i64, i64* %54
%56 = call i32 @munmap(i8* %53, i64 %55)
%57 = load i32, i32* @EX_OK
store i32 %57, i32* %3
br label %58
58: ; preds = %50, %28
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@EX_USAGE = global i32 0
@.str = [20 x i8] c"error: no arguments\00"
@.str.1 = [26 x i8] c"error: too many arguments\00"
@.str.2 = [32 x i8] c"error: cannot read main file %s\00"
@EX_OSERR = global i32 0
@stdout = global i32 0
@EX_OK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp eq i32 %0, 2
br i1 %6, label %11, label %7
7: ; preds = %5, %2
%8 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %5 ]
%9 = load i32, i32* @EX_USAGE
%10 = tail call i32 @errx(i32 %9, i8* %8)
br label %11
11: ; preds = %7, %5
%12 = bitcast %struct.stat* %3 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i8* @map_file(i8* %14, %struct.stat* %3)
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i64, i64* %18
%20 = icmp sgt i64 %19, 0
br i1 %20, label %29, label %24
21: ; preds = %11
%22 = load i8*, i8** %13
%23 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %38
24: ; preds = %29, %17
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = load i64, i64* %18
%28 = call i32 @munmap(i8* %15, i64 %27)
br label %38
29: ; preds = %17, %29
%30 = phi i64 [ %35, %29 ], [ 0, %17 ]
%31 = getelementptr inbounds i8, i8* %15, i64 %30
%32 = load i8, i8* %31
%33 = load i32, i32* @stdout
%34 = call i32 @putc(i8 signext %32, i32 %33)
%35 = add nuw nsw i64 %30, 1
%36 = load i64, i64* %18
%37 = icmp slt i64 %35, %36
br i1 %37, label %29, label %24
38: ; preds = %24, %21
%39 = phi i32* [ @EX_OSERR, %21 ], [ @EX_OK, %24 ]
%40 = load i32, i32* %39
ret i32 %40
}