#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);
char *char_replace(char *str, char o, char n) {
  char *p = str;
  if (str == NULL || *str == '\0')
    return str;
  while ((p = strchr(p, o)) != NULL)
    *p++ = n;
  return str;
}


x86 assembly (clang, -O0):
<char_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114a <char_replace+0x3a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1157 <char_replace+0x47>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <char_replace+0x88>
jmp    115c <char_replace+0x4c>
mov    -0x20(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1190 <char_replace+0x80>
mov    -0x12(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    115c <char_replace+0x4c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_replace>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     1147 <char_replace+0x37>
cmpb   $0x0,(%r14)
je     1147 <char_replace+0x37>
mov    %edx,%ebx
movsbl %sil,%ebp
mov    %r14,%rdi
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1147 <char_replace+0x37>
mov    %bl,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
jmp    1130 <char_replace+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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