#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 */
unsigned int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int replace_esc(char *in_file, char *out_file) {
  FILE *in;
  FILE *out;
  unsigned int c, c_old;
  in = fopen(in_file, "r");
  out = fopen(out_file, "w");
  printf("#\n");
  c = fgetc(in);
  while (c != EOF) {
    if (c == '\t') {
      fputs("#011", out);
    } else if (c == '\n' && c_old != '#') {
      fputs("#012", out);
    } else if (c != '#') {
      fputc(c, out);
    }
    c_old = c;
    c = fgetc(in);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<replace_esc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%eax
je     1241 <replace_esc+0xe1>
cmpl   $0x9,-0x24(%rbp)
jne    11e1 <replace_esc+0x81>
mov    -0x20(%rbp),%rsi
lea    0xe30(%rip),%rdi
call   1050 <fputs@plt>
jmp    122a <replace_esc+0xca>
cmpl   $0xa,-0x24(%rbp)
jne    120a <replace_esc+0xaa>
cmpl   $0x23,-0x28(%rbp)
je     120a <replace_esc+0xaa>
mov    -0x20(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1050 <fputs@plt>
jmp    1225 <replace_esc+0xc5>
cmpl   $0x23,-0x24(%rbp)
je     1220 <replace_esc+0xc0>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
jmp    1225 <replace_esc+0xc5>
jmp    122a <replace_esc+0xca>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
jmp    11b0 <replace_esc+0x50>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_esc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe7e(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e3e(%rip),%r13
cmp    0x0(%r13),%eax
jne    11d1 <replace_esc+0x71>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe2a(%rip),%r15
lea    0xe28(%rip),%r12
jmp    1217 <replace_esc+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %ebp,%ecx
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     11b0 <replace_esc+0x50>
cmp    $0x9,%ebp
je     11f0 <replace_esc+0x90>
cmp    $0xa,%ebp
jne    1240 <replace_esc+0xe0>
cmp    $0x23,%ecx
je     1240 <replace_esc+0xe0>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    11fd <replace_esc+0x9d>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x23,%ebp
je     1205 <replace_esc+0xa5>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
jmp    1205 <replace_esc+0xa5>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.3 = [5 x i8] c"\00"
@.str.4 = [5 x i8] c"\00"
@str = [2 x i8] c"#\00"
define i32 @replace_esc(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @fgetc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %29, label %9
9: ; preds = %2, %25
%10 = phi i32 [ %11, %25 ], [ undef, %2 ]
%11 = phi i32 [ %26, %25 ], [ %6, %2 ]
%12 = icmp eq i32 %11, 9
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %4)
br label %25
15: ; preds = %9
%16 = icmp eq i32 %11, 10
%17 = icmp ne i32 %10, 35
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %4)
br label %25
21: ; preds = %15
%22 = icmp eq i32 %11, 35
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 @fputc(i32 %11, i32* %4)
br label %25
25: ; preds = %19, %23, %21, %13
%26 = tail call i32 @fgetc(i32* %3)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %9
29: ; preds = %25, %2
%30 = tail call i32 @fclose(i32* %3)
%31 = tail call i32 @fclose(i32* %4)
ret i32 0
}