#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 short Read2Byte(char **);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned int UTF162UCS(char **src) {
  unsigned short lead = Read2Byte(src);
  if (lead >= 0xD800 && lead <= 0xDFFF) {
    unsigned short trail = Read2Byte(src);
    if (trail >= 0xDC00 && trail <= 0xDFFF) {
      lead -= 0xD800;
      trail -= 0xDC00;
      return (lead << 16) | (trail);
    } else {
      assert(0);
      return 0;
    }
  } else {
    return lead;
  }
}


x86 assembly (clang, -O0):
<UTF162UCS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <Read2Byte@plt>
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
cmp    $0xd800,%eax
jl     11c4 <UTF162UCS+0xa4>
movzwl -0x12(%rbp),%eax
cmp    $0xdfff,%eax
jg     11c4 <UTF162UCS+0xa4>
mov    -0x10(%rbp),%rdi
call   1030 <Read2Byte@plt>
mov    %ax,-0x14(%rbp)
movzwl -0x14(%rbp),%eax
cmp    $0xdc00,%eax
jl     11b1 <UTF162UCS+0x91>
movzwl -0x14(%rbp),%eax
cmp    $0xdfff,%eax
jg     11b1 <UTF162UCS+0x91>
movzwl -0x12(%rbp),%eax
sub    $0xd800,%eax
mov    %ax,-0x12(%rbp)
movzwl -0x14(%rbp),%eax
sub    $0xdc00,%eax
mov    %ax,-0x14(%rbp)
movzwl -0x12(%rbp),%eax
shl    $0x10,%eax
movzwl -0x14(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <UTF162UCS+0xab>
xor    %edi,%edi
call   1040 <assert@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cb <UTF162UCS+0xab>
movzwl -0x12(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UTF162UCS>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <Read2Byte@plt>
mov    %eax,%r14d
mov    %r14d,%eax
and    $0xf800,%eax
cmp    $0xd800,%eax
jne    116e <UTF162UCS+0x4e>
mov    %rbx,%rdi
call   1030 <Read2Byte@plt>
mov    %eax,%ecx
and    $0xfc00,%ecx
cmp    $0xdc00,%ecx
jne    1174 <UTF162UCS+0x54>
shl    $0x10,%r14d
add    $0x2400,%eax
movzwl %ax,%eax
lea    (%r14,%rax,1),%ebx
add    $0x28000000,%ebx
jmp    117d <UTF162UCS+0x5d>
movzwl %r14w,%ebx
jmp    117d <UTF162UCS+0x5d>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <assert@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @UTF162UCS(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i16
%5 = alloca i16
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = call zeroext i16 @Read2Byte(i8** %6)
store i16 %7, i16* %4
%8 = load i16, i16* %4
%9 = zext i16 %8 to i32
%10 = icmp sge i32 %9, 55296
br i1 %10, label %11, label %42
11: ; preds = %1
%12 = load i16, i16* %4
%13 = zext i16 %12 to i32
%14 = icmp sle i32 %13, 57343
br i1 %14, label %15, label %42
15: ; preds = %11
%16 = load i8**, i8*** %3
%17 = call zeroext i16 @Read2Byte(i8** %16)
store i16 %17, i16* %5
%18 = load i16, i16* %5
%19 = zext i16 %18 to i32
%20 = icmp sge i32 %19, 56320
br i1 %20, label %21, label %40
21: ; preds = %15
%22 = load i16, i16* %5
%23 = zext i16 %22 to i32
%24 = icmp sle i32 %23, 57343
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i16, i16* %4
%27 = zext i16 %26 to i32
%28 = sub nsw i32 %27, 55296
%29 = trunc i32 %28 to i16
store i16 %29, i16* %4
%30 = load i16, i16* %5
%31 = zext i16 %30 to i32
%32 = sub nsw i32 %31, 56320
%33 = trunc i32 %32 to i16
store i16 %33, i16* %5
%34 = load i16, i16* %4
%35 = zext i16 %34 to i32
%36 = shl i32 %35, 16
%37 = load i16, i16* %5
%38 = zext i16 %37 to i32
%39 = or i32 %36, %38
store i32 %39, i32* %2
br label %45
40: ; preds = %21, %15
%41 = call i32 @assert(i32 0)
store i32 0, i32* %2
br label %45
42: ; preds = %11, %1
%43 = load i16, i16* %4
%44 = zext i16 %43 to i32
store i32 %44, i32* %2
br label %45
45: ; preds = %42, %40, %25
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
define i32 @UTF162UCS(i8** %0) {
%2 = tail call zeroext i16 @Read2Byte(i8** %0)
%3 = and i16 %2, -2048
%4 = icmp eq i16 %3, -10240
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = tail call zeroext i16 @Read2Byte(i8** %0)
%7 = and i16 %6, -1024
%8 = icmp eq i16 %7, -9216
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = add nsw i16 %2, 10240
%11 = add nsw i16 %6, 9216
%12 = zext i16 %10 to i32
%13 = shl nuw nsw i32 %12, 16
%14 = zext i16 %11 to i32
%15 = or i32 %13, %14
br label %20
16: ; preds = %5
%17 = tail call i32 @assert(i32 0)
br label %20
18: ; preds = %1
%19 = zext i16 %2 to i32
br label %20
20: ; preds = %9, %16, %18
%21 = phi i32 [ %19, %18 ], [ %15, %9 ], [ 0, %16 ]
ret i32 %21
}