#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 */
char *strchr(char *, char const);
int replaceChr(char *const aString, char const aOldChr, char const aNewChr) {
  char *p;
  int lRes = 0;
  if (!aString) {
    return 0;
  }
  if (aOldChr == aNewChr) {
    return 0;
  }
  p = aString;
  while ((p = strchr(p, aOldChr))) {
    *p = aNewChr;
    p++;
    lRes = 1;
  }
  return lRes;
}


x86 assembly (clang, -O0):
<replaceChr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1145 <replaceChr+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11ab <replaceChr+0x9b>
movsbl -0x11(%rbp),%eax
movsbl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jne    1161 <replaceChr+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11ab <replaceChr+0x9b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11a5 <replaceChr+0x95>
mov    -0x12(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1169 <replaceChr+0x59>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceChr>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
test   %rdi,%rdi
je     115b <replaceChr+0x4b>
mov    %edx,%ebx
cmp    %bl,%sil
je     115b <replaceChr+0x4b>
movsbl %sil,%ebp
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     115b <replaceChr+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %bl,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1140 <replaceChr+0x30>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @replaceChr(i8* %0, i8 signext %1, i8 signext %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8 %1, %2
%6 = or i1 %4, %5
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = tail call i8* @strchr(i8* %0, i8 signext %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %7, %10
%11 = phi i8* [ %13, %10 ], [ %8, %7 ]
store i8 %2, i8* %11
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = tail call i8* @strchr(i8* %12, i8 signext %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10, %7, %3
%16 = phi i32 [ 0, %3 ], [ 0, %7 ], [ 1, %10 ]
ret i32 %16
}