#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  char *buffer;
  FILE *fp = stdin;
  if (argc > 1) {
    fp = fopen(argv[1], "r");
    if (fp == NULL)
      return 1;
  }
  buffer = malloc(sizeof(int));
  while (!feof(fp)) {
    int c = fgetc(fp);
    if (c != EOF)
      printf("%c", (char)c);
  }
  if (argc > 1)
    fclose(fp);
  free(buffer);
  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)
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11d2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cd <main+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xe6>
jmp    11d2 <main+0x62>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fe <main+0x8e>
jmp    1233 <main+0xc3>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%eax
je     122e <main+0xbe>
mov    -0x24(%rbp),%eax
lea    0xddc(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
jmp    11e0 <main+0x70>
cmpl   $0x1,-0x8(%rbp)
jle    1246 <main+0xd6>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
cmp    $0x2,%edi
jl     119f <main+0x2f>
mov    0x8(%rsi),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <main+0x39>
mov    $0x1,%eax
jmp    11da <main+0x6a>
mov    0x2e42(%rip),%rax
mov    (%rax),%rbx
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11e3 <main+0x73>
cmp    $0x2,%r15d
jl     11d0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df6(%rip),%rbp
lea    0xe11(%rip),%r12
jmp    120c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11c2 <main+0x52>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     1200 <main+0x90>
movsbl %al,%esi
mov    %r12,%rdi
call   1050 <printf@plt>
jmp    1200 <main+0x90>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32*, i32** @stdin
store i32* %9, i32** %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 1, i32* %3
br label %48
20: ; preds = %12
br label %21
21: ; preds = %20, %2
%22 = call i8* @malloc(i32 4)
store i8* %22, i8** %6
br label %23
23: ; preds = %38, %21
%24 = load i32*, i32** %7
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %39
28: ; preds = %23
%29 = load i32*, i32** %7
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i8
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %36)
br label %38
38: ; preds = %34, %28
br label %23
39: ; preds = %23
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %39
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %19
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %30, label %10
10: ; preds = %5, %2
%11 = phi i32* [ %8, %5 ], [ %3, %2 ]
%12 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%13 = tail call i32 @feof(i32* %11)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %10, %22
%16 = tail call i32 @fgetc(i32* %11)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = trunc i32 %16 to i8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %20)
br label %22
22: ; preds = %19, %15
%23 = tail call i32 @feof(i32* %11)
%24 = icmp eq i32 %23, 0
br i1 %24, label %15, label %25
25: ; preds = %22, %10
br i1 %4, label %26, label %28
26: ; preds = %25
%27 = tail call i32 @fclose(i32* %11)
br label %28
28: ; preds = %26, %25
%29 = tail call i32 @free(i8* %12)
br label %30
30: ; preds = %5, %28
%31 = phi i32 [ 0, %28 ], [ 1, %5 ]
ret i32 %31
}