#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 gb18030_range_lookup(unsigned char *, int *);
unsigned int gb18030_table_lookup(unsigned char *, unsigned char, int *);
unsigned int gb18030_to_unicode(unsigned char *s, unsigned char len) {
  unsigned int ret;
  int found;
  ret = gb18030_table_lookup(s, len, &found);
  if (!found && len == 4) {
    ret = gb18030_range_lookup(s, &found);
    if (!found)
      ret = '?';
  }
  return ret;
}


x86 assembly (clang, -O0):
<gb18030_to_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rdx
movzbl -0x9(%rbp),%esi
call   1030 <gb18030_table_lookup@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1183 <gb18030_to_unicode+0x63>
movzbl -0x9(%rbp),%eax
cmp    $0x4,%eax
jne    1183 <gb18030_to_unicode+0x63>
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <gb18030_range_lookup@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    117e <gb18030_to_unicode+0x5e>
movl   $0x3f,-0x10(%rbp)
jmp    1183 <gb18030_to_unicode+0x63>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gb18030_to_unicode>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x4(%rsp),%rdx
call   1030 <gb18030_table_lookup@plt>
cmp    $0x4,%bpl
jne    115b <gb18030_to_unicode+0x3b>
cmpl   $0x0,0x4(%rsp)
jne    115b <gb18030_to_unicode+0x3b>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <gb18030_range_lookup@plt>
cmpl   $0x0,0x4(%rsp)
mov    %eax,%ecx
mov    $0x3f,%eax
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gb18030_to_unicode(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8*, i8** %3
%8 = load i8, i8* %4
%9 = call i32 @gb18030_table_lookup(i8* %7, i8 zeroext %8, i32* %6)
store i32 %9, i32* %5
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %2
%13 = load i8, i8* %4
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = call i32 @gb18030_range_lookup(i8* %17, i32* %6)
store i32 %18, i32* %5
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 63, i32* %5
br label %22
22: ; preds = %21, %16
br label %23
23: ; preds = %22, %12, %2
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
define i32 @gb18030_to_unicode(i8* %0, i8 zeroext %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @gb18030_table_lookup(i8* %0, i8 zeroext %1, i32* %3)
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
%8 = icmp eq i8 %1, 4
%9 = and i1 %8, %7
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i32 @gb18030_range_lookup(i8* %0, i32* %3)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 63, i32 %11
br label %15
15: ; preds = %10, %2
%16 = phi i32 [ %14, %10 ], [ %5, %2 ]
ret i32 %16
}