#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 EXIT_SUCCESS;
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
char *troca_letra(char *, char, char);
int main(int argc, char **argv) {
  char nova, antiga;
  char palavra[20];
  char *p;
  printf("Digite a palavra: ");
  scanf("%s", palavra);
  getchar();
  printf("Digite letra a ser substituida: ");
  scanf("%c", &antiga);
  getchar();
  printf("Digite letra a nova letra: ");
  scanf("%c", &nova);
  p = troca_letra(palavra, antiga, nova);
  printf("Antiga: %s\nNova: %s", palavra, p);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xef5(%rip),%rdi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0x12(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x12(%rbp),%al
movsbl %al,%esi
movsbl -0x11(%rbp),%edx
call   1030 <troca_letra@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf08(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaf(%rip),%rbx
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movsbl 0xe(%rsp),%esi
movsbl 0xf(%rsp),%edx
mov    %r14,%rdi
call   1030 <troca_letra@plt>
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Digite a palavra: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [33 x i8] c"Digite letra a ser substituida: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [28 x i8] c"Digite letra a nova letra: \00"
@.str.5 = [20 x i8] c"Antiga: %s\0ANova: %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca [20 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 (...) @getchar()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%16 = call i32 (...) @getchar()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%20 = load i8, i8* %7
%21 = load i8, i8* %6
%22 = call i8* @troca_letra(i8* %19, i8 signext %20, i8 signext %21)
store i8* %22, i8** %9
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
@.str = [19 x i8] c"Digite a palavra: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [33 x i8] c"Digite letra a ser substituida: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [28 x i8] c"Digite letra a nova letra: \00"
@.str.5 = [20 x i8] c"Antiga: %s\0ANova: %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%9 = call i32 (...) @getchar()
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%12 = call i32 (...) @getchar()
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%15 = load i8, i8* %4
%16 = load i8, i8* %3
%17 = call i8* @troca_letra(i8* %6, i8 signext %15, i8 signext %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %17)
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}