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

/* Variables and functions */
int /*<<< orphan*/ gzread(int /*<<< orphan*/, char *, int);
int utf8_2_unicode(gzFile stream, char s, u_int16_t *ucode) {
  char s1, s2;
  *ucode = (u_int16_t)s;
  if (*ucode == 0xFFFF) {
    return -2;
  }
  if (*ucode == 0xFFFE) {
    return -1;
  }
  if (!(*ucode & 0x80)) {
    return 0;
  }
  *ucode = 0;
  if ((s & 0xE0) == 0xC0) {
    gzread(stream, &s1, 1);
    *ucode = (s & 0x1F) << 6;
    *ucode |= (s1 & 0x3F);
  } else if ((s & 0xF0) == 0xE0) {
    gzread(stream, &s1, 1);
    gzread(stream, &s2, 1);
    *ucode = (s & 0x0F) << 12;
    *ucode |= (s1 & 0x3F) << 6;
    *ucode |= (s2 & 0x3F);
  }
  return 0;
}


x86 assembly (clang, -O0):
<utf8_2_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movsbl -0x9(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffff,(%rax)
jne    114b <utf8_2_unicode+0x3b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    124d <utf8_2_unicode+0x13d>
mov    -0x18(%rbp),%rax
cmpl   $0xfffe,(%rax)
jne    1167 <utf8_2_unicode+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <utf8_2_unicode+0x13d>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1187 <utf8_2_unicode+0x77>
movl   $0x0,-0x4(%rbp)
jmp    124d <utf8_2_unicode+0x13d>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movsbl -0x9(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    11da <utf8_2_unicode+0xca>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <gzread@plt>
movsbl -0x9(%rbp),%ecx
and    $0x1f,%ecx
shl    $0x6,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movsbl -0x19(%rbp),%ecx
and    $0x3f,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    1246 <utf8_2_unicode+0x136>
movsbl -0x9(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    1241 <utf8_2_unicode+0x131>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <gzread@plt>
mov    -0x8(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x1,%edx
call   1030 <gzread@plt>
movsbl -0x9(%rbp),%ecx
and    $0xf,%ecx
shl    $0xc,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movsbl -0x19(%rbp),%ecx
and    $0x3f,%ecx
shl    $0x6,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
movsbl -0x1a(%rbp),%ecx
and    $0x3f,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    1246 <utf8_2_unicode+0x136>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_2_unicode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %esi,(%rdx)
test   $0x80,%bpl
je     11af <utf8_2_unicode+0x9f>
mov    %rdx,%rbx
mov    %edi,%r15d
movl   $0x0,(%rdx)
mov    %ebp,%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    115c <utf8_2_unicode+0x4c>
lea    0x6(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <gzread@plt>
and    $0x1f,%ebp
shl    $0x6,%ebp
jmp    11a4 <utf8_2_unicode+0x94>
mov    %ebp,%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    11af <utf8_2_unicode+0x9f>
lea    0x6(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <gzread@plt>
lea    0x7(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <gzread@plt>
shl    $0xc,%ebp
movzwl %bp,%eax
movzbl 0x6(%rsp),%ebp
and    $0x3f,%ebp
shl    $0x6,%ebp
or     %eax,%ebp
movzbl (%r14),%eax
and    $0x3f,%eax
or     %ebp,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @utf8_2_unicode(i32 %0, i8 signext %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i8
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32* %2, i32** %7
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = load i32*, i32** %7
store i32 %11, i32* %12
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 65535
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -2, i32* %4
br label %78
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 65534
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %78
22: ; preds = %17
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = and i32 %24, 128
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 0, i32* %4
br label %78
28: ; preds = %22
%29 = load i32*, i32** %7
store i32 0, i32* %29
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = and i32 %31, 224
%33 = icmp eq i32 %32, 192
br i1 %33, label %34, label %48
34: ; preds = %28
%35 = load i32, i32* %5
%36 = call i32 @gzread(i32 %35, i8* %8, i32 1)
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = and i32 %38, 31
%40 = shl i32 %39, 6
%41 = load i32*, i32** %7
store i32 %40, i32* %41
%42 = load i8, i8* %8
%43 = sext i8 %42 to i32
%44 = and i32 %43, 63
%45 = load i32*, i32** %7
%46 = load i32, i32* %45
%47 = or i32 %46, %44
store i32 %47, i32* %45
br label %77
48: ; preds = %28
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = and i32 %50, 240
%52 = icmp eq i32 %51, 224
br i1 %52, label %53, label %76
53: ; preds = %48
%54 = load i32, i32* %5
%55 = call i32 @gzread(i32 %54, i8* %8, i32 1)
%56 = load i32, i32* %5
%57 = call i32 @gzread(i32 %56, i8* %9, i32 1)
%58 = load i8, i8* %6
%59 = sext i8 %58 to i32
%60 = and i32 %59, 15
%61 = shl i32 %60, 12
%62 = load i32*, i32** %7
store i32 %61, i32* %62
%63 = load i8, i8* %8
%64 = sext i8 %63 to i32
%65 = and i32 %64, 63
%66 = shl i32 %65, 6
%67 = load i32*, i32** %7
%68 = load i32, i32* %67
%69 = or i32 %68, %66
store i32 %69, i32* %67
%70 = load i8, i8* %9
%71 = sext i8 %70 to i32
%72 = and i32 %71, 63
%73 = load i32*, i32** %7
%74 = load i32, i32* %73
%75 = or i32 %74, %72
store i32 %75, i32* %73
br label %76
76: ; preds = %53, %48
br label %77
77: ; preds = %76, %34
store i32 0, i32* %4
br label %78
78: ; preds = %77, %27, %21, %16
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
define i32 @utf8_2_unicode(i32 %0, i8 signext %1, i32* nocapture writeonly %2) {
%4 = alloca i8
%5 = alloca i8
%6 = sext i8 %1 to i32
store i32 %6, i32* %2
%7 = and i32 %6, 128
%8 = icmp eq i32 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %3
store i32 0, i32* %2
%10 = and i32 %6, 224
%11 = icmp eq i32 %10, 192
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @gzread(i32 %0, i8* %4, i32 1)
%14 = shl nsw i32 %6, 6
%15 = and i32 %14, 1984
br label %29
16: ; preds = %9
%17 = and i32 %6, 240
%18 = icmp eq i32 %17, 224
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = call i32 @gzread(i32 %0, i8* %4, i32 1)
%21 = call i32 @gzread(i32 %0, i8* %5, i32 1)
%22 = shl nsw i32 %6, 12
%23 = and i32 %22, 61440
%24 = load i8, i8* %4
%25 = and i8 %24, 63
%26 = zext i8 %25 to i32
%27 = shl nuw nsw i32 %26, 6
%28 = or i32 %27, %23
br label %29
29: ; preds = %19, %12
%30 = phi i8* [ %4, %12 ], [ %5, %19 ]
%31 = phi i32 [ %15, %12 ], [ %28, %19 ]
%32 = load i8, i8* %30
%33 = and i8 %32, 63
%34 = zext i8 %33 to i32
%35 = or i32 %31, %34
store i32 %35, i32* %2
br label %36
36: ; preds = %29, %16, %3
ret i32 0
}