#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 jisx0208_to_unicode(unsigned long, int /*<<< orphan*/);
long jisx0212_to_unicode(unsigned long, int /*<<< orphan*/);
long int euc_jp_to_ucs(unsigned long state) {
  switch (state >> 28) {
  case 1:
    return jisx0208_to_unicode(((state >> 8) & 0xFF) - 0xA1,
                               ((state)&0xFF) - 0xA1);
  case 2: {
    int c = state & 0xFF;
    if (c >= 0xA1 && c <= 0xDF)
      return c + (0xFF61 - 0xA1);
    else
      return 0xFFFFL;
  }
  case 3:
    return jisx0212_to_unicode(((state >> 8) & 0xFF) - 0xA1,
                               ((state)&0xFF) - 0xA1);
  default:
    return 0xFFFFL;
  }
}


x86 assembly (clang, -O0):
<euc_jp_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     116d <euc_jp_to_ucs+0x4d>
jmp    1147 <euc_jp_to_ucs+0x27>
mov    -0x20(%rbp),%rax
sub    $0x2,%rax
je     11a3 <euc_jp_to_ucs+0x83>
jmp    115a <euc_jp_to_ucs+0x3a>
mov    -0x20(%rbp),%rax
sub    $0x3,%rax
je     11ea <euc_jp_to_ucs+0xca>
jmp    1220 <euc_jp_to_ucs+0x100>
mov    -0x10(%rbp),%rdi
shr    $0x8,%rdi
and    $0xff,%rdi
sub    $0xa1,%rdi
mov    -0x10(%rbp),%rax
and    $0xff,%rax
sub    $0xa1,%rax
mov    %eax,%esi
call   1030 <jisx0208_to_unicode@plt>
mov    %rax,-0x8(%rbp)
jmp    1228 <euc_jp_to_ucs+0x108>
mov    -0x10(%rbp),%rax
and    $0xff,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0xa1,-0x14(%rbp)
jl     11dd <euc_jp_to_ucs+0xbd>
cmpl   $0xdf,-0x14(%rbp)
jg     11dd <euc_jp_to_ucs+0xbd>
mov    -0x14(%rbp),%eax
add    $0xfec0,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1228 <euc_jp_to_ucs+0x108>
movq   $0xffff,-0x8(%rbp)
jmp    1228 <euc_jp_to_ucs+0x108>
mov    -0x10(%rbp),%rdi
shr    $0x8,%rdi
and    $0xff,%rdi
sub    $0xa1,%rdi
mov    -0x10(%rbp),%rax
and    $0xff,%rax
sub    $0xa1,%rax
mov    %eax,%esi
call   1040 <jisx0212_to_unicode@plt>
mov    %rax,-0x8(%rbp)
jmp    1228 <euc_jp_to_ucs+0x108>
movq   $0xffff,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euc_jp_to_ucs>:
mov    %rdi,%rcx
mov    %rdi,%rdx
shr    $0x1c,%rdx
cmp    $0x3,%rdx
je     1159 <euc_jp_to_ucs+0x39>
cmp    $0x2,%rdx
je     1171 <euc_jp_to_ucs+0x51>
mov    $0xffff,%eax
cmp    $0x1,%rdx
jne    118b <euc_jp_to_ucs+0x6b>
movzbl %ch,%edi
add    $0xffffffffffffff5f,%rdi
movzbl %cl,%esi
add    $0xffffff5f,%esi
jmp    1030 <jisx0208_to_unicode@plt>
movzbl %ch,%edi
add    $0xffffffffffffff5f,%rdi
movzbl %cl,%esi
add    $0xffffff5f,%esi
jmp    1040 <jisx0212_to_unicode@plt>
movzbl %cl,%ecx
lea    -0xa1(%rcx),%eax
add    $0xfec0,%ecx
cmp    $0x3f,%eax
mov    $0xffff,%eax
cmovb  %ecx,%eax
ret

LLVM IR (-O0):
define i64 @euc_jp_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 %41 [
i64 1, label %7
i64 2, label %17
i64 3, label %31
]
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 @jisx0208_to_unicode(i64 %11, i32 %15)
store i64 %16, i64* %2
br label %42
17: ; preds = %1
%18 = load i64, i64* %3
%19 = and i64 %18, 255
%20 = trunc i64 %19 to i32
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp sge i32 %21, 161
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* %4
%25 = icmp sle i32 %24, 223
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 65216
%29 = sext i32 %28 to i64
store i64 %29, i64* %2
br label %42
30: ; preds = %23, %17
store i64 65535, i64* %2
br label %42
31: ; preds = %1
%32 = load i64, i64* %3
%33 = lshr i64 %32, 8
%34 = and i64 %33, 255
%35 = sub i64 %34, 161
%36 = load i64, i64* %3
%37 = and i64 %36, 255
%38 = sub i64 %37, 161
%39 = trunc i64 %38 to i32
%40 = call i64 @jisx0212_to_unicode(i64 %35, i32 %39)
store i64 %40, i64* %2
br label %42
41: ; preds = %1
store i64 65535, i64* %2
br label %42
42: ; preds = %41, %31, %30, %26, %7
%43 = load i64, i64* %2
ret i64 %43
}

LLVM IR (-O2):
define i64 @euc_jp_to_ucs(i64 %0) {
%2 = lshr i64 %0, 28
switch i64 %2, label %27 [
i64 1, label %3
i64 2, label %11
i64 3, label %19
]
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 @jisx0208_to_unicode(i64 %6, i32 %9)
br label %27
11: ; preds = %1
%12 = trunc i64 %0 to i32
%13 = and i32 %12, 255
%14 = add nsw i32 %13, -161
%15 = icmp ult i32 %14, 63
%16 = add nuw nsw i32 %13, 65216
%17 = select i1 %15, i32 %16, i32 65535
%18 = zext i32 %17 to i64
br label %27
19: ; preds = %1
%20 = lshr i64 %0, 8
%21 = and i64 %20, 255
%22 = add nsw i64 %21, -161
%23 = trunc i64 %0 to i32
%24 = and i32 %23, 255
%25 = add nsw i32 %24, -161
%26 = tail call i64 @jisx0212_to_unicode(i64 %22, i32 %25)
br label %27
27: ; preds = %1, %19, %11, %3
%28 = phi i64 [ %26, %19 ], [ %18, %11 ], [ %10, %3 ], [ 65535, %1 ]
ret i64 %28
}