#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int c;
  FILE *infp;
  FILE *outfp;
  char *infile = "../../src/bib";
  char *outfile = "foo";
  if (argc > 1)
    infile = argv[1];
  if (argc > 2)
    outfile = argv[2];
  infp = fopen(infile, "r");
  if (infp == NULL) {
    fprintf(stderr, "can't open %s\n", infile);
    exit(1);
  }
  outfp = fopen(outfile, "w");
  if (outfp == NULL) {
    fprintf(stderr, "can't open %s\n", outfile);
    exit(1);
  }
  while ((c = getc(infp)) != EOF)
    putc(c, outfp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1192 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <main+0x9a>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x38(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122c <main+0xdc>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xdf7(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1231 <main+0xe1>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%eax
je     125d <main+0x10d>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <putc@plt>
jmp    1231 <main+0xe1>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xeb2(%rip),%r14
cmp    $0x2,%edi
jl     116d <main+0x1d>
mov    0x8(%rsi),%rbx
je     1174 <main+0x24>
mov    0x10(%rsi),%r14
jmp    1174 <main+0x24>
lea    0xe8c(%rip),%rbx
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11df <main+0x8f>
mov    %rax,%r15
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f4 <main+0xa4>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <getc@plt>
mov    0x2e37(%rip),%r14
cmp    (%r14),%eax
je     11d7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
mov    %r15,%rdi
call   1070 <getc@plt>
cmp    (%r14),%eax
jne    11c0 <main+0x70>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    %rbx,%rdx
jmp    1207 <main+0xb7>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"../../src/bib\00"
@.str.1 = [4 x i8] c"foo\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"can't open %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = 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 i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %9
br label %17
17: ; preds = %13, %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %10
br label %24
24: ; preds = %20, %17
%25 = load i8*, i8** %9
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %9
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load i8*, i8** %10
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %8
%37 = load i32*, i32** %8
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %10
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %7
%47 = call i32 @getc(i32* %46)
store i32 %47, i32* %6
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i32, i32* %6
%52 = load i32*, i32** %8
%53 = call i32 @putc(i32 %51, i32* %52)
br label %45
54: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"../../src/bib\00"
@.str.1 = [4 x i8] c"foo\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"can't open %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
br label %11
11: ; preds = %2, %8, %4
%12 = phi i8* [ %6, %8 ], [ %6, %4 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %2 ]
%14 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = tail call i32 @getc(i32* %14)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %37, label %31
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %23, %31
%32 = phi i32 [ %34, %31 ], [ %24, %23 ]
%33 = tail call i32 @putc(i32 %32, i32* %21)
%34 = tail call i32 @getc(i32* %14)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %31
37: ; preds = %31, %23
ret i32 0
}