#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 *, int);
void strrep(char *s, int find, int replace) {
  while (s && *s && (s = strchr(s, find)) != NULL)
    *s++ = replace;
}


x86 assembly (clang, -O0):
<strrep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1161 <strrep+0x51>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1161 <strrep+0x51>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1171 <strrep+0x61>
jmp    118c <strrep+0x7c>
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1122 <strrep+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrep>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     114b <strrep+0x3b>
cmpb   $0x0,(%rdi)
je     114b <strrep+0x3b>
mov    %edx,%ebx
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114b <strrep+0x3b>
mov    %rax,%rdi
add    $0x1,%rdi
mov    %bl,(%rax)
cmpb   $0x0,0x1(%rax)
jne    1130 <strrep+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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