#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int swapOccurrences(char *string, char toChange) {
  int i = 0, counter = 0;
  char to = ' ';
  printf("Cambiar por: ");
  scanf("%c", &to);
  while (string[i]) {
    if (string[i] == toChange) {
      string[i] = to;
      counter++;
    }
    i++;
  }
  return counter;
}


x86 assembly (clang, -O0):
<swapOccurrences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x20,-0x15(%rbp)
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x15(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11af <swapOccurrences+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11a1 <swapOccurrences+0x81>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <swapOccurrences+0x40>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swapOccurrences>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movb   $0x20,0x7(%rsp)
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    (%rbx),%dl
test   %dl,%dl
je     1178 <swapOccurrences+0x58>
mov    0x7(%rsp),%cl
add    $0x1,%rbx
xor    %eax,%eax
jmp    116b <swapOccurrences+0x4b>
nopl   0x0(%rax)
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %dl,%dl
je     117a <swapOccurrences+0x5a>
cmp    %bpl,%dl
jne    1160 <swapOccurrences+0x40>
mov    %cl,-0x1(%rbx)
add    $0x1,%eax
jmp    1160 <swapOccurrences+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Cambiar por: \00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @swapOccurrences(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i8 32, i8* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %10
10: ; preds = %35, %2
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %23, %25
br i1 %26, label %27, label %35
27: ; preds = %17
%28 = load i8, i8* %7
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %35
35: ; preds = %27, %17
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %10
38: ; preds = %10
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
@.str = [14 x i8] c"Cambiar por: \00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @swapOccurrences(i8* nocapture %0, i8 signext %1) {
%3 = alloca i8
store i8 32, i8* %3
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = load i8, i8* %3
br label %10
10: ; preds = %8, %18
%11 = phi i64 [ 0, %8 ], [ %20, %18 ]
%12 = phi i8 [ %6, %8 ], [ %22, %18 ]
%13 = phi i8* [ %0, %8 ], [ %21, %18 ]
%14 = phi i32 [ 0, %8 ], [ %19, %18 ]
%15 = icmp eq i8 %12, %1
br i1 %15, label %16, label %18
16: ; preds = %10
store i8 %9, i8* %13
%17 = add nsw i32 %14, 1
br label %18
18: ; preds = %16, %10
%19 = phi i32 [ %17, %16 ], [ %14, %10 ]
%20 = add nuw i64 %11, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %10
24: ; preds = %18, %2
%25 = phi i32 [ 0, %2 ], [ %19, %18 ]
ret i32 %25
}