#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ write(int /*<<< orphan*/, char *, size_t);
int main(int argc, char *argv[]) {
  int fd;
  ssize_t n;
  char buf[4096 + 1];
  if (argc < 2) {
    fprintf(stderr, "Uso: %s <file name>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Err. open file\n");
    exit(EXIT_FAILURE);
  }
  if ((n = read(fd, buf, 4096)) < 0) {
    fprintf(stderr, "Err. read file\n");
    exit(EXIT_FAILURE);
  }
  buf[n] = '\0';
  if (write(STDOUT_FILENO, buf, n) < 0) {
    fprintf(stderr, "Err. write file\n");
    exit(EXIT_FAILURE);
  }
  close(fd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11af <main+0x4f>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11f6 <main+0x96>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jae    123d <main+0xdd>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x1030(%rbp,%rax,1)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1291 <main+0x131>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x1,%edi
jle    11d1 <main+0x71>
mov    0x8(%rsi),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11ed <main+0x8d>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
movb   $0x0,(%rsp,%rax,1)
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
test   %rax,%rax
js     11ff <main+0x9f>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe1c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1216 <main+0xb6>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
jmp    120f <main+0xaf>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Uso: %s <file name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"Err. open file\0A\00"
@.str.2 = [16 x i8] c"Err. read file\0A\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [17 x i8] c"Err. write file\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 i32
%7 = alloca i64
%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 %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %19
%32 = load i32, i32* %6
%33 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%34 = call i64 @read(i32 %32, i8* %33, i32 4096)
store i64 %34, i64* %7
%35 = icmp ult i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %31
%42 = load i64, i64* %7
%43 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i32, i32* @STDOUT_FILENO
%45 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%46 = load i64, i64* %7
%47 = call i64 @write(i32 %44, i8* %45, i64 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %41
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* @EXIT_SUCCESS
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Uso: %s <file name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"Err. open file\0A\00"
@STDOUT_FILENO = global i32 0
@.str.3 = [17 x i8] c"Err. write file\0A\00"
@EXIT_SUCCESS = 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 %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%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 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = call i64 @read(i32 %16, i8* %4, i32 4096)
%25 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i64 @write(i32 %26, i8* %4, i64 %24)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %23
%35 = tail call i32 @close(i32 %16)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}