#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ clear_buf(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int replace_chars(char input_file[], char output_file[]) {
  char buf[BUFSIZ];
  FILE *fp_in;
  FILE *fp_out;
  int i = 0;
  clear_buf(buf);
  fp_in = fopen(input_file, "r");
  fp_out = fopen(output_file, "w+");
  while (fgets(buf, sizeof(buf), fp_in)) {
    fprintf(fp_out, "%s", buf);
    for (i = 0; i < BUFSIZ && buf[i] != 0; i++) {
      switch (buf[i]) {
      case 'o':
        buf[i] = '0';
        fprintf(fp_out, "%s", buf);
        break;
      case 'a':
        buf[i] = '@';
        fprintf(fp_out, "%s", buf);
        break;
      case 'e':
        buf[i] = '3';
        fprintf(fp_out, "%s", buf);
        break;
      case 's':
        buf[i] = '$';
        fprintf(fp_out, "%s", buf);
        break;
      }
    }
  }
  fclose(fp_in);
  fclose(fp_out);
  return 0;
}


x86 assembly (clang, -O0):
<replace_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
call   1070 <clear_buf@plt>
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1301 <replace_chars+0x1b1>
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
mov    0x2dd8(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x49(%rbp)
jge    1228 <replace_chars+0xd8>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1238 <replace_chars+0xe8>
jmp    12fc <replace_chars+0x1ac>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x12,%eax
ja     12e9 <replace_chars+0x199>
mov    -0x58(%rbp),%rax
lea    0xd9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x40(%rbp),%rdx
movslq -0x34(%rbp),%rax
movb   $0x30,(%rdx,%rax,1)
mov    -0x30(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12e9 <replace_chars+0x199>
mov    -0x40(%rbp),%rdx
movslq -0x34(%rbp),%rax
movb   $0x40,(%rdx,%rax,1)
mov    -0x30(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12e9 <replace_chars+0x199>
mov    -0x40(%rbp),%rdx
movslq -0x34(%rbp),%rax
movb   $0x33,(%rdx,%rax,1)
mov    -0x30(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12e9 <replace_chars+0x199>
mov    -0x40(%rbp),%rdx
movslq -0x34(%rbp),%rax
movb   $0x24,(%rdx,%rax,1)
mov    -0x30(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12ee <replace_chars+0x19e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11fc <replace_chars+0xac>
jmp    11c4 <replace_chars+0x74>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_chars>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e72(%rip),%r13
mov    0x0(%r13),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1070 <clear_buf@plt>
lea    0xe6b(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe5b(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14,-0x38(%rbp)
mov    %r14d,%esi
mov    %r15,-0x30(%rbp)
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1254 <replace_chars+0x104>
mov    $0x285,%r14d
jmp    11f5 <replace_chars+0xa5>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1254 <replace_chars+0x104>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
cmpl   $0x0,0x0(%r13)
jle    11e0 <replace_chars+0x90>
xor    %r15d,%r15d
jmp    121d <replace_chars+0xcd>
nopl   0x0(%rax)
add    $0x1,%r15
movslq 0x0(%r13),%rax
cmp    %rax,%r15
jge    11e0 <replace_chars+0x90>
movsbl (%rbx,%r15,1),%eax
test   %eax,%eax
je     11e0 <replace_chars+0x90>
add    $0xffffff9f,%eax
ror    %eax
cmp    $0x9,%eax
ja     1210 <replace_chars+0xc0>
bt     %eax,%r14d
jae    1210 <replace_chars+0xc0>
cltq
lea    0xdc6(%rip),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %al,(%rbx,%r15,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
jmp    1210 <replace_chars+0xc0>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @replace_chars(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
store i32 0, i32* %9
%14 = call i32 @clear_buf(i8* %13)
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
br label %19
19: ; preds = %74, %2
%20 = trunc i64 %11 to i32
%21 = load i32*, i32** %7
%22 = call i64 @fgets(i8* %13, i32 %20, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %75
24: ; preds = %19
%25 = load i32*, i32** %8
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
store i32 0, i32* %9
br label %27
27: ; preds = %71, %24
%28 = load i32, i32* %9
%29 = load i32, i32* @BUFSIZ
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %13, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br label %38
38: ; preds = %31, %27
%39 = phi i1 [ false, %27 ], [ %37, %31 ]
br i1 %39, label %40, label %74
40: ; preds = %38
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %13, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
switch i32 %45, label %70 [
i32 111, label %46
i32 97, label %52
i32 101, label %58
i32 115, label %64
]
46: ; preds = %40
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %13, i64 %48
store i8 48, i8* %49
%50 = load i32*, i32** %8
%51 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %70
52: ; preds = %40
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %13, i64 %54
store i8 64, i8* %55
%56 = load i32*, i32** %8
%57 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %70
58: ; preds = %40
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %13, i64 %60
store i8 51, i8* %61
%62 = load i32*, i32** %8
%63 = call i32 @fprintf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %70
64: ; preds = %40
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %13, i64 %66
store i8 36, i8* %67
%68 = load i32*, i32** %8
%69 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %70
70: ; preds = %40, %64, %58, %52, %46
br label %71
71: ; preds = %70
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %27
74: ; preds = %38
br label %19
75: ; preds = %19
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %8
%79 = call i32 @fclose(i32* %78)
%80 = load i8*, i8** %5
ret i32 0
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@switch.table.replace_chars = [10 x i8] c"@03000000$"
define i32 @replace_chars(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @clear_buf(i8* %5)
%7 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %43, label %11
11: ; preds = %2, %40
%12 = call i32 @fputs(i8* %5, i32* %8)
%13 = load i32, i32* @BUFSIZ
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %40
15: ; preds = %11, %35
%16 = phi i64 [ %36, %35 ], [ 0, %11 ]
%17 = getelementptr inbounds i8, i8* %5, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %40, label %20
20: ; preds = %15
%21 = sext i8 %18 to i32
%22 = add nsw i32 %21, -97
%23 = call i32 @llvm.fshl.i32(i32 %22, i32 %22, i32 31)
%24 = icmp ult i32 %23, 10
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = trunc i32 %23 to i16
%27 = lshr i16 645, %26
%28 = and i16 %27, 1
%29 = icmp eq i16 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = sext i32 %23 to i64
%32 = getelementptr inbounds [10 x i8], [10 x i8]* @switch.table.replace_chars, i64 0, i64 %31
%33 = load i8, i8* %32
store i8 %33, i8* %17
%34 = call i32 @fputs(i8* %5, i32* %8)
br label %35
35: ; preds = %25, %20, %30
%36 = add nuw nsw i64 %16, 1
%37 = load i32, i32* @BUFSIZ
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %15, label %40
40: ; preds = %15, %35, %11
%41 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %11
43: ; preds = %40, %2
%44 = call i32 @fclose(i32* %7)
%45 = call i32 @fclose(i32* %8)
ret i32 0
}