#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_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char buffer[1024];
  int fd;
  int r;
  if (argc < 2)
    write(1, "File name missing.\n", 19);
  if (argc > 2)
    write(1, "Too many arguments.\n", 20);
  if (argc == 2) {
    fd = open(argv[1], O_RDONLY);
    while ((r = read(fd, buffer, 1024)) > 0)
      write(1, buffer, r);
    close(fd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1179 <main+0x39>
mov    $0x1,%edi
lea    0xe91(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1199 <main+0x59>
mov    $0x1,%edi
lea    0xe85(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmpl   $0x2,-0x8(%rbp)
jne    120c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x418(%rbp)
cmp    $0x0,%eax
jle    1201 <main+0xc1>
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11bf <main+0x7f>
mov    -0x414(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
cmp    $0x1,%edi
jg     1161 <main+0x21>
lea    0xeab(%rip),%rsi
mov    $0x1,%edi
mov    $0x13,%edx
jmp    11cc <main+0x8c>
cmp    $0x2,%edi
jne    11bb <main+0x7b>
mov    0x8(%rsi),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11b2 <main+0x72>
mov    %rsp,%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     1190 <main+0x50>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    11d1 <main+0x91>
lea    0xe52(%rip),%rsi
mov    $0x1,%edi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"File name missing.\0A\00"
@.str.1 = [21 x i8] c"Too many arguments.\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
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 %13
11: ; preds = %2
%12 = call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @write(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %7
br label %27
27: ; preds = %32, %21
%28 = load i32, i32* %7
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 1024)
store i32 %30, i32* %8
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* %8
%35 = call i32 @write(i32 1, i8* %33, i32 %34)
br label %27
36: ; preds = %27
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
br label %39
39: ; preds = %36, %18
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [20 x i8] c"File name missing.\0A\00"
@.str.1 = [21 x i8] c"Too many arguments.\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
br label %26
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %26
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = call i32 @read(i32 %16, i8* %4, i32 1024)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %12, %19
%20 = phi i32 [ %22, %19 ], [ %17, %12 ]
%21 = call i32 @write(i32 1, i8* %4, i32 %20)
%22 = call i32 @read(i32 %16, i8* %4, i32 1024)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %19, label %24
24: ; preds = %19, %12
%25 = tail call i32 @close(i32 %16)
br label %26
26: ; preds = %10, %6, %24
ret i32 0
}