#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 */
typedef int /*<<< orphan*/ int32_t;
typedef int /*<<< orphan*/ UNormalizationMode;
typedef scalar_t__ UErrorCode;
typedef int /*<<< orphan*/ UChar;

/* Variables and functions */
scalar_t__ U_ZERO_ERROR;
int /*<<< orphan*/ u_strFromUTF8(int /*<<< orphan*/ *, int,
                                 int /*<<< orphan*/ *, char const *, int,
                                 scalar_t__ *);
int /*<<< orphan*/ u_strToUTF8(char *, int, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, int /*<<< orphan*/,
                               scalar_t__ *);
int /*<<< orphan*/ unorm_normalize(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/, int /*<<< orphan*/,
                                   int /*<<< orphan*/ *, int, scalar_t__ *);
int normalize(const char *str, char *res, UNormalizationMode mode) {
  UErrorCode rc;
  int32_t ulen, nlen;
  UChar ubuf[0x100], nbuf[0x100];
  rc = U_ZERO_ERROR;
  u_strFromUTF8(ubuf, 0x100, &ulen, str, -1, &rc);
  if (rc != U_ZERO_ERROR) {
    return -1;
  }
  rc = U_ZERO_ERROR;
  nlen = unorm_normalize(ubuf, ulen, mode, 0, nbuf, 0x100, &rc);
  if (rc != U_ZERO_ERROR) {
    return -1;
  }
  rc = U_ZERO_ERROR;
  u_strToUTF8(res, 0x100, NULL, nbuf, nlen, &rc);
  if (rc != U_ZERO_ERROR) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    -0x2c(%rbp),%rdx
mov    $0xffffffff,%r8d
lea    -0x28(%rbp),%r9
call   1030 <u_strFromUTF8@plt>
mov    -0x28(%rbp),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
je     1197 <normalize+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <normalize+0x117>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    -0x830(%rbp),%r8
xor    %ecx,%ecx
mov    $0x100,%r9d
lea    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <unorm_normalize@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
je     11f1 <normalize+0xc1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <normalize+0x117>
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x830(%rbp),%rcx
mov    -0x30(%rbp),%r8d
mov    $0x100,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x28(%rbp),%r9
call   1050 <u_strToUTF8@plt>
mov    -0x28(%rbp),%rax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%rax
je     1240 <normalize+0x110>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <normalize+0x117>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x820,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rcx
mov    0x2e99(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x10(%rsp)
lea    0x420(%rsp),%rdi
lea    0x1c(%rsp),%rdx
mov    $0xffffffff,%ebp
lea    0x10(%rsp),%rbx
mov    $0x100,%esi
mov    $0xffffffff,%r8d
mov    %rbx,%r9
call   1030 <u_strFromUTF8@plt>
mov    0x10(%rsp),%rax
cmp    (%r12),%rax
jne    11ea <normalize+0xba>
mov    0x1c(%rsp),%esi
mov    %rbx,(%rsp)
lea    0x420(%rsp),%rdi
lea    0x20(%rsp),%r8
mov    %r15d,%edx
xor    %ecx,%ecx
mov    $0x100,%r9d
call   1040 <unorm_normalize@plt>
mov    0x10(%rsp),%rcx
cmp    (%r12),%rcx
jne    11ea <normalize+0xba>
lea    0x20(%rsp),%rcx
lea    0x10(%rsp),%r9
mov    %r14,%rdi
mov    $0x100,%esi
xor    %edx,%edx
mov    %eax,%r8d
call   1050 <u_strToUTF8@plt>
mov    0x10(%rsp),%rax
xor    %ebp,%ebp
cmp    (%r12),%rax
setne  %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x820,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@U_ZERO_ERROR = global i64 0
define i32 @normalize(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i32]
%12 = alloca [256 x i32]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i64, i64* @U_ZERO_ERROR
store i64 %13, i64* %8
%14 = getelementptr inbounds [256 x i32], [256 x i32]* %11, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @u_strFromUTF8(i32* %14, i32 256, i32* %9, i8* %15, i32 -1, i64* %8)
%17 = load i64, i64* %8
%18 = load i64, i64* @U_ZERO_ERROR
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %43
21: ; preds = %3
%22 = load i64, i64* @U_ZERO_ERROR
store i64 %22, i64* %8
%23 = getelementptr inbounds [256 x i32], [256 x i32]* %11, i64 0, i64 0
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %12, i64 0, i64 0
%27 = call i32 @unorm_normalize(i32* %23, i32 %24, i32 %25, i32 0, i32* %26, i32 256, i64* %8)
store i32 %27, i32* %10
%28 = load i64, i64* %8
%29 = load i64, i64* @U_ZERO_ERROR
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %21
store i32 -1, i32* %4
br label %43
32: ; preds = %21
%33 = load i64, i64* @U_ZERO_ERROR
store i64 %33, i64* %8
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %12, i64 0, i64 0
%36 = load i32, i32* %10
%37 = call i32 @u_strToUTF8(i8* %34, i32 256, i32* null, i32* %35, i32 %36, i64* %8)
%38 = load i64, i64* %8
%39 = load i64, i64* @U_ZERO_ERROR
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %32
store i32 -1, i32* %4
br label %43
42: ; preds = %32
store i32 0, i32* %4
br label %43
43: ; preds = %42, %41, %31, %20
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@U_ZERO_ERROR = global i64 0
define i32 @normalize(i8* %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca [256 x i32]
%7 = alloca [256 x i32]
%8 = bitcast i64* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast [256 x i32]* %6 to i8*
%11 = bitcast [256 x i32]* %7 to i8*
%12 = load i64, i64* @U_ZERO_ERROR
store i64 %12, i64* %4
%13 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%14 = call i32 @u_strFromUTF8(i32* %13, i32 256, i32* %5, i8* %0, i32 -1, i64* %4)
%15 = load i64, i64* %4
%16 = load i64, i64* @U_ZERO_ERROR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %3
%19 = load i32, i32* %5
%20 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 0
%21 = call i32 @unorm_normalize(i32* %13, i32 %19, i32 %2, i32 0, i32* %20, i32 256, i64* %4)
%22 = load i64, i64* %4
%23 = load i64, i64* @U_ZERO_ERROR
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = call i32 @u_strToUTF8(i8* %1, i32 256, i32* null, i32* %20, i32 %21, i64* %4)
%27 = load i64, i64* %4
%28 = load i64, i64* @U_ZERO_ERROR
%29 = icmp ne i64 %27, %28
%30 = sext i1 %29 to i32
br label %31
31: ; preds = %25, %18, %3
%32 = phi i32 [ -1, %3 ], [ -1, %18 ], [ %30, %25 ]
ret i32 %32
}