#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 */
size_t strlen(char *);
char *strxreplace(char *s, char c1, char c2) {
  size_t ii;
  for (ii = 0; ii < strlen(s); ++ii)
    if (s[ii] == c1)
      s[ii] = c2;
  return s;
}


x86 assembly (clang, -O0):
<strxreplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    118c <strxreplace+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1176 <strxreplace+0x66>
mov    -0xa(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    117b <strxreplace+0x6b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112f <strxreplace+0x1f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strxreplace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1151 <strxreplace+0x41>
mov    %edx,%r14d
mov    %esi,%r15d
mov    $0x1,%ebp
cmp    %r15b,%al
jne    1135 <strxreplace+0x25>
mov    %r14b,-0x1(%rbx,%rbp,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbp
jae    1151 <strxreplace+0x41>
movzbl (%rbx,%rbp,1),%eax
add    $0x1,%rbp
cmp    %r15b,%al
je     1130 <strxreplace+0x20>
jmp    1135 <strxreplace+0x25>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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