#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 /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
int main() {
  char a[] = "Humpty dumpty sat on a wall";
  char search_char = 'u';
  char replace_char = 'o';
  char *ap = (char *)&a[0];
  printf("Before: %s\n", a);
  while ((ap = strchr(ap, search_char)) != NULL) {
    ap[0] = replace_char;
  }
  printf("After: %s\n", a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec2(%rip),%eax
mov    %eax,-0x8(%rbp)
movb   $0x75,-0x21(%rbp)
movb   $0x6f,-0x22(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11a2 <main+0x82>
mov    -0x22(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
jmp    1179 <main+0x59>
lea    -0x20(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movups 0xee0(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed9(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x75,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <main+0x57>
movb   $0x6f,(%rax)
mov    %rax,%rdi
jmp    1160 <main+0x40>
lea    0xeaa(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.a = [28 x i8] c"Humpty dumpty sat on a wall\00"
@.str = [12 x i8] c"Before: %s\0A\00"
@.str.1 = [11 x i8] c"After: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [28 x i8]
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [28 x i8]* %2 to i8*
store i8 117, i8* %3
store i8 111, i8* %4
%7 = getelementptr inbounds [28 x i8], [28 x i8]* %2, i64 0, i64 0
store i8* %7, i8** %5
%8 = getelementptr inbounds [28 x i8], [28 x i8]* %2, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %15, %0
%11 = load i8*, i8** %5
%12 = load i8, i8* %3
%13 = call i8* @strchr(i8* %11, i8 signext %12)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8, i8* %4
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 %16, i8* %18
br label %10
19: ; preds = %10
%20 = getelementptr inbounds [28 x i8], [28 x i8]* %2, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %20)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [28 x i8] c"Humpty dumpty sat on a wall\00"
@.str = [12 x i8] c"Before: %s\0A\00"
@.str.1 = [11 x i8] c"After: %s\0A\00"
define i32 @main() {
%1 = alloca [28 x i8]
%2 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 117)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0, %6
%7 = phi i8* [ %8, %6 ], [ %4, %0 ]
store i8 111, i8* %7
%8 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 117)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %6
10: ; preds = %6, %0
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}