#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 /*<<< orphan*/ utf8;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
short vktor_unicode_sp_to_utf8(unsigned short high, unsigned short low,
                               unsigned char *utf8) {
  unsigned long utf32;
  assert(sizeof(utf8) >= 4);
  assert((high >= 0xd800 && high <= 0xdbff));
  assert((low >= 0xdc99 && low <= 0xdfff));
  utf32 = (high << 10) + low + (0x10000 - (0xd800 << 10) - 0xdc00);
  utf8[0] = (unsigned char)0xf0 | (utf32 >> 18);
  utf8[1] = (unsigned char)0x80 | ((utf32 >> 12) & 0x3f);
  utf8[2] = (unsigned char)0x80 | ((utf32 >> 6) & 0x3f);
  utf8[3] = (unsigned char)0x80 | (utf32 & 0x3f);
  utf8[4] = '\0';
  return 4;
}


x86 assembly (clang, -O0):
<vktor_unicode_sp_to_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x1,%edi
call   1030 <assert@plt>
movzwl -0x2(%rbp),%ecx
xor    %eax,%eax
cmp    $0xd800,%ecx
mov    %al,-0x19(%rbp)
jl     1158 <vktor_unicode_sp_to_utf8+0x48>
movzwl -0x2(%rbp),%eax
cmp    $0xdbff,%eax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movzwl -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    $0xdc99,%ecx
mov    %al,-0x1a(%rbp)
jl     1189 <vktor_unicode_sp_to_utf8+0x79>
movzwl -0x4(%rbp),%eax
cmp    $0xdfff,%eax
setle  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movzwl -0x2(%rbp),%eax
shl    $0xa,%eax
movzwl -0x4(%rbp),%ecx
add    %ecx,%eax
add    $0xfca02400,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x12,%rax
or     $0xf0,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
shr    $0xc,%rax
and    $0x3f,%rax
or     $0x80,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
shr    $0x6,%rax
and    $0x3f,%rax
or     $0x80,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rax
and    $0x3f,%rax
or     $0x80,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    $0x4,%ax
cwtl
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vktor_unicode_sp_to_utf8>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%ebx
mov    $0x1,%edi
call   1030 <assert@plt>
mov    %ebx,%eax
and    $0xfc00,%eax
xor    %edi,%edi
cmp    $0xd800,%eax
sete   %dil
call   1030 <assert@plt>
lea    0x2367(%r14),%eax
movzwl %ax,%eax
xor    %edi,%edi
cmp    $0x367,%eax
setb   %dil
call   1030 <assert@plt>
shl    $0xa,%ebx
lea    (%rbx,%r14,1),%eax
lea    (%rbx,%r14,1),%ecx
add    $0xfca02400,%ecx
mov    %ecx,%edx
shr    $0x12,%edx
or     $0xf0,%dl
mov    %dl,(%r15)
mov    %ecx,%edx
shr    $0xc,%edx
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,0x1(%r15)
shr    $0x6,%ecx
and    $0x3f,%cl
or     $0x80,%cl
mov    %cl,0x2(%r15)
and    $0x3f,%al
or     $0x80,%al
mov    %al,0x3(%r15)
movb   $0x0,0x4(%r15)
mov    $0x4,%ax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define signext i16 @vktor_unicode_sp_to_utf8(i16 zeroext %0, i16 zeroext %1, i8* %2) {
%4 = alloca i16
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i64
store i16 %0, i16* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%8 = call i32 @assert(i32 1)
%9 = load i16, i16* %4
%10 = zext i16 %9 to i32
%11 = icmp sge i32 %10, 55296
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i16, i16* %4
%14 = zext i16 %13 to i32
%15 = icmp sle i32 %14, 56319
br label %16
16: ; preds = %12, %3
%17 = phi i1 [ false, %3 ], [ %15, %12 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i16, i16* %5
%21 = zext i16 %20 to i32
%22 = icmp sge i32 %21, 56473
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i16, i16* %5
%25 = zext i16 %24 to i32
%26 = icmp sle i32 %25, 57343
br label %27
27: ; preds = %23, %16
%28 = phi i1 [ false, %16 ], [ %26, %23 ]
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i16, i16* %4
%32 = zext i16 %31 to i32
%33 = shl i32 %32, 10
%34 = load i16, i16* %5
%35 = zext i16 %34 to i32
%36 = add nsw i32 %33, %35
%37 = add nsw i32 %36, -56613888
%38 = sext i32 %37 to i64
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = lshr i64 %39, 18
%41 = or i64 240, %40
%42 = trunc i64 %41 to i8
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 %42, i8* %44
%45 = load i64, i64* %7
%46 = lshr i64 %45, 12
%47 = and i64 %46, 63
%48 = or i64 128, %47
%49 = trunc i64 %48 to i8
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8 %49, i8* %51
%52 = load i64, i64* %7
%53 = lshr i64 %52, 6
%54 = and i64 %53, 63
%55 = or i64 128, %54
%56 = trunc i64 %55 to i8
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 2
store i8 %56, i8* %58
%59 = load i64, i64* %7
%60 = and i64 %59, 63
%61 = or i64 128, %60
%62 = trunc i64 %61 to i8
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 3
store i8 %62, i8* %64
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i64 4
store i8 0, i8* %66
ret i16 4
}

LLVM IR (-O2):
define signext i16 @vktor_unicode_sp_to_utf8(i16 zeroext %0, i16 zeroext %1, i8* nocapture writeonly %2) {
%4 = tail call i32 @assert(i32 1)
%5 = zext i16 %0 to i32
%6 = and i16 %0, -1024
%7 = icmp eq i16 %6, -10240
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = zext i16 %1 to i32
%11 = add i16 %1, 9063
%12 = icmp ult i16 %11, 871
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = shl nuw nsw i32 %5, 10
%16 = add nuw nsw i32 %15, %10
%17 = add nsw i32 %16, -56613888
%18 = lshr i32 %17, 18
%19 = trunc i32 %18 to i8
%20 = or i8 %19, -16
store i8 %20, i8* %2
%21 = lshr i32 %17, 12
%22 = trunc i32 %21 to i8
%23 = and i8 %22, 63
%24 = or i8 %23, -128
%25 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %24, i8* %25
%26 = lshr i32 %17, 6
%27 = trunc i32 %26 to i8
%28 = and i8 %27, 63
%29 = or i8 %28, -128
%30 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %29, i8* %30
%31 = trunc i32 %16 to i8
%32 = and i8 %31, 63
%33 = or i8 %32, -128
%34 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %2, i64 4
store i8 0, i8* %35
ret i16 4
}