#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 */
int cet_ucs4_to_utf8(char *dest, size_t dest_size, int value) {
  int result;
  unsigned char trash[16];
  unsigned char *c;
  c = (dest != NULL) ? (unsigned char *)dest : trash;
  if ((value & 0xffffff80) == 0) {
    if (dest_size < 1)
      return (dest_size - 1);
    *c++ = value;
    result = 1;
  } else if ((value & 0xfffff800) == 0) {
    if (dest_size < 2)
      return (dest_size - 2);
    *c++ = (0xc0 | (value >> 6));
    *c++ = (0x80 | (value & 0x3f));
    result = 2;
  } else if ((value & 0xffff0000) == 0) {
    if (dest_size < 3)
      return (dest_size - 3);
    *c++ = (0xe0 | (value >> 12));
    *c++ = (0x80 | ((value >> 6) & 0x3f));
    *c++ = (0x80 | (value & 0x3f));
    result = 3;
  } else if ((value & 0xffe00000) == 0) {
    if (dest_size < 4)
      return (dest_size - 4);
    *c++ = (0xf0 | (value >> 18));
    *c++ = (0x80 | ((value >> 12) & 0x3f));
    *c++ = (0x80 | ((value >> 6) & 0x3f));
    *c++ = (0x80 | (value & 0x3f));
    result = 4;
  } else if ((value & 0xfc000000) == 0) {
    if (dest_size < 5)
      return (dest_size - 5);
    *c++ = (0xf8 | (value >> 24));
    *c++ = (0x80 | ((value >> 18) & 0x3f));
    *c++ = (0x80 | ((value >> 12) & 0x3f));
    *c++ = (0x80 | ((value >> 6) & 0x3f));
    *c++ = (0x80 | (value & 0x3f));
    result = 5;
  } else if ((value & 0x80000000) == 0) {
    if (dest_size < 6)
      return (dest_size - 6);
    *c++ = (0xfc | (value >> 30));
    *c++ = (0x80 | ((value >> 24) & 0x3f));
    *c++ = (0x80 | ((value >> 18) & 0x3f));
    *c++ = (0x80 | ((value >> 12) & 0x3f));
    *c++ = (0x80 | ((value >> 6) & 0x3f));
    *c++ = (0x80 | (value & 0x3f));
    result = 6;
  } else {
    return 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<cet_ucs4_to_utf8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1127 <cet_ucs4_to_utf8+0x27>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    112f <cet_ucs4_to_utf8+0x2f>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffffff80,%eax
cmp    $0x0,%eax
jne    1183 <cet_ucs4_to_utf8+0x83>
cmpq   $0x1,-0x18(%rbp)
jae    1161 <cet_ucs4_to_utf8+0x61>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x1,-0x20(%rbp)
jmp    1536 <cet_ucs4_to_utf8+0x436>
mov    -0x1c(%rbp),%eax
and    $0xfffff800,%eax
cmp    $0x0,%eax
jne    11f7 <cet_ucs4_to_utf8+0xf7>
cmpq   $0x2,-0x18(%rbp)
jae    11af <cet_ucs4_to_utf8+0xaf>
mov    -0x18(%rbp),%rax
sub    $0x2,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
or     $0xc0,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x2,-0x20(%rbp)
jmp    1531 <cet_ucs4_to_utf8+0x431>
mov    -0x1c(%rbp),%eax
and    $0xffff0000,%eax
cmp    $0x0,%eax
jne    128c <cet_ucs4_to_utf8+0x18c>
cmpq   $0x3,-0x18(%rbp)
jae    1223 <cet_ucs4_to_utf8+0x123>
mov    -0x18(%rbp),%rax
sub    $0x3,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
or     $0xe0,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x3,-0x20(%rbp)
jmp    152c <cet_ucs4_to_utf8+0x42c>
mov    -0x1c(%rbp),%eax
and    $0xffe00000,%eax
cmp    $0x0,%eax
jne    1342 <cet_ucs4_to_utf8+0x242>
cmpq   $0x4,-0x18(%rbp)
jae    12b8 <cet_ucs4_to_utf8+0x1b8>
mov    -0x18(%rbp),%rax
sub    $0x4,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
sar    $0x12,%eax
or     $0xf0,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x4,-0x20(%rbp)
jmp    1527 <cet_ucs4_to_utf8+0x427>
mov    -0x1c(%rbp),%eax
and    $0xfc000000,%eax
cmp    $0x0,%eax
jne    1419 <cet_ucs4_to_utf8+0x319>
cmpq   $0x5,-0x18(%rbp)
jae    136e <cet_ucs4_to_utf8+0x26e>
mov    -0x18(%rbp),%rax
sub    $0x5,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
or     $0xf8,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x12,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x5,-0x20(%rbp)
jmp    1522 <cet_ucs4_to_utf8+0x422>
mov    -0x1c(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    1511 <cet_ucs4_to_utf8+0x411>
cmpq   $0x6,-0x18(%rbp)
jae    1445 <cet_ucs4_to_utf8+0x345>
mov    -0x18(%rbp),%rax
sub    $0x6,%rax
mov    %eax,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
mov    -0x1c(%rbp),%eax
sar    $0x1e,%eax
or     $0xfc,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x12,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
movl   $0x6,-0x20(%rbp)
jmp    151d <cet_ucs4_to_utf8+0x41d>
movl   $0x0,-0x4(%rbp)
jmp    153c <cet_ucs4_to_utf8+0x43c>
jmp    1522 <cet_ucs4_to_utf8+0x422>
jmp    1527 <cet_ucs4_to_utf8+0x427>
jmp    152c <cet_ucs4_to_utf8+0x42c>
jmp    1531 <cet_ucs4_to_utf8+0x431>
jmp    1536 <cet_ucs4_to_utf8+0x436>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cet_ucs4_to_utf8>:
push   %rbp
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
test   %rdi,%rdi
lea    -0x8(%rsp),%rcx
cmovne %rdi,%rcx
cmp    $0x7f,%edx
ja     112b <cet_ucs4_to_utf8+0x2b>
test   %rax,%rax
je     1157 <cet_ucs4_to_utf8+0x57>
mov    %dl,(%rcx)
mov    $0x1,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
cmp    $0x7ff,%edx
ja     1141 <cet_ucs4_to_utf8+0x41>
cmp    $0x1,%rax
ja     1161 <cet_ucs4_to_utf8+0x61>
add    $0xfffffffe,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
cmp    $0xffff,%edx
ja     118c <cet_ucs4_to_utf8+0x8c>
cmp    $0x2,%rax
ja     11a2 <cet_ucs4_to_utf8+0xa2>
add    $0xfffffffd,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    $0xffffffff,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    %edx,%eax
shr    $0x6,%eax
or     $0xc0,%al
lea    0x1(%rdi),%rsi
test   %rdi,%rdi
lea    -0xf(%rsp),%rdi
cmovne %rsi,%rdi
mov    %al,(%rcx)
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,(%rdi)
mov    $0x2,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
cmp    $0x1fffff,%edx
ja     11ea <cet_ucs4_to_utf8+0xea>
cmp    $0x3,%rax
ja     1204 <cet_ucs4_to_utf8+0x104>
add    $0xfffffffc,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    %edx,%eax
shr    $0xc,%eax
or     $0xe0,%al
lea    0x1(%rdi),%r8
mov    %edx,%esi
shr    $0x6,%esi
and    $0x3f,%sil
or     $0x80,%sil
lea    0x2(%rdi),%r9
test   %rdi,%rdi
lea    -0xf(%rsp),%rdi
cmovne %r8,%rdi
mov    %al,(%rcx)
lea    -0xe(%rsp),%rax
cmovne %r9,%rax
mov    %sil,(%rdi)
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,(%rax)
mov    $0x3,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
cmp    $0x3ffffff,%edx
ja     1269 <cet_ucs4_to_utf8+0x169>
cmp    $0x4,%rax
ja     1283 <cet_ucs4_to_utf8+0x183>
add    $0xfffffffb,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    %edx,%r10d
shr    $0x12,%r10d
or     $0xf0,%r10b
lea    0x1(%rdi),%r8
mov    %edx,%esi
shr    $0xc,%esi
and    $0x3f,%sil
or     $0x80,%sil
lea    0x2(%rdi),%r9
mov    %edx,%eax
shr    $0x6,%eax
and    $0x3f,%al
or     $0x80,%al
lea    0x3(%rdi),%r11
test   %rdi,%rdi
lea    -0xf(%rsp),%rdi
cmovne %r8,%rdi
mov    %r10b,(%rcx)
lea    -0xe(%rsp),%rcx
cmovne %r9,%rcx
mov    %sil,(%rdi)
lea    -0xd(%rsp),%rsi
cmovne %r11,%rsi
mov    %al,(%rcx)
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,(%rsi)
mov    $0x4,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
test   %edx,%edx
js     1302 <cet_ucs4_to_utf8+0x202>
cmp    $0x5,%rax
ja     1309 <cet_ucs4_to_utf8+0x209>
add    $0xfffffffa,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    %edx,%r10d
shr    $0x18,%r10d
or     $0xf8,%r10b
lea    0x1(%rdi),%r8
mov    %edx,%esi
shr    $0x12,%esi
and    $0x3f,%sil
or     $0x80,%sil
lea    0x2(%rdi),%r9
mov    %edx,%eax
shr    $0xc,%eax
and    $0x3f,%al
or     $0x80,%al
lea    0x3(%rdi),%r11
mov    %edx,%ebx
shr    $0x6,%ebx
and    $0x3f,%bl
or     $0x80,%bl
lea    0x4(%rdi),%r14
test   %rdi,%rdi
lea    -0xf(%rsp),%rdi
cmovne %r8,%rdi
mov    %r10b,(%rcx)
lea    -0xe(%rsp),%rcx
cmovne %r9,%rcx
mov    %sil,(%rdi)
lea    -0xd(%rsp),%rsi
cmovne %r11,%rsi
mov    %al,(%rcx)
lea    -0xc(%rsp),%rax
cmovne %r14,%rax
mov    %bl,(%rsi)
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,(%rax)
mov    $0x5,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
xor    %eax,%eax
jmp    13a5 <cet_ucs4_to_utf8+0x2a5>
mov    %edx,%r9d
shr    $0x1e,%r9d
or     $0xfc,%r9b
lea    0x1(%rdi),%r8
mov    %edx,%r11d
shr    $0x18,%r11d
and    $0x3f,%r11b
or     $0x80,%r11b
lea    0x2(%rdi),%r10
mov    %edx,%eax
shr    $0x12,%eax
and    $0x3f,%al
or     $0x80,%al
lea    0x3(%rdi),%r14
mov    %edx,%esi
shr    $0xc,%esi
and    $0x3f,%sil
or     $0x80,%sil
lea    0x4(%rdi),%r15
mov    %edx,%ebp
shr    $0x6,%ebp
and    $0x3f,%bpl
or     $0x80,%bpl
lea    0x5(%rdi),%rbx
test   %rdi,%rdi
lea    -0xf(%rsp),%rdi
cmovne %r8,%rdi
mov    %r9b,(%rcx)
lea    -0xe(%rsp),%rcx
cmovne %r10,%rcx
mov    %r11b,(%rdi)
lea    -0xd(%rsp),%rdi
cmovne %r14,%rdi
mov    %al,(%rcx)
lea    -0xc(%rsp),%rax
cmovne %r15,%rax
mov    %sil,(%rdi)
lea    -0x1(%rsp),%rcx
cmovne %rbx,%rcx
mov    %bpl,(%rax)
and    $0x3f,%dl
or     $0x80,%dl
mov    %dl,(%rcx)
mov    $0x6,%eax
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cet_ucs4_to_utf8(i8* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i8*, i8** %5
br label %17
15: ; preds = %3
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %14, %13 ], [ %16, %15 ]
store i8* %18, i8** %10
%19 = load i32, i32* %7
%20 = and i32 %19, -128
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = load i64, i64* %6
%24 = icmp ult i64 %23, 1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i64, i64* %6
%27 = sub i64 %26, 1
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
br label %232
29: ; preds = %22
%30 = load i32, i32* %7
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %10
store i8 %31, i8* %32
store i32 1, i32* %8
br label %230
34: ; preds = %17
%35 = load i32, i32* %7
%36 = and i32 %35, -2048
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %58
38: ; preds = %34
%39 = load i64, i64* %6
%40 = icmp ult i64 %39, 2
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i64, i64* %6
%43 = sub i64 %42, 2
%44 = trunc i64 %43 to i32
store i32 %44, i32* %4
br label %232
45: ; preds = %38
%46 = load i32, i32* %7
%47 = ashr i32 %46, 6
%48 = or i32 192, %47
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %10
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %10
store i8 %49, i8* %50
%52 = load i32, i32* %7
%53 = and i32 %52, 63
%54 = or i32 128, %53
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %10
store i8 %55, i8* %56
store i32 2, i32* %8
br label %229
58: ; preds = %34
%59 = load i32, i32* %7
%60 = and i32 %59, -65536
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %89
62: ; preds = %58
%63 = load i64, i64* %6
%64 = icmp ult i64 %63, 3
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i64, i64* %6
%67 = sub i64 %66, 3
%68 = trunc i64 %67 to i32
store i32 %68, i32* %4
br label %232
69: ; preds = %62
%70 = load i32, i32* %7
%71 = ashr i32 %70, 12
%72 = or i32 224, %71
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %10
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %10
store i8 %73, i8* %74
%76 = load i32, i32* %7
%77 = ashr i32 %76, 6
%78 = and i32 %77, 63
%79 = or i32 128, %78
%80 = trunc i32 %79 to i8
%81 = load i8*, i8** %10
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %10
store i8 %80, i8* %81
%83 = load i32, i32* %7
%84 = and i32 %83, 63
%85 = or i32 128, %84
%86 = trunc i32 %85 to i8
%87 = load i8*, i8** %10
%88 = getelementptr inbounds i8, i8* %87, i32 1
store i8* %88, i8** %10
store i8 %86, i8* %87
store i32 3, i32* %8
br label %228
89: ; preds = %58
%90 = load i32, i32* %7
%91 = and i32 %90, -2097152
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %127
93: ; preds = %89
%94 = load i64, i64* %6
%95 = icmp ult i64 %94, 4
br i1 %95, label %96, label %100
96: ; preds = %93
%97 = load i64, i64* %6
%98 = sub i64 %97, 4
%99 = trunc i64 %98 to i32
store i32 %99, i32* %4
br label %232
100: ; preds = %93
%101 = load i32, i32* %7
%102 = ashr i32 %101, 18
%103 = or i32 240, %102
%104 = trunc i32 %103 to i8
%105 = load i8*, i8** %10
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %10
store i8 %104, i8* %105
%107 = load i32, i32* %7
%108 = ashr i32 %107, 12
%109 = and i32 %108, 63
%110 = or i32 128, %109
%111 = trunc i32 %110 to i8
%112 = load i8*, i8** %10
%113 = getelementptr inbounds i8, i8* %112, i32 1
store i8* %113, i8** %10
store i8 %111, i8* %112
%114 = load i32, i32* %7
%115 = ashr i32 %114, 6
%116 = and i32 %115, 63
%117 = or i32 128, %116
%118 = trunc i32 %117 to i8
%119 = load i8*, i8** %10
%120 = getelementptr inbounds i8, i8* %119, i32 1
store i8* %120, i8** %10
store i8 %118, i8* %119
%121 = load i32, i32* %7
%122 = and i32 %121, 63
%123 = or i32 128, %122
%124 = trunc i32 %123 to i8
%125 = load i8*, i8** %10
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %10
store i8 %124, i8* %125
store i32 4, i32* %8
br label %227
127: ; preds = %89
%128 = load i32, i32* %7
%129 = and i32 %128, -67108864
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %172
131: ; preds = %127
%132 = load i64, i64* %6
%133 = icmp ult i64 %132, 5
br i1 %133, label %134, label %138
134: ; preds = %131
%135 = load i64, i64* %6
%136 = sub i64 %135, 5
%137 = trunc i64 %136 to i32
store i32 %137, i32* %4
br label %232
138: ; preds = %131
%139 = load i32, i32* %7
%140 = ashr i32 %139, 24
%141 = or i32 248, %140
%142 = trunc i32 %141 to i8
%143 = load i8*, i8** %10
%144 = getelementptr inbounds i8, i8* %143, i32 1
store i8* %144, i8** %10
store i8 %142, i8* %143
%145 = load i32, i32* %7
%146 = ashr i32 %145, 18
%147 = and i32 %146, 63
%148 = or i32 128, %147
%149 = trunc i32 %148 to i8
%150 = load i8*, i8** %10
%151 = getelementptr inbounds i8, i8* %150, i32 1
store i8* %151, i8** %10
store i8 %149, i8* %150
%152 = load i32, i32* %7
%153 = ashr i32 %152, 12
%154 = and i32 %153, 63
%155 = or i32 128, %154
%156 = trunc i32 %155 to i8
%157 = load i8*, i8** %10
%158 = getelementptr inbounds i8, i8* %157, i32 1
store i8* %158, i8** %10
store i8 %156, i8* %157
%159 = load i32, i32* %7
%160 = ashr i32 %159, 6
%161 = and i32 %160, 63
%162 = or i32 128, %161
%163 = trunc i32 %162 to i8
%164 = load i8*, i8** %10
%165 = getelementptr inbounds i8, i8* %164, i32 1
store i8* %165, i8** %10
store i8 %163, i8* %164
%166 = load i32, i32* %7
%167 = and i32 %166, 63
%168 = or i32 128, %167
%169 = trunc i32 %168 to i8
%170 = load i8*, i8** %10
%171 = getelementptr inbounds i8, i8* %170, i32 1
store i8* %171, i8** %10
store i8 %169, i8* %170
store i32 5, i32* %8
br label %226
172: ; preds = %127
%173 = load i32, i32* %7
%174 = and i32 %173, -2147483648
%175 = icmp eq i32 %174, 0
br i1 %175, label %176, label %224
176: ; preds = %172
%177 = load i64, i64* %6
%178 = icmp ult i64 %177, 6
br i1 %178, label %179, label %183
179: ; preds = %176
%180 = load i64, i64* %6
%181 = sub i64 %180, 6
%182 = trunc i64 %181 to i32
store i32 %182, i32* %4
br label %232
183: ; preds = %176
%184 = load i32, i32* %7
%185 = ashr i32 %184, 30
%186 = or i32 252, %185
%187 = trunc i32 %186 to i8
%188 = load i8*, i8** %10
%189 = getelementptr inbounds i8, i8* %188, i32 1
store i8* %189, i8** %10
store i8 %187, i8* %188
%190 = load i32, i32* %7
%191 = ashr i32 %190, 24
%192 = and i32 %191, 63
%193 = or i32 128, %192
%194 = trunc i32 %193 to i8
%195 = load i8*, i8** %10
%196 = getelementptr inbounds i8, i8* %195, i32 1
store i8* %196, i8** %10
store i8 %194, i8* %195
%197 = load i32, i32* %7
%198 = ashr i32 %197, 18
%199 = and i32 %198, 63
%200 = or i32 128, %199
%201 = trunc i32 %200 to i8
%202 = load i8*, i8** %10
%203 = getelementptr inbounds i8, i8* %202, i32 1
store i8* %203, i8** %10
store i8 %201, i8* %202
%204 = load i32, i32* %7
%205 = ashr i32 %204, 12
%206 = and i32 %205, 63
%207 = or i32 128, %206
%208 = trunc i32 %207 to i8
%209 = load i8*, i8** %10
%210 = getelementptr inbounds i8, i8* %209, i32 1
store i8* %210, i8** %10
store i8 %208, i8* %209
%211 = load i32, i32* %7
%212 = ashr i32 %211, 6
%213 = and i32 %212, 63
%214 = or i32 128, %213
%215 = trunc i32 %214 to i8
%216 = load i8*, i8** %10
%217 = getelementptr inbounds i8, i8* %216, i32 1
store i8* %217, i8** %10
store i8 %215, i8* %216
%218 = load i32, i32* %7
%219 = and i32 %218, 63
%220 = or i32 128, %219
%221 = trunc i32 %220 to i8
%222 = load i8*, i8** %10
%223 = getelementptr inbounds i8, i8* %222, i32 1
store i8* %223, i8** %10
store i8 %221, i8* %222
store i32 6, i32* %8
br label %225
224: ; preds = %172
store i32 0, i32* %4
br label %232
225: ; preds = %183
br label %226
226: ; preds = %225, %138
br label %227
227: ; preds = %226, %100
br label %228
228: ; preds = %227, %69
br label %229
229: ; preds = %228, %45
br label %230
230: ; preds = %229, %29
%231 = load i32, i32* %8
store i32 %231, i32* %4
br label %232
232: ; preds = %230, %224, %179, %134, %96, %65, %41, %25
%233 = load i32, i32* %4
ret i32 %233
}

LLVM IR (-O2):
define i32 @cet_ucs4_to_utf8(i8* writeonly %0, i64 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = icmp eq i8* %0, null
%11 = select i1 %10, i8* %4, i8* %0
%12 = icmp ult i32 %2, 128
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = icmp eq i64 %1, 0
br i1 %14, label %157, label %15
15: ; preds = %13
%16 = trunc i32 %2 to i8
store i8 %16, i8* %11
br label %157
17: ; preds = %3
%18 = icmp ult i32 %2, 2048
br i1 %18, label %19, label %33
19: ; preds = %17
%20 = icmp ult i64 %1, 2
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = trunc i64 %1 to i32
%23 = add nuw nsw i32 %22, -2
br label %157
24: ; preds = %19
%25 = lshr i32 %2, 6
%26 = trunc i32 %25 to i8
%27 = or i8 %26, -64
%28 = getelementptr inbounds i8, i8* %0, i64 1
%29 = select i1 %10, i8* %5, i8* %28
store i8 %27, i8* %11
%30 = trunc i32 %2 to i8
%31 = and i8 %30, 63
%32 = or i8 %31, -128
store i8 %32, i8* %29
br label %157
33: ; preds = %17
%34 = icmp ult i32 %2, 65536
br i1 %34, label %35, label %55
35: ; preds = %33
%36 = icmp ult i64 %1, 3
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = trunc i64 %1 to i32
%39 = add nuw nsw i32 %38, -3
br label %157
40: ; preds = %35
%41 = lshr i32 %2, 12
%42 = trunc i32 %41 to i8
%43 = or i8 %42, -32
%44 = getelementptr inbounds i8, i8* %0, i64 1
%45 = select i1 %10, i8* %5, i8* %44
store i8 %43, i8* %11
%46 = lshr i32 %2, 6
%47 = trunc i32 %46 to i8
%48 = and i8 %47, 63
%49 = or i8 %48, -128
%50 = getelementptr inbounds i8, i8* %0, i64 2
%51 = select i1 %10, i8* %6, i8* %50
store i8 %49, i8* %45
%52 = trunc i32 %2 to i8
%53 = and i8 %52, 63
%54 = or i8 %53, -128
store i8 %54, i8* %51
br label %157
55: ; preds = %33
%56 = icmp ult i32 %2, 2097152
br i1 %56, label %57, label %83
57: ; preds = %55
%58 = icmp ult i64 %1, 4
br i1 %58, label %59, label %62
59: ; preds = %57
%60 = trunc i64 %1 to i32
%61 = add nuw nsw i32 %60, -4
br label %157
62: ; preds = %57
%63 = lshr i32 %2, 18
%64 = trunc i32 %63 to i8
%65 = or i8 %64, -16
%66 = getelementptr inbounds i8, i8* %0, i64 1
%67 = select i1 %10, i8* %5, i8* %66
store i8 %65, i8* %11
%68 = lshr i32 %2, 12
%69 = trunc i32 %68 to i8
%70 = and i8 %69, 63
%71 = or i8 %70, -128
%72 = getelementptr inbounds i8, i8* %0, i64 2
%73 = select i1 %10, i8* %6, i8* %72
store i8 %71, i8* %67
%74 = lshr i32 %2, 6
%75 = trunc i32 %74 to i8
%76 = and i8 %75, 63
%77 = or i8 %76, -128
%78 = getelementptr inbounds i8, i8* %0, i64 3
%79 = select i1 %10, i8* %7, i8* %78
store i8 %77, i8* %73
%80 = trunc i32 %2 to i8
%81 = and i8 %80, 63
%82 = or i8 %81, -128
store i8 %82, i8* %79
br label %157
83: ; preds = %55
%84 = icmp ult i32 %2, 67108864
br i1 %84, label %85, label %117
85: ; preds = %83
%86 = icmp ult i64 %1, 5
br i1 %86, label %87, label %90
87: ; preds = %85
%88 = trunc i64 %1 to i32
%89 = add nuw nsw i32 %88, -5
br label %157
90: ; preds = %85
%91 = lshr i32 %2, 24
%92 = trunc i32 %91 to i8
%93 = or i8 %92, -8
%94 = getelementptr inbounds i8, i8* %0, i64 1
%95 = select i1 %10, i8* %5, i8* %94
store i8 %93, i8* %11
%96 = lshr i32 %2, 18
%97 = trunc i32 %96 to i8
%98 = and i8 %97, 63
%99 = or i8 %98, -128
%100 = getelementptr inbounds i8, i8* %0, i64 2
%101 = select i1 %10, i8* %6, i8* %100
store i8 %99, i8* %95
%102 = lshr i32 %2, 12
%103 = trunc i32 %102 to i8
%104 = and i8 %103, 63
%105 = or i8 %104, -128
%106 = getelementptr inbounds i8, i8* %0, i64 3
%107 = select i1 %10, i8* %7, i8* %106
store i8 %105, i8* %101
%108 = lshr i32 %2, 6
%109 = trunc i32 %108 to i8
%110 = and i8 %109, 63
%111 = or i8 %110, -128
%112 = getelementptr inbounds i8, i8* %0, i64 4
%113 = select i1 %10, i8* %8, i8* %112
store i8 %111, i8* %107
%114 = trunc i32 %2 to i8
%115 = and i8 %114, 63
%116 = or i8 %115, -128
store i8 %116, i8* %113
br label %157
117: ; preds = %83
%118 = icmp sgt i32 %2, -1
br i1 %118, label %119, label %157
119: ; preds = %117
%120 = icmp ult i64 %1, 6
br i1 %120, label %121, label %124
121: ; preds = %119
%122 = trunc i64 %1 to i32
%123 = add nuw nsw i32 %122, -6
br label %157
124: ; preds = %119
%125 = lshr i32 %2, 30
%126 = trunc i32 %125 to i8
%127 = or i8 %126, -4
%128 = getelementptr inbounds i8, i8* %0, i64 1
%129 = select i1 %10, i8* %5, i8* %128
store i8 %127, i8* %11
%130 = lshr i32 %2, 24
%131 = trunc i32 %130 to i8
%132 = and i8 %131, 63
%133 = or i8 %132, -128
%134 = getelementptr inbounds i8, i8* %0, i64 2
%135 = select i1 %10, i8* %6, i8* %134
store i8 %133, i8* %129
%136 = lshr i32 %2, 18
%137 = trunc i32 %136 to i8
%138 = and i8 %137, 63
%139 = or i8 %138, -128
%140 = getelementptr inbounds i8, i8* %0, i64 3
%141 = select i1 %10, i8* %7, i8* %140
store i8 %139, i8* %135
%142 = lshr i32 %2, 12
%143 = trunc i32 %142 to i8
%144 = and i8 %143, 63
%145 = or i8 %144, -128
%146 = getelementptr inbounds i8, i8* %0, i64 4
%147 = select i1 %10, i8* %8, i8* %146
store i8 %145, i8* %141
%148 = lshr i32 %2, 6
%149 = trunc i32 %148 to i8
%150 = and i8 %149, 63
%151 = or i8 %150, -128
%152 = getelementptr inbounds i8, i8* %0, i64 5
%153 = select i1 %10, i8* %9, i8* %152
store i8 %151, i8* %147
%154 = trunc i32 %2 to i8
%155 = and i8 %154, 63
%156 = or i8 %155, -128
store i8 %156, i8* %153
br label %157
157: ; preds = %15, %40, %90, %124, %62, %24, %117, %13, %121, %87, %59, %37, %21
%158 = phi i32 [ %23, %21 ], [ %39, %37 ], [ %61, %59 ], [ %89, %87 ], [ %123, %121 ], [ -1, %13 ], [ 0, %117 ], [ 1, %15 ], [ 2, %24 ], [ 3, %40 ], [ 4, %62 ], [ 5, %90 ], [ 6, %124 ]
ret i32 %158
}