#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 */

/* Variables and functions */
int /*<<< orphan*/ find_and_replace(char **, char, char);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void main() {
  char string[10], find, replace;
  printf("Enter a string: ");
  scanf("%s", &string);
  while (getchar() != '\n')
    ;
  printf("Replace what char?: ");
  scanf("%c", &find);
  while (getchar() != '\n')
    ;
  printf("With what char: ");
  scanf("%c", &replace);
  while (getchar() != '\n')
    ;
  find_and_replace(&string, find, replace);
  printf("Modified string: %s", string);
  return;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
lea    -0xa(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1180 <main+0x40>
jmp    1168 <main+0x28>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0xb(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11b8 <main+0x78>
jmp    11a0 <main+0x60>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11f0 <main+0xb0>
jmp    11d8 <main+0x98>
lea    -0xa(%rbp),%rdi
mov    -0xb(%rbp),%al
movsbl %al,%esi
movsbl -0xc(%rbp),%edx
call   1050 <find_and_replace@plt>
lea    -0xa(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    0x6(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1170 <main+0x30>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0x5(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <main+0x60>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe66(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11d0 <main+0x90>
movsbl 0x5(%rsp),%esi
movsbl 0x4(%rsp),%edx
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <find_and_replace@plt>
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [21 x i8] c"Replace what char?: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [17 x i8] c"With what char: \00"
@.str.5 = [20 x i8] c"Modified string: %s\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = alloca i8
%3 = alloca i8
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [10 x i8]* %1)
br label %6
6: ; preds = %10, %0
%7 = call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %11
10: ; preds = %6
br label %6
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %14
14: ; preds = %18, %11
%15 = call signext i8 (...) @getchar()
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %22
22: ; preds = %26, %19
%23 = call signext i8 (...) @getchar()
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %22
br label %22
27: ; preds = %22
%28 = bitcast [10 x i8]* %1 to i8**
%29 = load i8, i8* %2
%30 = load i8, i8* %3
%31 = call i32 @find_and_replace(i8** %28, i8 signext %29, i8 signext %30)
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [21 x i8] c"Replace what char?: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [17 x i8] c"With what char: \00"
@.str.5 = [20 x i8] c"Modified string: %s\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = alloca i8
%3 = alloca i8
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [10 x i8]* %1)
br label %7
7: ; preds = %7, %0
%8 = call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %7
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %13
13: ; preds = %13, %10
%14 = call signext i8 (...) @getchar()
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %13
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %19
19: ; preds = %19, %16
%20 = call signext i8 (...) @getchar()
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %19
22: ; preds = %19
%23 = bitcast [10 x i8]* %1 to i8**
%24 = load i8, i8* %2
%25 = load i8, i8* %3
%26 = call i32 @find_and_replace(i8** %23, i8 signext %24, i8 signext %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %4)
ret void
}