#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 */
int hangul_split(unsigned int, unsigned int *, unsigned int *, unsigned int *);
unsigned int utf8_decode(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ utf8_encode_nt(unsigned int, char *, int);
int hangul_split_utf8char(const char *utf8char, char *lead_utf8char,
                          char *vowel_utf8char, char *tail_utf8char) {
  unsigned int lead = 0, vowel = 0, tail = 0, ch;
  int ret;
  ch = utf8_decode(utf8char, NULL);
  ret = hangul_split(ch, &lead, &vowel, &tail);
  if (ret == 0) {
    if (lead_utf8char)
      utf8_encode_nt(lead, lead_utf8char, 4);
    if (vowel_utf8char)
      utf8_encode_nt(vowel, vowel_utf8char, 4);
    if (tail_utf8char) {
      if (tail)
        utf8_encode_nt(tail, tail_utf8char, 4);
      else
        tail_utf8char[0] = 0;
    }
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<hangul_split_utf8char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <utf8_decode@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <hangul_split@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    1209 <hangul_split_utf8char+0xd9>
cmpq   $0x0,-0x18(%rbp)
je     11aa <hangul_split_utf8char+0x7a>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
cmpq   $0x0,-0x20(%rbp)
je     11c6 <hangul_split_utf8char+0x96>
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
cmpq   $0x0,-0x28(%rbp)
je     11fd <hangul_split_utf8char+0xcd>
cmpl   $0x0,-0x34(%rbp)
je     11f1 <hangul_split_utf8char+0xc1>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
jmp    11f8 <hangul_split_utf8char+0xc8>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    11fd <hangul_split_utf8char+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    1210 <hangul_split_utf8char+0xe0>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hangul_split_utf8char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %esi,%esi
call   1040 <utf8_decode@plt>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %eax,%edi
call   1050 <hangul_split@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     118e <hangul_split_utf8char+0x5e>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbx,%rbx
je     11a4 <hangul_split_utf8char+0x74>
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
test   %r15,%r15
je     11ba <hangul_split_utf8char+0x8a>
mov    0x10(%rsp),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
xor    %ebp,%ebp
test   %r14,%r14
je     1181 <hangul_split_utf8char+0x51>
mov    0xc(%rsp),%edi
test   %edi,%edi
je     11d8 <hangul_split_utf8char+0xa8>
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <utf8_encode_nt@plt>
jmp    1181 <hangul_split_utf8char+0x51>
movb   $0x0,(%r14)
jmp    1181 <hangul_split_utf8char+0x51>

LLVM IR (-O0):
define i32 @hangul_split_utf8char(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load i8*, i8** %6
%16 = call i32 @utf8_decode(i8* %15, i32* null)
store i32 %16, i32* %13
%17 = load i32, i32* %13
%18 = call i32 @hangul_split(i32 %17, i32* %10, i32* %11, i32* %12)
store i32 %18, i32* %14
%19 = load i32, i32* %14
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %50
21: ; preds = %4
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %10
%26 = load i8*, i8** %7
%27 = call i32 @utf8_encode_nt(i32 %25, i8* %26, i32 4)
br label %28
28: ; preds = %24, %21
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %11
%33 = load i8*, i8** %8
%34 = call i32 @utf8_encode_nt(i32 %32, i8* %33, i32 4)
br label %35
35: ; preds = %31, %28
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = load i32, i32* %12
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %12
%43 = load i8*, i8** %9
%44 = call i32 @utf8_encode_nt(i32 %42, i8* %43, i32 4)
br label %48
45: ; preds = %38
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %48, %35
store i32 0, i32* %5
br label %51
50: ; preds = %4
store i32 -1, i32* %5
br label %51
51: ; preds = %50, %49
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @hangul_split_utf8char(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%10 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%11 = tail call i32 @utf8_decode(i8* %0, i32* null)
%12 = call i32 @hangul_split(i32 %11, i32* %5, i32* %6, i32* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %4
%15 = icmp eq i8* %1, null
br i1 %15, label %19, label %16
16: ; preds = %14
%17 = load i32, i32* %5
%18 = call i32 @utf8_encode_nt(i32 %17, i8* %1, i32 4)
br label %19
19: ; preds = %16, %14
%20 = icmp eq i8* %2, null
br i1 %20, label %24, label %21
21: ; preds = %19
%22 = load i32, i32* %6
%23 = call i32 @utf8_encode_nt(i32 %22, i8* %2, i32 4)
br label %24
24: ; preds = %21, %19
%25 = icmp eq i8* %3, null
br i1 %25, label %32, label %26
26: ; preds = %24
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @utf8_encode_nt(i32 %27, i8* %3, i32 4)
br label %32
31: ; preds = %26
store i8 0, i8* %3
br label %32
32: ; preds = %4, %24, %31, %29
%33 = phi i32 [ 0, %29 ], [ 0, %31 ], [ 0, %24 ], [ -1, %4 ]
ret i32 %33
}