#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*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void putc_utf8(int c) {
  if (c < (1 << 7)) {
    putc(c, stdout);
    return;
  }
  if (c < (1 << 11)) {
    putc((c >> 6) | 0xC0, stdout);
    putc((c & 0x3F) | 0x80, stdout);
    return;
  }
  if (c < (1 << 16)) {
    putc(((c >> 12)) | 0xE0, stdout);
    putc(((c >> 6) & 0x3F) | 0x80, stdout);
    putc((c & 0x3F) | 0x80, stdout);
    return;
  }
  if (c < (1 << 21)) {
    putc(((c >> 18)) | 0xF0, stdout);
    putc(((c >> 12) & 0x3F) | 0x80, stdout);
    putc(((c >> 6) & 0x3F) | 0x80, stdout);
    putc((c & 0x3F) | 0x80, stdout);
    return;
  }
}


x86 assembly (clang, -O0):
<putc_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    113e <putc_utf8+0x2e>
mov    -0x4(%rbp),%edi
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
jmp    1262 <putc_utf8+0x152>
cmpl   $0x800,-0x4(%rbp)
jge    1184 <putc_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    1262 <putc_utf8+0x152>
cmpl   $0x10000,-0x4(%rbp)
jge    11e7 <putc_utf8+0xd7>
mov    -0x4(%rbp),%edi
sar    $0xc,%edi
or     $0xe0,%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
sar    $0x6,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
jmp    1262 <putc_utf8+0x152>
cmpl   $0x200000,-0x4(%rbp)
jge    1262 <putc_utf8+0x152>
mov    -0x4(%rbp),%edi
sar    $0x12,%edi
or     $0xf0,%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
sar    $0xc,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
sar    $0x6,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putc_utf8>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x80,%edi
jl     11b2 <putc_utf8+0xa2>
cmp    $0x7ff,%ebx
ja     1137 <putc_utf8+0x27>
mov    %ebx,%edi
shr    $0x6,%edi
or     $0xc0,%edi
jmp    119b <putc_utf8+0x8b>
cmp    $0xffff,%ebx
ja     1155 <putc_utf8+0x45>
mov    %ebx,%edi
shr    $0xc,%edi
or     $0xe0,%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
jmp    1188 <putc_utf8+0x78>
cmp    $0x1fffff,%ebx
ja     11c9 <putc_utf8+0xb9>
mov    %ebx,%edi
shr    $0x12,%edi
or     $0xf0,%edi
mov    0x2e71(%rip),%r14
mov    (%r14),%esi
call   1030 <putc@plt>
mov    %ebx,%edi
shr    $0xc,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    (%r14),%esi
call   1030 <putc@plt>
mov    %ebx,%edi
shr    $0x6,%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1030 <putc@plt>
and    $0x3f,%ebx
or     $0x80,%ebx
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @putc_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 %69
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 %69
23: ; preds = %9
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 65536
br i1 %25, label %26, label %43
26: ; preds = %23
%27 = load i32, i32* %2
%28 = ashr i32 %27, 12
%29 = or i32 %28, 224
%30 = load i32, i32* @stdout
%31 = call i32 @putc(i32 %29, i32 %30)
%32 = load i32, i32* %2
%33 = ashr i32 %32, 6
%34 = and i32 %33, 63
%35 = or i32 %34, 128
%36 = load i32, i32* @stdout
%37 = call i32 @putc(i32 %35, i32 %36)
%38 = load i32, i32* %2
%39 = and i32 %38, 63
%40 = or i32 %39, 128
%41 = load i32, i32* @stdout
%42 = call i32 @putc(i32 %40, i32 %41)
br label %69
43: ; preds = %23
%44 = load i32, i32* %2
%45 = icmp slt i32 %44, 2097152
br i1 %45, label %46, label %69
46: ; preds = %43
%47 = load i32, i32* %2
%48 = ashr i32 %47, 18
%49 = or i32 %48, 240
%50 = load i32, i32* @stdout
%51 = call i32 @putc(i32 %49, i32 %50)
%52 = load i32, i32* %2
%53 = ashr i32 %52, 12
%54 = and i32 %53, 63
%55 = or i32 %54, 128
%56 = load i32, i32* @stdout
%57 = call i32 @putc(i32 %55, i32 %56)
%58 = load i32, i32* %2
%59 = ashr i32 %58, 6
%60 = and i32 %59, 63
%61 = or i32 %60, 128
%62 = load i32, i32* @stdout
%63 = call i32 @putc(i32 %61, i32 %62)
%64 = load i32, i32* %2
%65 = and i32 %64, 63
%66 = or i32 %65, 128
%67 = load i32, i32* @stdout
%68 = call i32 @putc(i32 %66, i32 %67)
br label %69
69: ; preds = %5, %12, %26, %46, %43
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @putc_utf8(i32 %0) {
%2 = icmp slt i32 %0, 128
br i1 %2, label %39, 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 %33
8: ; preds = %3
%9 = icmp ult i32 %0, 65536
br i1 %9, label %10, label %18
10: ; preds = %8
%11 = lshr i32 %0, 12
%12 = or i32 %11, 224
%13 = load i32, i32* @stdout
%14 = tail call i32 @putc(i32 %12, i32 %13)
%15 = lshr i32 %0, 6
%16 = and i32 %15, 63
%17 = or i32 %16, 128
br label %33
18: ; preds = %8
%19 = icmp ult i32 %0, 2097152
br i1 %19, label %20, label %43
20: ; preds = %18
%21 = lshr i32 %0, 18
%22 = or i32 %21, 240
%23 = load i32, i32* @stdout
%24 = tail call i32 @putc(i32 %22, i32 %23)
%25 = lshr i32 %0, 12
%26 = and i32 %25, 63
%27 = or i32 %26, 128
%28 = load i32, i32* @stdout
%29 = tail call i32 @putc(i32 %27, i32 %28)
%30 = lshr i32 %0, 6
%31 = and i32 %30, 63
%32 = or i32 %31, 128
br label %33
33: ; preds = %5, %10, %20
%34 = phi i32 [ %32, %20 ], [ %17, %10 ], [ %7, %5 ]
%35 = load i32, i32* @stdout
%36 = tail call i32 @putc(i32 %34, i32 %35)
%37 = and i32 %0, 63
%38 = or i32 %37, 128
br label %39
39: ; preds = %33, %1
%40 = phi i32 [ %0, %1 ], [ %38, %33 ]
%41 = load i32, i32* @stdout
%42 = tail call i32 @putc(i32 %40, i32 %41)
br label %43
43: ; preds = %39, %18
ret void
}