#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_int8_t;
typedef int u_int16_t;

/* Variables and functions */
u_int16_t bs_utf8_to_utf16(const char *s, char **outpos) {
  u_int8_t c;
  u_int16_t uc;
  c = *s++;
  if (c < 0x80) {
    uc = c;
  } else if (c >= 0xc2 && c <= 0xdf) {
    uc = (((u_int16_t)c & 0x1f) << 6) + (((u_int16_t)*s++) & 0x3f);
  } else if (c >= 0xe0 && c <= 0xef) {
    uc = (((u_int16_t)c & 0x0f) << 12) + ((((u_int16_t)*s++) & 0x3f) << 6);
    uc += ((u_int16_t)*s++) & 0x3f;
  } else
    uc = 32;
  if (outpos != NULL)
    *outpos = (char *)s;
  return uc;
}


x86 assembly (clang, -O0):
<bs_utf8_to_utf16>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    1139 <bs_utf8_to_utf16+0x39>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11ec <bs_utf8_to_utf16+0xec>
cmpl   $0xc2,-0x14(%rbp)
jl     117b <bs_utf8_to_utf16+0x7b>
cmpl   $0xdf,-0x14(%rbp)
jg     117b <bs_utf8_to_utf16+0x7b>
mov    -0x14(%rbp),%eax
and    $0x1f,%eax
shl    $0x6,%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
and    $0x3f,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    11e7 <bs_utf8_to_utf16+0xe7>
cmpl   $0xe0,-0x14(%rbp)
jl     11db <bs_utf8_to_utf16+0xdb>
cmpl   $0xef,-0x14(%rbp)
jg     11db <bs_utf8_to_utf16+0xdb>
mov    -0x14(%rbp),%eax
and    $0xf,%eax
shl    $0xc,%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
and    $0x3f,%ecx
shl    $0x6,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
and    $0x3f,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <bs_utf8_to_utf16+0xe2>
movl   $0x20,-0x18(%rbp)
jmp    11e7 <bs_utf8_to_utf16+0xe7>
jmp    11ec <bs_utf8_to_utf16+0xec>
cmpq   $0x0,-0x10(%rbp)
je     1202 <bs_utf8_to_utf16+0x102>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bs_utf8_to_utf16>:
movsbl (%rdi),%eax
test   %rsi,%rsi
je     110f <bs_utf8_to_utf16+0xf>
add    $0x1,%rdi
mov    %rdi,(%rsi)
ret

LLVM IR (-O0):
define i32 @bs_utf8_to_utf16(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %3
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 128
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %5
store i32 %14, i32* %6
br label %58
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 194
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = load i32, i32* %5
%20 = icmp sle i32 %19, 223
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %5
%23 = and i32 %22, 31
%24 = shl i32 %23, 6
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = and i32 %28, 63
%30 = add nsw i32 %24, %29
store i32 %30, i32* %6
br label %57
31: ; preds = %18, %15
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 224
br i1 %33, label %34, label %55
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp sle i32 %35, 239
br i1 %36, label %37, label %55
37: ; preds = %34
%38 = load i32, i32* %5
%39 = and i32 %38, 15
%40 = shl i32 %39, 12
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %3
%43 = load i8, i8* %41
%44 = sext i8 %43 to i32
%45 = and i32 %44, 63
%46 = shl i32 %45, 6
%47 = add nsw i32 %40, %46
store i32 %47, i32* %6
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %3
%50 = load i8, i8* %48
%51 = sext i8 %50 to i32
%52 = and i32 %51, 63
%53 = load i32, i32* %6
%54 = add nsw i32 %53, %52
store i32 %54, i32* %6
br label %56
55: ; preds = %34, %31
store i32 32, i32* %6
br label %56
56: ; preds = %55, %37
br label %57
57: ; preds = %56, %21
br label %58
58: ; preds = %57, %13
%59 = load i8**, i8*** %4
%60 = icmp ne i8** %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i8*, i8** %3
%63 = load i8**, i8*** %4
store i8* %62, i8** %63
br label %64
64: ; preds = %61, %58
%65 = load i32, i32* %6
ret i32 %65
}

LLVM IR (-O2):
define i32 @bs_utf8_to_utf16(i8* %0, i8** writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8** %1, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8* %6, i8** %1
br label %7
7: ; preds = %5, %2
%8 = sext i8 %3 to i32
ret i32 %8
}