#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *file;
  FILE *ofile;
  char *i;
  char oldc, newc, c = '\n';
  char input[20];
  printf("NOTE: this character changer software only works on a file named "
         "\"input.txt\". Your results are in output.txt.\n");
  printf("Please rename your file if you need to.\n");
  printf("Type the character you want to replace\n");
  scanf("%c", &oldc);
  printf("Type the new character\n");
  scanf("\n%c", &newc);
  file = fopen("input.txt", "r");
  ofile = fopen("output.txt", "w");
  if (file != NULL) {
    printf("Starting work.\n");
    while (c != EOF) {
      c = fgetc(file);
      if (c == oldc) {
        fputc(newc, ofile);
      } else {
        fputc(c, ofile);
      }
    }
  }
  fclose(file);
  printf("Finished work.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0xa,-0x23(%rbp)
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    0xee9(%rip),%rdi
call   1040 <printf@plt>
lea    0xf06(%rip),%rdi
call   1040 <printf@plt>
lea    0xf3b(%rip),%rdi
lea    -0x21(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xf12(%rip),%rdi
call   1040 <printf@plt>
lea    0xf1e(%rip),%rdi
lea    -0x22(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xf12(%rip),%rdi
lea    0xf15(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xf07(%rip),%rdi
lea    0xf0b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1267 <main+0x107>
lea    0xef2(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x23(%rbp),%eax
mov    0x2dd5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1262 <main+0x102>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x23(%rbp)
movsbl -0x23(%rbp),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    124e <main+0xee>
mov    -0x22(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    125d <main+0xfd>
mov    -0x23(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1208 <main+0xa8>
jmp    1267 <main+0x107>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xf2a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6e(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
lea    0xe50(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xe43(%rip),%rdi
lea    0xf25(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe37(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1080 <fopen@plt>
test   %r15,%r15
je     1205 <main+0xa5>
mov    %rax,%r14
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dea(%rip),%r12
cmpb   $0xa,(%r12)
jne    1244 <main+0xe4>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
nopw   0x0(%rax,%rax,1)
movzbl %bl,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
cmp    (%r12),%bl
je     1205 <main+0xa5>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    0x7(%rsp),%al
jne    1230 <main+0xd0>
movzbl 0x6(%rsp),%eax
jmp    1233 <main+0xd3>

LLVM IR (-O0):
@.str = [111 x i8] c"NOTE: this character changer software only works on a file named \22input.txt\22. Your results are in output.txt.\0A\00"
@.str.1 = [41 x i8] c"Please rename your file if you need to.\0A\00"
@.str.2 = [40 x i8] c"Type the character you want to replace\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [24 x i8] c"Type the new character\0A\00"
@.str.5 = [4 x i8] c"\0A%c\00"
@.str.6 = [10 x i8] c"input.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [11 x i8] c"output.txt\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [16 x i8] c"Starting work.\0A\00"
@EOF = global i8 0
@.str.11 = [16 x i8] c"Finished work.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca [20 x i8]
store i32 0, i32* %1
store i8 10, i8* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%15 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %15, i32** %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %2
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %45
19: ; preds = %0
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %21
21: ; preds = %43, %19
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %44
27: ; preds = %21
%28 = load i32*, i32** %2
%29 = call signext i8 @fgetc(i32* %28)
store i8 %29, i8* %7
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %31, %33
br i1 %34, label %35, label %39
35: ; preds = %27
%36 = load i8, i8* %6
%37 = load i32*, i32** %3
%38 = call i32 @fputc(i8 signext %36, i32* %37)
br label %43
39: ; preds = %27
%40 = load i8, i8* %7
%41 = load i32*, i32** %3
%42 = call i32 @fputc(i8 signext %40, i32* %41)
br label %43
43: ; preds = %39, %35
br label %21
44: ; preds = %21
br label %45
45: ; preds = %44, %0
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%c\00"
@.str.5 = [4 x i8] c"\0A%c\00"
@.str.6 = [10 x i8] c"input.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [11 x i8] c"output.txt\00"
@.str.9 = [2 x i8] c"w\00"
@EOF = global i8 0
@str = [110 x i8] c"NOTE: this character changer software only works on a file named \22input.txt\22. Your results are in output.txt.\00"
@str.12 = [40 x i8] c"Please rename your file if you need to.\00"
@str.13 = [39 x i8] c"Type the character you want to replace\00"
@str.14 = [23 x i8] c"Type the new character\00"
@str.15 = [15 x i8] c"Finished work.\00"
@str.16 = [15 x i8] c"Starting work.\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([110 x i8], [110 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.12, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.14, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%11 = icmp eq i32* %9, null
br i1 %11, label %25, label %12
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.16, i64 0, i64 0))
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %14, 10
br i1 %15, label %25, label %16
16: ; preds = %12, %16
%17 = call signext i8 @fgetc(i32* %9)
%18 = load i8, i8* %1
%19 = icmp eq i8 %17, %18
%20 = load i8, i8* %2
%21 = select i1 %19, i8 %20, i8 %17
%22 = call i32 @fputc(i8 signext %21, i32* %10)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %17, %23
br i1 %24, label %25, label %16
25: ; preds = %16, %12, %0
%26 = call i32 @fclose(i32* %9)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.15, i64 0, i64 0))
ret i32 0
}