#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 */
scalar_t__ EOF;
char *expand(char, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *stdin;
void run(char *path, int mode) {
  FILE *input = fopen(path, "rt");
  char c;
  if (!input) {
    input = stdin;
  }
  while (fscanf(input, "%c", &c) != EOF) {
    printf("%s", expand(c, mode));
  }
  fclose(input);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <run+0x3c>
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1191 <run+0x41>
mov    -0x18(%rbp),%rdi
lea    0xe67(%rip),%rsi
lea    -0x19(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11d7 <run+0x87>
mov    -0x19(%rbp),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1070 <expand@plt>
mov    %rax,%rsi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
jmp    1191 <run+0x41>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117b <run+0x2b>
mov    0x2e70(%rip),%rax
mov    (%rax),%rbx
lea    0xe81(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x2e4a(%rip),%r13
cmp    0x0(%r13),%rax
je     11db <run+0x8b>
lea    0xe63(%rip),%r14
lea    0xe59(%rip),%r15
lea    0x7(%rsp),%r12
nop
movsbl 0x7(%rsp),%edi
mov    %ebp,%esi
call   1070 <expand@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11b0 <run+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%s\00"
define void @run(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i32*, i32** @stdin
store i32* %12, i32** %5
br label %13
13: ; preds = %11, %2
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %5
%16 = call i64 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%17 = load i64, i64* @EOF
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8, i8* %6
%21 = load i32, i32* %4
%22 = call i8* @expand(i8 signext %20, i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %14
24: ; preds = %14
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%s\00"
define void @run(i8* nocapture %0, i32 %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
%6 = load i32*, i32** @stdin
%7 = select i1 %5, i32* %6, i32* %4
%8 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %18, label %11
11: ; preds = %2, %11
%12 = load i8, i8* %3
%13 = call i8* @expand(i8 signext %12, i32 %1)
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %11
18: ; preds = %11, %2
%19 = call i32 @fclose(i32* %7)
ret void
}