#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 /*<<< orphan*/ gb2312_cpy(unsigned char const *, int *, unsigned int *,
                              int const);
int get_eci_length(int const, unsigned char const *, int);
scalar_t__ is_eci_convertible(int const);
int utf8_to_eci(int const, unsigned char const *, unsigned char *, int *);
__attribute__((visibility("hidden"))) int
gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length,
                   unsigned int *gbdata, const int full_multibyte) {
  if (is_eci_convertible(eci)) {
    int error_number;
    int eci_length = get_eci_length(eci, source, *p_length);
    unsigned char converted[eci_length + 1];
    error_number = utf8_to_eci(eci, source, converted, p_length);
    if (error_number != 0) {
      return error_number;
    }
    gb2312_cpy(converted, p_length, gbdata, full_multibyte);
  } else {
    gb2312_cpy(source, p_length, gbdata, full_multibyte);
  }
  return 0;
}


x86 assembly (clang, -O0):
<gb2312_utf8_to_eci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <is_eci_convertible@plt>
cmp    $0x0,%rax
je     1216 <gb2312_utf8_to_eci+0xd6>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <get_eci_length@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
call   1030 <utf8_to_eci@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11da <gb2312_utf8_to_eci+0x9a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    11f5 <gb2312_utf8_to_eci+0xb5>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <gb2312_cpy@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x44(%rbp),%eax
test   %eax,%eax
je     1211 <gb2312_utf8_to_eci+0xd1>
jmp    120c <gb2312_utf8_to_eci+0xcc>
jmp    1231 <gb2312_utf8_to_eci+0xf1>
jmp    122a <gb2312_utf8_to_eci+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <gb2312_cpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gb2312_utf8_to_eci>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebx
call   1060 <is_eci_convertible@plt>
test   %rax,%rax
je     11c3 <gb2312_utf8_to_eci+0x83>
mov    %r15,-0x38(%rbp)
mov    %r14d,-0x2c(%rbp)
mov    (%r12),%edx
mov    %ebx,%edi
mov    %r13,%rsi
call   1040 <get_eci_length@plt>
mov    %rsp,%r15
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1030 <utf8_to_eci@plt>
test   %eax,%eax
jne    11be <gb2312_utf8_to_eci+0x7e>
mov    %r14,%rdi
mov    %r12,%rsi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1050 <gb2312_cpy@plt>
xor    %eax,%eax
mov    %r15,%rsp
jmp    11d6 <gb2312_utf8_to_eci+0x96>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <gb2312_cpy@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define hidden i32 @gb2312_utf8_to_eci(i32 %0, i8* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%17 = load i32, i32* %7
%18 = call i64 @is_eci_convertible(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %48
20: ; preds = %5
%21 = load i32, i32* %7
%22 = load i8*, i8** %8
%23 = load i32*, i32** %9
%24 = load i32, i32* %23
%25 = call i32 @get_eci_length(i32 %21, i8* %22, i32 %24)
store i32 %25, i32* %13
%26 = load i32, i32* %13
%27 = add nsw i32 %26, 1
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %14
%30 = alloca i8, i64 %28
store i64 %28, i64* %15
%31 = load i32, i32* %7
%32 = load i8*, i8** %8
%33 = load i32*, i32** %9
%34 = call i32 @utf8_to_eci(i32 %31, i8* %32, i8* %30, i32* %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %20
%38 = load i32, i32* %12
store i32 %38, i32* %6
store i32 1, i32* %16
br label %44
39: ; preds = %20
%40 = load i32*, i32** %9
%41 = load i32*, i32** %10
%42 = load i32, i32* %11
%43 = call i32 @gb2312_cpy(i8* %30, i32* %40, i32* %41, i32 %42)
store i32 0, i32* %16
br label %44
44: ; preds = %39, %37
%45 = load i8*, i8** %14
%46 = load i32, i32* %16
switch i32 %46, label %57 [
i32 0, label %47
i32 1, label %55
]
47: ; preds = %44
br label %54
48: ; preds = %5
%49 = load i8*, i8** %8
%50 = load i32*, i32** %9
%51 = load i32*, i32** %10
%52 = load i32, i32* %11
%53 = call i32 @gb2312_cpy(i8* %49, i32* %50, i32* %51, i32 %52)
br label %54
54: ; preds = %48, %47
store i32 0, i32* %6
br label %55
55: ; preds = %54, %44
%56 = load i32, i32* %6
ret i32 %56
57: ; preds = %44
unreachable
}

LLVM IR (-O2):
define hidden i32 @gb2312_utf8_to_eci(i32 %0, i8* %1, i32* %2, i32* %3, i32 %4) {
%6 = tail call i64 @is_eci_convertible(i32 %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = load i32, i32* %2
%10 = tail call i32 @get_eci_length(i32 %0, i8* %1, i32 %9)
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = call i32 @utf8_to_eci(i32 %0, i8* %1, i8* %14, i32* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = call i32 @gb2312_cpy(i8* %14, i32* %2, i32* %3, i32 %4)
br label %22
19: ; preds = %8
br label %22
20: ; preds = %5
%21 = tail call i32 @gb2312_cpy(i8* %1, i32* %2, i32* %3, i32 %4)
br label %22
22: ; preds = %20, %17, %19
%23 = phi i32 [ %15, %19 ], [ 0, %17 ], [ 0, %20 ]
ret i32 %23
}