#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*/ S_IRUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ft_putstr(char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int file;
  int re;
  char buffer[4096 + 1];
  if (argc < 2) {
    write(2, "File name missing.\n", 19);
    return (0);
  }
  if (argc > 2) {
    write(2, "Too many arguments.\n", 20);
    return (0);
  }
  file = open(argv[1], O_RDONLY, S_IRUSR);
  re = read(file, buffer, 4096);
  buffer[re] = '\0';
  ft_putstr(buffer);
  close(file);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1195 <main+0x45>
mov    $0x2,%edi
lea    0xe81(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <main+0xd1>
cmpl   $0x2,-0x8(%rbp)
jle    11c1 <main+0x71>
mov    $0x2,%edi
lea    0xe69(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
call   1070 <ft_putstr@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x1,%edi
jg     1172 <main+0x22>
lea    0xe9a(%rip),%rsi
mov    $0x2,%edi
mov    $0x13,%edx
jmp    11ce <main+0x7e>
cmp    $0x2,%edi
jne    11bd <main+0x6d>
mov    0x8(%rsi),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
call   1060 <open@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1070 <ft_putstr@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11d3 <main+0x83>
lea    0xe50(%rip),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
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
@S_IRUSR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4097 x i8]
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 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
store i32 0, i32* %3
br label %35
13: ; preds = %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 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
store i32 0, i32* %3
br label %35
18: ; preds = %13
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = load i32, i32* @S_IRUSR
%24 = call i32 @open(i8* %21, i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 4096)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%32 = call i32 @ft_putstr(i8* %31)
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
store i32 0, i32* %3
br label %35
35: ; preds = %18, %16, %11
%36 = load i32, i32* %3
ret i32 %36
}

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
@S_IRUSR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4097 x i8]
%4 = getelementptr inbounds [4097 x i8], [4097 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 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
br label %23
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 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %23
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = load i32, i32* @S_IRUSR
%17 = tail call i32 @open(i8* %14, i32 %15, i32 %16)
%18 = call i32 @read(i32 %17, i8* %4, i32 4096)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @ft_putstr(i8* %4)
%22 = call i32 @close(i32 %17)
br label %23
23: ; preds = %12, %10, %6
ret i32 0
}