#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 */
unsigned int decode_utf16(unsigned short const **);
unsigned short *get_decomp_record(unsigned int);
int ucdn_compat_decompose(unsigned int code, unsigned int *decomposed) {
  int i, len;
  const unsigned short *rec = get_decomp_record(code);
  len = rec[0] >> 8;
  if (len == 0)
    return 0;
  rec++;
  for (i = 0; i < len; i++)
    decomposed[i] = decode_utf16(&rec);
  return len;
}


x86 assembly (clang, -O0):
<ucdn_compat_decompose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <get_decomp_record@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzwl (%rax),%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    115e <ucdn_compat_decompose+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <ucdn_compat_decompose+0x87>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a1 <ucdn_compat_decompose+0x81>
lea    -0x20(%rbp),%rdi
call   1040 <decode_utf16@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <ucdn_compat_decompose+0x51>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ucdn_compat_decompose>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
call   1030 <get_decomp_record@plt>
movzwl (%rax),%r15d
xor    %ecx,%ecx
cmp    $0x100,%r15d
jb     1188 <ucdn_compat_decompose+0x68>
shr    $0x8,%r15d
add    $0x2,%rax
mov    %rax,0x8(%rsp)
cmp    $0x2,%r15d
mov    $0x1,%ebp
cmovae %r15d,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <decode_utf16@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <ucdn_compat_decompose+0x50>
mov    %r15d,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ucdn_compat_decompose(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16*
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32, i32* %4
%10 = call i16* @get_decomp_record(i32 %9)
store i16* %10, i16** %8
%11 = load i16*, i16** %8
%12 = getelementptr inbounds i16, i16* %11, i64 0
%13 = load i16, i16* %12
%14 = zext i16 %13 to i32
%15 = ashr i32 %14, 8
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %3
br label %37
19: ; preds = %2
%20 = load i16*, i16** %8
%21 = getelementptr inbounds i16, i16* %20, i32 1
store i16* %21, i16** %8
store i32 0, i32* %6
br label %22
22: ; preds = %32, %19
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = call i32 @decode_utf16(i16** %8)
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %22
35: ; preds = %22
%36 = load i32, i32* %7
store i32 %36, i32* %3
br label %37
37: ; preds = %35, %18
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @ucdn_compat_decompose(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i16*
%4 = bitcast i16** %3 to i8*
%5 = tail call i16* @get_decomp_record(i32 %0)
%6 = load i16, i16* %5
%7 = lshr i16 %6, 8
%8 = zext i16 %7 to i32
%9 = icmp ult i16 %6, 256
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = getelementptr inbounds i16, i16* %5, i64 1
store i16* %11, i16** %3
%12 = call i32 @llvm.umax.i32(i32 %8, i32 1)
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %18, %14 ]
%16 = call i32 @decode_utf16(i16** %3)
%17 = getelementptr inbounds i32, i32* %1, i64 %15
store i32 %16, i32* %17
%18 = add nuw nsw i64 %15, 1
%19 = icmp eq i64 %18, %13
br i1 %19, label %20, label %14
20: ; preds = %14, %2
%21 = phi i32 [ 0, %2 ], [ %8, %14 ]
ret i32 %21
}