#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*/ UNormalizer2;
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*/ unorm2_normalize(int /*<<< orphan*/ const *,
                                    int /*<<< orphan*/ *, int /*<<< orphan*/,
                                    int /*<<< orphan*/ *, int, scalar_t__ *);
int normalize(const char *str, char *res, const UNormalizer2 *normalizer) {
  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 = unorm2_normalize(normalizer, ubuf, ulen, 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    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e9a(%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   1040 <u_strFromUTF8@plt>
mov    -0x28(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
je     1198 <normalize+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <normalize+0x113>
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x830(%rbp),%rcx
mov    $0x100,%r8d
lea    -0x28(%rbp),%r9
call   1030 <unorm2_normalize@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
je     11ed <normalize+0xbd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <normalize+0x113>
mov    0x2df4(%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    0x2dc1(%rip),%rcx
cmp    (%rcx),%rax
je     123c <normalize+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <normalize+0x113>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rcx
mov    0x2e9b(%rip),%r15
mov    (%r15),%rax
mov    %rax,(%rsp)
lea    0x410(%rsp),%rdi
lea    0xc(%rsp),%rdx
mov    $0xffffffff,%ebp
mov    %rsp,%r9
mov    $0x100,%esi
mov    $0xffffffff,%r8d
call   1040 <u_strFromUTF8@plt>
mov    (%rsp),%rax
cmp    (%r15),%rax
jne    11d6 <normalize+0xa6>
mov    0xc(%rsp),%edx
lea    0x410(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rsp,%r9
mov    %rbx,%rdi
mov    $0x100,%r8d
call   1030 <unorm2_normalize@plt>
mov    (%rsp),%rcx
cmp    (%r15),%rcx
jne    11d6 <normalize+0xa6>
lea    0x10(%rsp),%rcx
mov    %rsp,%r9
mov    %r14,%rdi
mov    $0x100,%esi
xor    %edx,%edx
mov    %eax,%r8d
call   1050 <u_strToUTF8@plt>
mov    (%rsp),%rax
xor    %ebp,%ebp
cmp    (%r15),%rax
setne  %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x818,%rsp
pop    %rbx
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 = load i32*, i32** %7
%24 = getelementptr inbounds [256 x i32], [256 x i32]* %11, i64 0, i64 0
%25 = load i32, i32* %9
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %12, i64 0, i64 0
%27 = call i32 @unorm2_normalize(i32* %23, i32* %24, i32 %25, 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 @unorm2_normalize(i32* %2, i32* %13, i32 %19, 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
}