#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 */
char EOF;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *handle_char(char);
int /*<<< orphan*/ printf(char *, char, char *);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *fp;
  char c;
  if (argv[1]) {
    if (!(fp = fopen(argv[1], "r")))
      die("[ERROR] fopen");
  } else
    fp = stdin;
  while ((c = fgetc(fp)) != EOF)
    printf("%04d \'%s\'\n", c, handle_char(c));
  fclose(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    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11b8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b3 <main+0x53>
lea    0xe54(%rip),%rdi
call   1080 <die@plt>
jmp    11c6 <main+0x66>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11cb <main+0x6b>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2dff(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1215 <main+0xb5>
mov    -0x19(%rbp),%al
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%edi
call   1060 <handle_char@plt>
mov    %rax,%rdx
mov    -0x1a(%rbp),%al
lea    0xe08(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
jmp    11cb <main+0x6b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1194 <main+0x34>
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119e <main+0x3e>
lea    0xe77(%rip),%rdi
call   1080 <die@plt>
xor    %ebx,%ebx
jmp    119e <main+0x3e>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e33(%rip),%r15
cmp    (%r15),%al
je     11e4 <main+0x84>
lea    0xe57(%rip),%r14
nopl   0x0(%rax)
movsbl %al,%ebp
mov    %ebp,%edi
call   1060 <handle_char@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"[ERROR] fopen\00"
@stdin = global i32* null
@EOF = global i8 0
@.str.2 = [11 x i8] c"%04d '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
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** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
br label %23
21: ; preds = %2
%22 = load i32*, i32** @stdin
store i32* %22, i32** %6
br label %23
23: ; preds = %21, %20
br label %24
24: ; preds = %31, %23
%25 = load i32*, i32** %6
%26 = call signext i8 @fgetc(i32* %25)
store i8 %26, i8* %7
%27 = sext i8 %26 to i32
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i8, i8* %7
%33 = load i8, i8* %7
%34 = call i8* @handle_char(i8 signext %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8 signext %32, i8* %34)
br label %24
36: ; preds = %24
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

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