#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 int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char buf[1024];
  size_t len;
  FILE *fh;
  if (argc != 2) {
    fprintf(stderr, "Incorrect number of arguments, got %i\n", argc);
    return 1;
  }
  fh = fopen(argv[1], "r");
  if (fh == NULL) {
    fprintf(stderr, "Opening %s: errno=%i\n", argv[1], errno);
    return 1;
  }
  do {
    len = fread(buf, 1, sizeof(buf), fh);
    if (len > 0) {
      fwrite(buf, 1, len, stdout);
    }
  } while (len > 0);
  fclose(fh);
  return 0;
}


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)
je     1199 <main+0x49>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x124>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    11f6 <main+0xa6>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    0x2dfe(%rip),%rax
mov    (%rax),%ecx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x124>
jmp    11fb <main+0xab>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jbe    124e <main+0xfe>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    0x2d8e(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    1253 <main+0x103>
cmpq   $0x0,-0x418(%rbp)
ja     11fb <main+0xab>
mov    -0x420(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x2,%edi
jne    11d9 <main+0x89>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f4 <main+0xa4>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11cd <main+0x7d>
mov    0x2e33(%rip),%r15
mov    %rsp,%rbx
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    121d <main+0xcd>
mov    %edi,%edx
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1218 <main+0xc8>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
mov    0x2dd0(%rip),%rax
mov    (%rax),%ecx
lea    0xe18(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Incorrect number of arguments, got %i\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Opening %s: errno=%i\0A\00"
@errno = global i32 0
@stdout = 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 i64
%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 ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %4
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %48
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @errno
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32 %27)
store i32 1, i32* %3
br label %48
29: ; preds = %15
br label %30
30: ; preds = %42, %29
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %8
%33 = call i64 @fread(i8* %31, i32 1, i32 1024, i32* %32)
store i64 %33, i64* %7
%34 = load i64, i64* %7
%35 = icmp ugt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%38 = load i64, i64* %7
%39 = load i32, i32* @stdout
%40 = call i32 @fwrite(i8* %37, i32 1, i64 %38, i32 %39)
br label %41
41: ; preds = %36, %30
br label %42
42: ; preds = %41
%43 = load i64, i64* %7
%44 = icmp ugt i64 %43, 0
br i1 %44, label %30, label %45
45: ; preds = %42
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %22, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Incorrect number of arguments, got %i\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Opening %s: errno=%i\0A\00"
@errno = global i32 0
@stdout = 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 eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %30
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %28, label %22
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %10
%20 = load i32, i32* @errno
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 %20)
br label %30
22: ; preds = %14, %22
%23 = phi i64 [ %26, %22 ], [ %15, %14 ]
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %4, i32 1, i64 %23, i32 %24)
%26 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %22
28: ; preds = %22, %14
%29 = call i32 @fclose(i32* %12)
br label %30
30: ; preds = %28, %17, %6
%31 = phi i32 [ 1, %6 ], [ 1, %17 ], [ 0, %28 ]
ret i32 %31
}