#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 /*<<< orphan*/ colorize(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *fp = stdin;
  if (argc == 2) {
    fp = fopen(argv[1], "r");
    if (!fp) {
      fprintf(stderr, "Unable to open file: %s\n", argv[1]);
      return 1;
    }
  }
  if (fp != stdin) {
    fclose(fp);
  }
  colorize(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11bf <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <main+0x7a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <main+0xac>
jmp    11bf <main+0x7f>
mov    -0x18(%rbp),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
je     11dc <main+0x9c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1060 <colorize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%r15
cmp    $0x2,%edi
jne    117b <main+0x3b>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118a <main+0x4a>
mov    %rax,%rbx
cmp    (%r15),%rax
je     117e <main+0x3e>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    117e <main+0x3e>
mov    (%r15),%rbx
mov    %rbx,%rdi
call   1060 <colorize@plt>
xor    %eax,%eax
jmp    11a8 <main+0x68>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32*, i32** @stdin
store i32* %7, i32** %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %34
23: ; preds = %10
br label %24
24: ; preds = %23, %2
%25 = load i32*, i32** %6
%26 = load i32*, i32** @stdin
%27 = icmp ne i32* %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %24
%32 = load i32*, i32** %6
%33 = call i32 @colorize(i32* %32)
store i32 0, i32* %3
br label %34
34: ; preds = %31, %17
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %19
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 %10, label %14
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %6
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %22
14: ; preds = %5
%15 = load i32*, i32** @stdin
%16 = icmp eq i32* %8, %15
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @fclose(i32* %8)
br label %19
19: ; preds = %2, %17, %14
%20 = phi i32* [ %8, %17 ], [ %8, %14 ], [ %3, %2 ]
%21 = tail call i32 @colorize(i32* %20)
br label %22
22: ; preds = %19, %10
%23 = phi i32 [ 0, %19 ], [ 1, %10 ]
ret i32 %23
}