#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 */
typedef int /*<<< orphan*/ state;

/* Variables and functions */
long cns11643_to_unicode(int, unsigned long, int /*<<< orphan*/);
long int euc_tw_to_ucs(unsigned long state) {
  int plane;
  switch (state >> 28) {
  case 1:
    return cns11643_to_unicode(0, ((state >> 8) & 0xFF) - 0xA1,
                               ((state)&0xFF) - 0xA1);
  case 2:
    plane = ((state >> 8) & 0xFF) - 0xA1;
    if (plane >= 7)
      return 0xFFFFL;
    return cns11643_to_unicode(plane, ((state >> 8) & 0xFF) - 0xA1,
                               ((state)&0xFF) - 0xA1);
  default:
    return 0xFFFFL;
  }
}


x86 assembly (clang, -O0):
<euc_tw_to_ucs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1c,%rax
mov    %rax,-0x20(%rbp)
sub    $0x1,%rax
je     114a <euc_tw_to_ucs+0x3a>
jmp    1137 <euc_tw_to_ucs+0x27>
mov    -0x20(%rbp),%rax
sub    $0x2,%rax
je     1182 <euc_tw_to_ucs+0x72>
jmp    11e9 <euc_tw_to_ucs+0xd9>
mov    -0x10(%rbp),%rsi
shr    $0x8,%rsi
and    $0xff,%rsi
sub    $0xa1,%rsi
mov    -0x10(%rbp),%rax
and    $0xff,%rax
sub    $0xa1,%rax
mov    %eax,%edx
xor    %edi,%edi
call   1030 <cns11643_to_unicode@plt>
mov    %rax,-0x8(%rbp)
jmp    11f1 <euc_tw_to_ucs+0xe1>
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
sub    $0xa1,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jl     11b0 <euc_tw_to_ucs+0xa0>
movq   $0xffff,-0x8(%rbp)
jmp    11f1 <euc_tw_to_ucs+0xe1>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
shr    $0x8,%rsi
and    $0xff,%rsi
sub    $0xa1,%rsi
mov    -0x10(%rbp),%rax
and    $0xff,%rax
sub    $0xa1,%rax
mov    %eax,%edx
call   1030 <cns11643_to_unicode@plt>
mov    %rax,-0x8(%rbp)
jmp    11f1 <euc_tw_to_ucs+0xe1>
movq   $0xffff,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euc_tw_to_ucs>:
mov    %rdi,%rax
mov    %rdi,%rcx
shr    $0x1c,%rcx
cmp    $0x2,%rcx
je     1140 <euc_tw_to_ucs+0x30>
cmp    $0x1,%rcx
jne    114f <euc_tw_to_ucs+0x3f>
movzbl %ah,%esi
add    $0xffffffffffffff5f,%rsi
movzbl %al,%edx
add    $0xffffff5f,%edx
xor    %edi,%edi
jmp    1030 <cns11643_to_unicode@plt>
movzbl %ah,%edi
add    $0xffffffffffffff5f,%rdi
cmp    $0x6,%edi
jle    1155 <euc_tw_to_ucs+0x45>
mov    $0xffff,%eax
ret
movzbl %al,%edx
add    $0xffffff5f,%edx
mov    %rdi,%rsi
jmp    1030 <cns11643_to_unicode@plt>

LLVM IR (-O0):
define i64 @euc_tw_to_ucs(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = lshr i64 %5, 28
switch i64 %6, label %37 [
i64 1, label %7
i64 2, label %17
]
7: ; preds = %1
%8 = load i64, i64* %3
%9 = lshr i64 %8, 8
%10 = and i64 %9, 255
%11 = sub i64 %10, 161
%12 = load i64, i64* %3
%13 = and i64 %12, 255
%14 = sub i64 %13, 161
%15 = trunc i64 %14 to i32
%16 = call i64 @cns11643_to_unicode(i32 0, i64 %11, i32 %15)
store i64 %16, i64* %2
br label %38
17: ; preds = %1
%18 = load i64, i64* %3
%19 = lshr i64 %18, 8
%20 = and i64 %19, 255
%21 = sub i64 %20, 161
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 7
br i1 %24, label %25, label %26
25: ; preds = %17
store i64 65535, i64* %2
br label %38
26: ; preds = %17
%27 = load i32, i32* %4
%28 = load i64, i64* %3
%29 = lshr i64 %28, 8
%30 = and i64 %29, 255
%31 = sub i64 %30, 161
%32 = load i64, i64* %3
%33 = and i64 %32, 255
%34 = sub i64 %33, 161
%35 = trunc i64 %34 to i32
%36 = call i64 @cns11643_to_unicode(i32 %27, i64 %31, i32 %35)
store i64 %36, i64* %2
br label %38
37: ; preds = %1
store i64 65535, i64* %2
br label %38
38: ; preds = %37, %26, %25, %7
%39 = load i64, i64* %2
ret i64 %39
}

LLVM IR (-O2):
define i64 @euc_tw_to_ucs(i64 %0) {
%2 = lshr i64 %0, 28
switch i64 %2, label %22 [
i64 1, label %3
i64 2, label %11
]
3: ; preds = %1
%4 = lshr i64 %0, 8
%5 = and i64 %4, 255
%6 = add nsw i64 %5, -161
%7 = trunc i64 %0 to i32
%8 = and i32 %7, 255
%9 = add nsw i32 %8, -161
%10 = tail call i64 @cns11643_to_unicode(i32 0, i64 %6, i32 %9)
br label %22
11: ; preds = %1
%12 = lshr i64 %0, 8
%13 = and i64 %12, 255
%14 = add nsw i64 %13, -161
%15 = trunc i64 %14 to i32
%16 = icmp sgt i32 %15, 6
br i1 %16, label %22, label %17
17: ; preds = %11
%18 = trunc i64 %0 to i32
%19 = and i32 %18, 255
%20 = add nsw i32 %19, -161
%21 = tail call i64 @cns11643_to_unicode(i32 %15, i64 %14, i32 %20)
br label %22
22: ; preds = %1, %11, %17, %3
%23 = phi i64 [ %21, %17 ], [ %10, %3 ], [ 65535, %11 ], [ 65535, %1 ]
ret i64 %23
}