#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 /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void utf8(unsigned short ch) {
  if (ch > 0x7FF) {
    fputc((unsigned char)(((ch >> 12) & 0xF) | 0xE0), stdout);
    fputc((unsigned char)(((ch >> 6) & 0x3F) | 0x80), stdout);
    fputc((unsigned char)((ch & 0x3F) | 0x80), stdout);
  } else {
    if (ch > 0x7F) {
      fputc((unsigned char)(((ch >> 6) & 0x1F) | 0xC0), stdout);
      fputc((unsigned char)((ch & 0x3F) | 0x80), stdout);
    } else {
      fputc((unsigned char)ch, stdout);
    }
  }
}


x86 assembly (clang, -O0):
<utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x7ff,%eax
jle    1190 <utf8+0x80>
movzwl -0x2(%rbp),%eax
sar    $0xc,%eax
and    $0xf,%eax
or     $0xe0,%eax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
movzwl -0x2(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
movzwl -0x2(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
jmp    11f9 <utf8+0xe9>
movzwl -0x2(%rbp),%eax
cmp    $0x7f,%eax
jle    11df <utf8+0xcf>
movzwl -0x2(%rbp),%eax
sar    $0x6,%eax
and    $0x1f,%eax
or     $0xc0,%eax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
movzwl -0x2(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
jmp    11f4 <utf8+0xe4>
mov    -0x2(%rbp),%ax
mov    0x2df6(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
jmp    11f9 <utf8+0xe9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
cmp    $0x800,%edi
jb     114e <utf8+0x3e>
movzwl %bx,%ebp
mov    %ebp,%eax
shr    $0xc,%eax
or     $0xe0,%al
mov    0x2eb1(%rip),%r14
mov    (%r14),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
shr    $0x6,%ebp
and    $0x3f,%bpl
or     $0x80,%bpl
mov    (%r14),%esi
movzbl %bpl,%edi
jmp    116b <utf8+0x5b>
movzwl %bx,%eax
cmp    $0x80,%eax
jb     1176 <utf8+0x66>
mov    %ebx,%eax
shr    $0x6,%eax
or     $0xc0,%al
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <fputc@plt>
and    $0x3f,%bl
or     $0x80,%bl
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
movzbl %bl,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@stdout = global i32 0
define void @utf8(i16 zeroext %0) {
%2 = alloca i16
store i16 %0, i16* %2
%3 = load i16, i16* %2
%4 = zext i16 %3 to i32
%5 = icmp sgt i32 %4, 2047
br i1 %5, label %6, label %30
6: ; preds = %1
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = ashr i32 %8, 12
%10 = and i32 %9, 15
%11 = or i32 %10, 224
%12 = trunc i32 %11 to i8
%13 = load i32, i32* @stdout
%14 = call i32 @fputc(i8 zeroext %12, i32 %13)
%15 = load i16, i16* %2
%16 = zext i16 %15 to i32
%17 = ashr i32 %16, 6
%18 = and i32 %17, 63
%19 = or i32 %18, 128
%20 = trunc i32 %19 to i8
%21 = load i32, i32* @stdout
%22 = call i32 @fputc(i8 zeroext %20, i32 %21)
%23 = load i16, i16* %2
%24 = zext i16 %23 to i32
%25 = and i32 %24, 63
%26 = or i32 %25, 128
%27 = trunc i32 %26 to i8
%28 = load i32, i32* @stdout
%29 = call i32 @fputc(i8 zeroext %27, i32 %28)
br label %56
30: ; preds = %1
%31 = load i16, i16* %2
%32 = zext i16 %31 to i32
%33 = icmp sgt i32 %32, 127
br i1 %33, label %34, label %50
34: ; preds = %30
%35 = load i16, i16* %2
%36 = zext i16 %35 to i32
%37 = ashr i32 %36, 6
%38 = and i32 %37, 31
%39 = or i32 %38, 192
%40 = trunc i32 %39 to i8
%41 = load i32, i32* @stdout
%42 = call i32 @fputc(i8 zeroext %40, i32 %41)
%43 = load i16, i16* %2
%44 = zext i16 %43 to i32
%45 = and i32 %44, 63
%46 = or i32 %45, 128
%47 = trunc i32 %46 to i8
%48 = load i32, i32* @stdout
%49 = call i32 @fputc(i8 zeroext %47, i32 %48)
br label %55
50: ; preds = %30
%51 = load i16, i16* %2
%52 = trunc i16 %51 to i8
%53 = load i32, i32* @stdout
%54 = call i32 @fputc(i8 zeroext %52, i32 %53)
br label %55
55: ; preds = %50, %34
br label %56
56: ; preds = %55, %6
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @utf8(i16 zeroext %0) {
%2 = icmp ugt i16 %0, 2047
br i1 %2, label %3, label %18
3: ; preds = %1
%4 = lshr i16 %0, 12
%5 = trunc i16 %4 to i8
%6 = or i8 %5, -32
%7 = load i32, i32* @stdout
%8 = tail call i32 @fputc(i8 zeroext %6, i32 %7)
%9 = lshr i16 %0, 6
%10 = trunc i16 %9 to i8
%11 = and i8 %10, 63
%12 = or i8 %11, -128
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputc(i8 zeroext %12, i32 %13)
%15 = trunc i16 %0 to i8
%16 = and i8 %15, 63
%17 = or i8 %16, -128
br label %31
18: ; preds = %1
%19 = icmp ugt i16 %0, 127
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = lshr i16 %0, 6
%22 = trunc i16 %21 to i8
%23 = or i8 %22, -64
%24 = load i32, i32* @stdout
%25 = tail call i32 @fputc(i8 zeroext %23, i32 %24)
%26 = trunc i16 %0 to i8
%27 = and i8 %26, 63
%28 = or i8 %27, -128
br label %31
29: ; preds = %18
%30 = trunc i16 %0 to i8
br label %31
31: ; preds = %20, %29, %3
%32 = phi i8 [ %28, %20 ], [ %30, %29 ], [ %17, %3 ]
%33 = load i32, i32* @stdout
%34 = tail call i32 @fputc(i8 zeroext %32, i32 %33)
ret void
}