#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int ch;
  FILE *fp;
  long count = 0;
  if (argc != 2) {
    printf("Usage: %s filename\n", argv[0]);
    exit(1);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    printf("Can't open %s\n", argv[1]);
    exit(1);
  }
  while ((ch = getc(fp)) != EOF) {
    putc(ch, stdout);
    count++;
  }
  fclose(fp);
  printf("File %s has %ld characters\n", argv[1], count);
  return 0;
}


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)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11ee <main+0x8e>
mov    -0x20(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
je     122b <main+0xcb>
mov    -0x14(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ee <main+0x8e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11f6 <main+0x96>
mov    0x8(%r14),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <getc@plt>
mov    0x2e4c(%rip),%r12
cmp    (%r12),%eax
jne    11a6 <main+0x46>
xor    %ebx,%ebx
jmp    11cd <main+0x6d>
xor    %ebx,%ebx
mov    0x2e29(%rip),%r13
nop
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1050 <putc@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1080 <getc@plt>
cmp    (%r12),%eax
jne    11b0 <main+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x8(%r14),%rsi
lea    0xe45(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xe00(%rip),%rdi
jmp    120d <main+0xad>
mov    0x8(%r14),%rsi
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [28 x i8] c"File %s has %ld characters\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %17
br label %30
30: ; preds = %35, %29
%31 = load i32*, i32** %7
%32 = call i32 @getc(i32* %31)
store i32 %32, i32* %6
%33 = load i32, i32* @EOF
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* %6
%37 = load i32, i32* @stdout
%38 = call i32 @putc(i32 %36, i32 %37)
%39 = load i64, i64* %8
%40 = add nsw i64 %39, 1
store i64 %40, i64* %8
br label %30
41: ; preds = %30
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i64, i64* %8
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %46, i64 %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [28 x i8] c"File %s has %ld characters\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @getc(i32* %11)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %30, label %21
17: ; preds = %8
%18 = load i8*, i8** %9
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13, %21
%22 = phi i32 [ %27, %21 ], [ %14, %13 ]
%23 = phi i64 [ %26, %21 ], [ 0, %13 ]
%24 = load i32, i32* @stdout
%25 = tail call i32 @putc(i32 %22, i32 %24)
%26 = add nuw nsw i64 %23, 1
%27 = tail call i32 @getc(i32* %11)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %21
30: ; preds = %21, %13
%31 = phi i64 [ 0, %13 ], [ %26, %21 ]
%32 = tail call i32 @fclose(i32* %11)
%33 = load i8*, i8** %9
%34 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %33, i64 %31)
ret i32 0
}