#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ dup2(int, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int fd, fd2, fd3, nr;
  char buf;
  if (argc < 2) {
    fprintf(stderr, "Uso: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno), argv[1]);
    exit(EXIT_FAILURE);
  }
  fd2 = dup(fd);
  close(fd);
  dup2(fd2, fd3);
  while ((nr = read(fd3, &buf, 1)) > 0)
    write(STDOUT_FILENO, &buf, nr);
  close(fd3);
  return (EXIT_SUCCESS);
}


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    11dc <main+0x4c>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1251 <main+0xc1>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <dup2@plt>
mov    -0x1c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    12a6 <main+0x116>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    -0x21(%rbp),%rsi
call   1030 <write@plt>
jmp    126f <main+0xdf>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1235 <main+0xa5>
mov    0x8(%rbx),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1251 <main+0xc1>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <dup@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1040 <dup2@plt>
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    121e <main+0x8e>
mov    0x2dff(%rip),%rbp
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1200 <main+0x70>
call   1060 <close@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1285 <main+0xf5>
mov    0x2d78(%rip),%rax
mov    (%rax),%r14d
mov    0x2d66(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
mov    0x8(%rbx),%r8
lea    0xd9e(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Uso: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = load i8*, i8** %12
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %20, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %11
%26 = tail call i32 @dup(i32 %15)
%27 = tail call i32 @close(i32 %15)
%28 = tail call i32 @dup2(i32 %26, i32 undef)
%29 = call i32 @read(i32 undef, i8* %3, i32 1)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25, %31
%32 = phi i32 [ %35, %31 ], [ %29, %25 ]
%33 = load i32, i32* @STDOUT_FILENO
%34 = call i32 @write(i32 %33, i8* %3, i32 %32)
%35 = call i32 @read(i32 undef, i8* %3, i32 1)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %31, label %37
37: ; preds = %31, %25
%38 = tail call i32 @close(i32 undef)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}