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

/* Variables and functions */
int /*<<< orphan*/ putc(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void print_unicode_to_utf8(uint16_t unicode) {
  if (unicode < 0x80) {
    putc((uint8_t)unicode, stdout);
  } else if (unicode < 0x800) {
    putc((uint8_t)((unicode >> 6) | 0300), stdout);
    putc((uint8_t)((unicode & 077) | 0200), stdout);
  } else {
    putc((uint8_t)((unicode >> 12) | 0340), stdout);
    putc((uint8_t)(((unicode >> 6) & 077) | 0200), stdout);
    putc((uint8_t)((unicode & 077) | 0200), stdout);
  }
}


x86 assembly (clang, -O0):
<print_unicode_to_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    113e <print_unicode_to_utf8+0x2e>
mov    -0x4(%rbp),%edi
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
jmp    11da <print_unicode_to_utf8+0xca>
cmpl   $0x800,-0x4(%rbp)
jge    1184 <print_unicode_to_utf8+0x74>
mov    -0x4(%rbp),%edi
sar    $0x6,%edi
or     $0xc0,%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
jmp    11d5 <print_unicode_to_utf8+0xc5>
mov    -0x4(%rbp),%edi
sar    $0xc,%edi
or     $0xe0,%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
sar    $0x6,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
jmp    11da <print_unicode_to_utf8+0xca>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_unicode_to_utf8>:
push   %rbx
mov    %edi,%ebx
cmp    $0x80,%edi
jl     116c <print_unicode_to_utf8+0x5c>
mov    %ebx,%edi
cmp    $0x7ff,%ebx
ja     1130 <print_unicode_to_utf8+0x20>
shr    $0x6,%edi
or     $0xc0,%edi
jmp    1155 <print_unicode_to_utf8+0x45>
shr    $0xc,%edi
or     $0xe0,%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    %ebx,%edi
shr    $0x6,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
and    $0x3f,%ebx
or     $0x80,%ebx
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
pop    %rbx
jmp    1030 <putc@plt>

LLVM IR (-O0):
@stdout = global i32 0
define void @print_unicode_to_utf8(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 128
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* %2
%7 = load i32, i32* @stdout
%8 = call i32 @putc(i32 %6, i32 %7)
br label %41
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 2048
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %2
%14 = ashr i32 %13, 6
%15 = or i32 %14, 192
%16 = load i32, i32* @stdout
%17 = call i32 @putc(i32 %15, i32 %16)
%18 = load i32, i32* %2
%19 = and i32 %18, 63
%20 = or i32 %19, 128
%21 = load i32, i32* @stdout
%22 = call i32 @putc(i32 %20, i32 %21)
br label %40
23: ; preds = %9
%24 = load i32, i32* %2
%25 = ashr i32 %24, 12
%26 = or i32 %25, 224
%27 = load i32, i32* @stdout
%28 = call i32 @putc(i32 %26, i32 %27)
%29 = load i32, i32* %2
%30 = ashr i32 %29, 6
%31 = and i32 %30, 63
%32 = or i32 %31, 128
%33 = load i32, i32* @stdout
%34 = call i32 @putc(i32 %32, i32 %33)
%35 = load i32, i32* %2
%36 = and i32 %35, 63
%37 = or i32 %36, 128
%38 = load i32, i32* @stdout
%39 = call i32 @putc(i32 %37, i32 %38)
br label %40
40: ; preds = %23, %12
br label %41
41: ; preds = %40, %5
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @print_unicode_to_utf8(i32 %0) {
%2 = icmp slt i32 %0, 128
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 2048
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = lshr i32 %0, 6
%7 = or i32 %6, 192
br label %16
8: ; preds = %3
%9 = lshr i32 %0, 12
%10 = or i32 %9, 224
%11 = load i32, i32* @stdout
%12 = tail call i32 @putc(i32 %10, i32 %11)
%13 = lshr i32 %0, 6
%14 = and i32 %13, 63
%15 = or i32 %14, 128
br label %16
16: ; preds = %8, %5
%17 = phi i32 [ %7, %5 ], [ %15, %8 ]
%18 = load i32, i32* @stdout
%19 = tail call i32 @putc(i32 %17, i32 %18)
%20 = and i32 %0, 63
%21 = or i32 %20, 128
br label %22
22: ; preds = %16, %1
%23 = phi i32 [ %0, %1 ], [ %21, %16 ]
%24 = load i32, i32* @stdout
%25 = tail call i32 @putc(i32 %23, i32 %24)
ret void
}