#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 */
scalar_t__ utf8_is_valid(char *, char **);
void utf8_normalize(char *string, char replacement) {
  char *error;
  while (string && string[0]) {
    if (utf8_is_valid(string, &error))
      return;
    error[0] = replacement;
    string = error + 1;
  }
}


x86 assembly (clang, -O0):
<utf8_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     1142 <utf8_normalize+0x32>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1152 <utf8_normalize+0x42>
jmp    1188 <utf8_normalize+0x78>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <utf8_is_valid@plt>
cmp    $0x0,%rax
je     116e <utf8_normalize+0x5e>
jmp    1188 <utf8_normalize+0x78>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1122 <utf8_normalize+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_normalize>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1151 <utf8_normalize+0x41>
cmpb   $0x0,(%rdi)
je     1151 <utf8_normalize+0x41>
mov    %esi,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rsi
call   1030 <utf8_is_valid@plt>
test   %rax,%rax
jne    1151 <utf8_normalize+0x41>
mov    (%rsp),%rax
mov    %bl,(%rax)
mov    (%rsp),%rax
lea    0x1(%rax),%rdi
cmpb   $0x0,0x1(%rax)
jne    1130 <utf8_normalize+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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