#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 */
scalar_t__ unicode_to_jisx0208(long, int *, int *);
scalar_t__ unicode_to_jisx0212(long, int *, int *);
unsigned long euc_jp_from_ucs(long int ucs) {
  int r, c;
  if (ucs >= 0xFF61 && ucs <= 0xFF9F)
    return 0x20000000 | (ucs - (0xFF61 - 0xA1));
  else if (unicode_to_jisx0208(ucs, &r, &c))
    return 0x10000000 | ((r + 0xA1) << 8) | (c + 0xA1);
  else if (unicode_to_jisx0212(ucs, &r, &c))
    return 0x30000000 | ((r + 0xA1) << 8) | (c + 0xA1);
  else
    return 0;
}


x86 assembly (clang, -O0):
<euc_jp_from_ucs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0xff61,-0x10(%rbp)
jl     1161 <euc_jp_from_ucs+0x41>
cmpq   $0xff9f,-0x10(%rbp)
jg     1161 <euc_jp_from_ucs+0x41>
mov    -0x10(%rbp),%rax
sub    $0xfec0,%rax
or     $0x20000000,%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <euc_jp_from_ucs+0xcb>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <unicode_to_jisx0208@plt>
cmp    $0x0,%rax
je     11a2 <euc_jp_from_ucs+0x82>
mov    -0x14(%rbp),%eax
add    $0xa1,%eax
shl    $0x8,%eax
or     $0x10000000,%eax
mov    -0x18(%rbp),%ecx
add    $0xa1,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    11eb <euc_jp_from_ucs+0xcb>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <unicode_to_jisx0212@plt>
cmp    $0x0,%rax
je     11e3 <euc_jp_from_ucs+0xc3>
mov    -0x14(%rbp),%eax
add    $0xa1,%eax
shl    $0x8,%eax
or     $0x30000000,%eax
mov    -0x18(%rbp),%ecx
add    $0xa1,%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    11eb <euc_jp_from_ucs+0xcb>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euc_jp_from_ucs>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    -0xff61(%rdi),%rax
cmp    $0x3e,%rax
ja     1145 <euc_jp_from_ucs+0x25>
add    $0xffffffffffff0140,%rbx
or     $0x20000000,%rbx
jmp    11c3 <euc_jp_from_ucs+0xa3>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <unicode_to_jisx0208@plt>
test   %rax,%rax
je     1183 <euc_jp_from_ucs+0x63>
mov    0xc(%rsp),%eax
shl    $0x8,%eax
add    $0xa100,%eax
movslq 0x8(%rsp),%rcx
add    $0xa1,%rcx
movslq %eax,%rbx
or     %rcx,%rbx
or     $0x10000000,%rbx
jmp    11c3 <euc_jp_from_ucs+0xa3>
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <unicode_to_jisx0212@plt>
test   %rax,%rax
je     11c1 <euc_jp_from_ucs+0xa1>
mov    0xc(%rsp),%eax
shl    $0x8,%eax
add    $0xa100,%eax
movslq 0x8(%rsp),%rcx
add    $0xa1,%rcx
movslq %eax,%rbx
or     %rcx,%rbx
or     $0x30000000,%rbx
jmp    11c3 <euc_jp_from_ucs+0xa3>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @euc_jp_from_ucs(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp sge i64 %6, 65377
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i64, i64* %3
%10 = icmp sle i64 %9, 65439
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i64, i64* %3
%13 = sub nsw i64 %12, 65216
%14 = or i64 536870912, %13
store i64 %14, i64* %2
br label %42
15: ; preds = %8, %1
%16 = load i64, i64* %3
%17 = call i64 @unicode_to_jisx0208(i64 %16, i32* %4, i32* %5)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 161
%22 = shl i32 %21, 8
%23 = or i32 268435456, %22
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 161
%26 = or i32 %23, %25
%27 = sext i32 %26 to i64
store i64 %27, i64* %2
br label %42
28: ; preds = %15
%29 = load i64, i64* %3
%30 = call i64 @unicode_to_jisx0212(i64 %29, i32* %4, i32* %5)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 161
%35 = shl i32 %34, 8
%36 = or i32 805306368, %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 161
%39 = or i32 %36, %38
%40 = sext i32 %39 to i64
store i64 %40, i64* %2
br label %42
41: ; preds = %28
store i64 0, i64* %2
br label %42
42: ; preds = %41, %32, %19, %11
%43 = load i64, i64* %2
ret i64 %43
}

LLVM IR (-O2):
define i64 @euc_jp_from_ucs(i64 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = add i64 %0, -65377
%7 = icmp ult i64 %6, 63
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = add nsw i64 %0, -65216
%10 = or i64 %9, 536870912
br label %35
11: ; preds = %1
%12 = call i64 @unicode_to_jisx0208(i64 %0, i32* %2, i32* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = shl i32 %15, 8
%17 = add i32 %16, 41216
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 161
%20 = or i32 %19, %17
%21 = or i32 %20, 268435456
%22 = sext i32 %21 to i64
br label %35
23: ; preds = %11
%24 = call i64 @unicode_to_jisx0212(i64 %0, i32* %2, i32* %3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = load i32, i32* %2
%28 = shl i32 %27, 8
%29 = add i32 %28, 41216
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 161
%32 = or i32 %31, %29
%33 = or i32 %32, 805306368
%34 = sext i32 %33 to i64
br label %35
35: ; preds = %23, %26, %14, %8
%36 = phi i64 [ %10, %8 ], [ %22, %14 ], [ %34, %26 ], [ 0, %23 ]
ret i64 %36
}