#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 strlen(char *);
void replaceChar(char *s, char x, char replaceWith, int start) {
  int i;
  for (i = start; i < strlen(s); i++) {
    if (s[i] == x)
      s[i] = replaceWith;
  }
}


x86 assembly (clang, -O0):
<replaceChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1185 <replaceChar+0x75>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1172 <replaceChar+0x62>
mov    -0xa(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1177 <replaceChar+0x67>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <replaceChar+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceChar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    %r15d,%eax
jle    115f <replaceChar+0x4f>
movslq %r15d,%rbp
jmp    1153 <replaceChar+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    115f <replaceChar+0x4f>
cmp    %r12b,(%rbx,%rbp,1)
jne    1140 <replaceChar+0x30>
mov    %r14b,(%rbx,%rbp,1)
jmp    1140 <replaceChar+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @replaceChar(i8* %0, i8 signext %1, i8 signext %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
store i32 %10, i32* %9
br label %11
11: ; preds = %33, %4
%12 = load i32, i32* %9
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %36
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %6
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %32
26: ; preds = %16
%27 = load i8, i8* %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %26, %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %11
36: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @replaceChar(i8* %0, i8 signext %1, i8 signext %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, %3
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = sext i32 %3 to i64
br label %9
9: ; preds = %7, %15
%10 = phi i64 [ %8, %7 ], [ %16, %15 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
br i1 %13, label %14, label %15
14: ; preds = %9
store i8 %2, i8* %11
br label %15
15: ; preds = %9, %14
%16 = add nsw i64 %10, 1
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %9, label %20
20: ; preds = %15, %4
ret void
}