#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__ strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strstr(char const *, char *);
int substitute(char const *, char *, char *, char *, int);
int make_utf8_forms(const char *utf8, char *nonNbsp, char *nbsp) {
  int success;
  if (strchr(utf8, '_')) {
    success = substitute(utf8, "_", nbsp, "\xC2\xA0", 128);
    if (success)
      success = substitute(nbsp, "\xC2\xA0", nonNbsp, "_", 128);
  } else if (strstr(utf8, "\xC2\xA0")) {
    success = substitute(utf8, "\xC2\xA0", nonNbsp, "_", 128);
    if (success)
      success = substitute(nonNbsp, "_", nbsp, "\xC2\xA0", 128);
  } else {
    (void)strcpy(nonNbsp, utf8);
    *nbsp = 0;
    success = 1;
  }
  return success;
}


x86 assembly (clang, -O0):
<make_utf8_forms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5f,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11c3 <make_utf8_forms+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe85(%rip),%rsi
lea    0xe80(%rip),%rcx
mov    $0x80,%r8d
call   1050 <substitute@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11be <make_utf8_forms+0x7e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe59(%rip),%rsi
lea    0xe50(%rip),%rcx
mov    $0x80,%r8d
call   1050 <substitute@plt>
mov    %eax,-0x1c(%rbp)
jmp    1254 <make_utf8_forms+0x114>
mov    -0x8(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     1234 <make_utf8_forms+0xf4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe16(%rip),%rsi
lea    0xe0d(%rip),%rcx
mov    $0x80,%r8d
call   1050 <substitute@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     122f <make_utf8_forms+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xde6(%rip),%rsi
lea    0xde1(%rip),%rcx
mov    $0x80,%r8d
call   1050 <substitute@plt>
mov    %eax,-0x1c(%rbp)
jmp    124f <make_utf8_forms+0x10f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x1c(%rbp)
jmp    1254 <make_utf8_forms+0x114>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_utf8_forms>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x5f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1196 <make_utf8_forms+0x56>
lea    0xe9c(%rip),%rsi
lea    0xe97(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    $0x80,%r8d
call   1050 <substitute@plt>
test   %eax,%eax
je     11f1 <make_utf8_forms+0xb1>
lea    0xe7b(%rip),%rsi
lea    0xe72(%rip),%rcx
mov    %r15,%rdi
mov    %r14,%rdx
jmp    11e1 <make_utf8_forms+0xa1>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11f5 <make_utf8_forms+0xb5>
lea    0xe51(%rip),%rsi
lea    0xe48(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x80,%r8d
call   1050 <substitute@plt>
test   %eax,%eax
je     11f1 <make_utf8_forms+0xb1>
lea    0xe2c(%rip),%rsi
lea    0xe27(%rip),%rcx
mov    %r14,%rdi
mov    %r15,%rdx
mov    $0x80,%r8d
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <substitute@plt>
xor    %eax,%eax
jmp    1209 <make_utf8_forms+0xc9>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movb   $0x0,(%r15)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"_\00"
@.str.1 = [3 x i8] c"\C2\A0\00"
define i32 @make_utf8_forms(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i64 @strchr(i8* %8, i8 signext 95)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %6
%14 = call i32 @substitute(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 128)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = call i32 @substitute(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 128)
store i32 %20, i32* %7
br label %21
21: ; preds = %17, %11
br label %43
22: ; preds = %3
%23 = load i8*, i8** %4
%24 = call i64 @strstr(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i32 @substitute(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 128)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i32 @substitute(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 128)
store i32 %35, i32* %7
br label %36
36: ; preds = %32, %26
br label %42
37: ; preds = %22
%38 = load i8*, i8** %5
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %6
store i8 0, i8* %41
store i32 1, i32* %7
br label %42
42: ; preds = %37, %36
br label %43
43: ; preds = %42, %21
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"_\00"
@.str.1 = [3 x i8] c"\C2\A0\00"
define i32 @make_utf8_forms(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strchr(i8* %0, i8 signext 95)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @substitute(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 128)
%8 = icmp eq i32 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = tail call i32 @substitute(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 128)
br label %21
11: ; preds = %3
%12 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = tail call i32 @substitute(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 128)
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i32 @substitute(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 128)
br label %21
19: ; preds = %11
%20 = tail call i32 @strcpy(i8* %1, i8* %0)
store i8 0, i8* %2
br label %21
21: ; preds = %19, %17, %14, %6, %9
%22 = phi i32 [ %10, %9 ], [ 0, %6 ], [ %18, %17 ], [ 0, %14 ], [ 1, %19 ]
ret i32 %22
}