#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *replace_char_in_str(char *, char);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int main() {
  char text_string[99];
  printf("Enter a text string: ");
  fgets(text_string, 99, stdin);
  char letter;
  printf("Enter a letter to replace: ");
  scanf("%c", &letter);
  printf("%s\n", replace_char_in_str(text_string, letter));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x63,%esi
call   1040 <fgets@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x71(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x70(%rbp),%rdi
movsbl -0x71(%rbp),%esi
call   1060 <replace_char_in_str@plt>
mov    %rax,%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x63,%esi
call   1050 <fgets@plt>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
call   1070 <replace_char_in_str@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter a text string: \00"
@stdin = global i32 0
@.str.1 = [28 x i8] c"Enter a letter to replace: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [99 x i8]
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [99 x i8], [99 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 99, i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%10 = getelementptr inbounds [99 x i8], [99 x i8]* %2, i64 0, i64 0
%11 = load i8, i8* %3
%12 = call i8* @replace_char_in_str(i8* %10, i8 signext %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter a text string: \00"
@stdin = global i32 0
@.str.1 = [28 x i8] c"Enter a letter to replace: \00"
@.str.2 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca [99 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [99 x i8], [99 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 99, i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = load i8, i8* %2
%10 = call i8* @replace_char_in_str(i8* %3, i8 signext %9)
%11 = call i32 @puts(i8* dereferenceable(1) %10)
ret i32 0
}