#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int utf2ucs(const uint8_t *utf8, uint16_t *pucs) {
  uint16_t c;
  c = *utf8++;
  if ((c & 0x80) == 0) {
    *pucs = c;
    return 1;
  }
  switch (c >> 5) {
  case 0x06:
    *pucs = ((c & 0x1F) << 6) | (utf8[0] & 0x3F);
    return 2;
  case 0x07:
    *pucs = ((c & 0x0F) << 12) | ((utf8[0] & 0x3F) << 6) | (utf8[1] & 0x3F);
    return 3;
  }
  *pucs = '?';
  return 1;
}


x86 assembly (clang, -O0):
<utf2ucs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1146 <utf2ucs+0x46>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11da <utf2ucs+0xda>
mov    -0x1c(%rbp),%eax
sar    $0x5,%eax
mov    %eax,-0x20(%rbp)
sub    $0x6,%eax
je     116e <utf2ucs+0x6e>
jmp    115d <utf2ucs+0x5d>
mov    -0x20(%rbp),%eax
sub    $0x7,%eax
je     1194 <utf2ucs+0x94>
jmp    11c9 <utf2ucs+0xc9>
mov    -0x1c(%rbp),%ecx
and    $0x1f,%ecx
shl    $0x6,%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x3f,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    11da <utf2ucs+0xda>
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
shl    $0xc,%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0x3f,%eax
shl    $0x6,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x3f,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x3,-0x4(%rbp)
jmp    11da <utf2ucs+0xda>
mov    -0x18(%rbp),%rax
movl   $0x3f,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf2ucs>:
mov    (%rdi),%edx
mov    $0x1,%eax
test   $0x80,%dl
jne    110f <utf2ucs+0xf>
mov    %edx,(%rsi)
ret
mov    %edx,%ecx
sar    $0x5,%ecx
cmp    $0x7,%ecx
je     113c <utf2ucs+0x3c>
mov    $0x3f,%r9d
cmp    $0x6,%ecx
jne    1161 <utf2ucs+0x61>
and    $0x1f,%edx
shl    $0x6,%edx
mov    0x4(%rdi),%r8d
and    $0x3f,%r8d
mov    $0x2,%eax
mov    %edx,%r9d
jmp    115e <utf2ucs+0x5e>
shl    $0xc,%edx
movzwl %dx,%eax
mov    0x4(%rdi),%r8d
mov    0x8(%rdi),%r9d
and    $0x3f,%r8d
shl    $0x6,%r8d
or     %eax,%r8d
and    $0x3f,%r9d
mov    $0x3,%eax
or     %r8d,%r9d
mov    %r9d,(%rsi)
ret

LLVM IR (-O0):
define i32 @utf2ucs(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %4
%8 = getelementptr inbounds i32, i32* %7, i32 1
store i32* %8, i32** %4
%9 = load i32, i32* %7
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = and i32 %10, 128
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load i32*, i32** %5
store i32 %14, i32* %15
store i32 1, i32* %3
br label %47
16: ; preds = %2
%17 = load i32, i32* %6
%18 = ashr i32 %17, 5
switch i32 %18, label %45 [
i32 6, label %19
i32 7, label %29
]
19: ; preds = %16
%20 = load i32, i32* %6
%21 = and i32 %20, 31
%22 = shl i32 %21, 6
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = and i32 %25, 63
%27 = or i32 %22, %26
%28 = load i32*, i32** %5
store i32 %27, i32* %28
store i32 2, i32* %3
br label %47
29: ; preds = %16
%30 = load i32, i32* %6
%31 = and i32 %30, 15
%32 = shl i32 %31, 12
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 0
%35 = load i32, i32* %34
%36 = and i32 %35, 63
%37 = shl i32 %36, 6
%38 = or i32 %32, %37
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 1
%41 = load i32, i32* %40
%42 = and i32 %41, 63
%43 = or i32 %38, %42
%44 = load i32*, i32** %5
store i32 %43, i32* %44
store i32 3, i32* %3
br label %47
45: ; preds = %16
%46 = load i32*, i32** %5
store i32 63, i32* %46
store i32 1, i32* %3
br label %47
47: ; preds = %45, %29, %19, %13
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @utf2ucs(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %0
%5 = and i32 %4, 128
%6 = icmp eq i32 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %2
%8 = ashr i32 %4, 5
switch i32 %8, label %29 [
i32 6, label %9
i32 7, label %14
]
9: ; preds = %7
%10 = shl i32 %4, 6
%11 = and i32 %10, 1984
%12 = load i32, i32* %3
%13 = and i32 %12, 63
br label %24
14: ; preds = %7
%15 = shl i32 %4, 12
%16 = and i32 %15, 61440
%17 = load i32, i32* %3
%18 = shl i32 %17, 6
%19 = and i32 %18, 4032
%20 = or i32 %19, %16
%21 = getelementptr inbounds i32, i32* %0, i64 2
%22 = load i32, i32* %21
%23 = and i32 %22, 63
br label %24
24: ; preds = %9, %14
%25 = phi i32 [ %23, %14 ], [ %11, %9 ]
%26 = phi i32 [ %20, %14 ], [ %13, %9 ]
%27 = phi i32 [ 3, %14 ], [ 2, %9 ]
%28 = or i32 %26, %25
br label %29
29: ; preds = %24, %7, %2
%30 = phi i32 [ %4, %2 ], [ 63, %7 ], [ %28, %24 ]
%31 = phi i32 [ 1, %2 ], [ 1, %7 ], [ %27, %24 ]
store i32 %30, i32* %1
ret i32 %31
}