#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int swapOccurrences(char *, char);
int main() {
  char string[100];
  char toChange = ' ';
  int times = 0;
  gets(string);
  printf("Ingresa el caracter a cambiar: ");
  scanf("%c", &toChange);
  setbuf(stdin, NULL);
  times = swapOccurrences(string, toChange);
  printf("%s \n", string);
  printf("%d ocurrencias\n", times);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x20,-0x71(%rbp)
movl   $0x0,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0x71(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
lea    -0x70(%rbp),%rdi
movsbl -0x71(%rbp),%esi
call   1050 <swapOccurrences@plt>
mov    %eax,-0x78(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
movb   $0x20,0xf(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
call   1050 <swapOccurrences@plt>
mov    %eax,%ebp
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Ingresa el caracter a cambiar: \00"
@.str.1 = [3 x i8] c"%c\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"%s \0A\00"
@.str.3 = [16 x i8] c"%d ocurrencias\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i8 32, i8* %3
store i32 0, i32* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 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* %3)
%9 = load i32, i32* @stdin
%10 = call i32 @setbuf(i32 %9, i32* null)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %3
%13 = call i32 @swapOccurrences(i8* %11, i8 signext %12)
store i32 %13, i32* %4
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Ingresa el caracter a cambiar: \00"
@.str.1 = [3 x i8] c"%c\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"%s \0A\00"
@.str.3 = [16 x i8] c"%d ocurrencias\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 32, i8* %2
%4 = call i32 @gets(i8* %3)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = load i32, i32* @stdin
%8 = call i32 @setbuf(i32 %7, i32* null)
%9 = load i8, i8* %2
%10 = call i32 @swapOccurrences(i8* %3, i8 signext %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %10)
ret i32 0
}