#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__ convert(char const *, char const *, char const *, int, char **, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ unac_string_utf16(char *, int, char **, int *);
char const *utf16be();
int unac_string(const char *charset, const char *in, size_t in_length,
                char **outp, size_t *out_lengthp) {
  if (in_length <= 0) {
    if (!*outp)
      *outp = malloc(32);
    (*outp)[0] = '\0';
    *out_lengthp = 0;
  } else {
    char *utf16 = 0;
    int utf16_length = 0;
    char *utf16_unaccented = 0;
    int utf16_unaccented_length = 0;
    if (convert(charset, utf16be(), in, in_length, &utf16, &utf16_length) < 0) {
      return -1;
    }
    unac_string_utf16(utf16, utf16_length, &utf16_unaccented,
                      &utf16_unaccented_length);
    free(utf16);
    if (convert(utf16be(), charset, utf16_unaccented, utf16_unaccented_length,
                outp, out_lengthp) < 0) {
      return -1;
    }
    free(utf16_unaccented);
  }
  return 0;
}


x86 assembly (clang, -O0):
<unac_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     11b3 <unac_string+0x63>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1199 <unac_string+0x49>
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
jmp    1276 <unac_string+0x126>
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1070 <utf16be@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
lea    -0x3c(%rbp),%r9
mov    $0x0,%al
call   1040 <convert@plt>
cmp    $0x0,%rax
jge    1216 <unac_string+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    127d <unac_string+0x12d>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x48(%rbp),%rdx
lea    -0x4c(%rbp),%rcx
call   1060 <unac_string_utf16@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <utf16be@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    $0x0,%al
call   1040 <convert@plt>
cmp    $0x0,%rax
jge    126d <unac_string+0x11d>
movl   $0xffffffff,-0x4(%rbp)
jmp    127d <unac_string+0x12d>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unac_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8,%r14
mov    %rcx,%r15
test   %rdx,%rdx
je     1216 <unac_string+0xc6>
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r12
movq   $0x0,0x18(%rsp)
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1070 <utf16be@plt>
lea    0x18(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <convert@plt>
test   %rax,%rax
js     1239 <unac_string+0xe9>
mov    0x18(%rsp),%rdi
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <unac_string_utf16@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <utf16be@plt>
mov    0x10(%rsp),%rdx
mov    0x8(%rsp),%ecx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <convert@plt>
test   %rax,%rax
js     1239 <unac_string+0xe9>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
jmp    123e <unac_string+0xee>
mov    (%r15),%rax
test   %rax,%rax
jne    122b <unac_string+0xdb>
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
movb   $0x0,(%rax)
movq   $0x0,(%r14)
xor    %ebp,%ebp
jmp    123e <unac_string+0xee>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unac_string(i8* %0, i8* %1, i64 %2, i8** %3, i64* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i64*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8** %3, i8*** %10
store i64* %4, i64** %11
%16 = load i64, i64* %9
%17 = icmp ule i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %5
%19 = load i8**, i8*** %10
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = call i8* @malloc(i32 32)
%24 = load i8**, i8*** %10
store i8* %23, i8** %24
br label %25
25: ; preds = %22, %18
%26 = load i8**, i8*** %10
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 0, i8* %28
%29 = load i64*, i64** %11
store i64 0, i64* %29
br label %57
30: ; preds = %5
store i8* null, i8** %12
store i32 0, i32* %13
store i8* null, i8** %14
store i32 0, i32* %15
%31 = load i8*, i8** %7
%32 = call i8* (...) @utf16be()
%33 = load i8*, i8** %8
%34 = load i64, i64* %9
%35 = trunc i64 %34 to i32
%36 = call i64 (i8*, i8*, i8*, i32, i8**, ...) @convert(i8* %31, i8* %32, i8* %33, i32 %35, i8** %12, i32* %13)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 -1, i32* %6
br label %58
39: ; preds = %30
%40 = load i8*, i8** %12
%41 = load i32, i32* %13
%42 = call i32 @unac_string_utf16(i8* %40, i32 %41, i8** %14, i32* %15)
%43 = load i8*, i8** %12
%44 = call i32 @free(i8* %43)
%45 = call i8* (...) @utf16be()
%46 = load i8*, i8** %7
%47 = load i8*, i8** %14
%48 = load i32, i32* %15
%49 = load i8**, i8*** %10
%50 = load i64*, i64** %11
%51 = call i64 (i8*, i8*, i8*, i32, i8**, ...) @convert(i8* %45, i8* %46, i8* %47, i32 %48, i8** %49, i64* %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %39
store i32 -1, i32* %6
br label %58
54: ; preds = %39
%55 = load i8*, i8** %14
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %54, %25
store i32 0, i32* %6
br label %58
58: ; preds = %57, %53, %38
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
define i32 @unac_string(i8* %0, i8* %1, i64 %2, i8** %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = icmp eq i64 %2, 0
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
store i8* %15, i8** %3
br label %16
16: ; preds = %14, %11
%17 = phi i8* [ %15, %14 ], [ %12, %11 ]
store i8 0, i8* %17
store i64 0, i64* %4
br label %42
18: ; preds = %5
%19 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%20 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%21 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%22 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%23 = tail call i8* (...) @utf16be()
%24 = trunc i64 %2 to i32
%25 = call i64 (i8*, i8*, i8*, i32, i8**, ...) @convert(i8* %0, i8* %23, i8* %1, i32 %24, i8** %6, i32* %7)
%26 = icmp slt i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %18
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = call i32 @unac_string_utf16(i8* %28, i32 %29, i8** %8, i32* %9)
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
%33 = call i8* (...) @utf16be()
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = call i64 (i8*, i8*, i8*, i32, i8**, ...) @convert(i8* %33, i8* %0, i8* %34, i32 %35, i8** %3, i64* %4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %18, %27
br label %42
39: ; preds = %27
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %16, %39, %38
%43 = phi i32 [ -1, %38 ], [ 0, %39 ], [ 0, %16 ]
ret i32 %43
}