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

/* Variables and functions */
int /*<<< orphan*/ putc(unsigned short, int /*<<< orphan*/ *);
void utf8_putc(unsigned short c, FILE *fd) {
  if (c < 0x80) {
    putc(c, fd);
    return;
  }
  if (c < 0x800) {
    putc(c >> 6 | 0xc0, fd);
    putc((c & 0x3f) | 0x80, fd);
    return;
  }
  putc(c >> 12 | 0xe0, fd);
  putc(((c >> 6) & 0x3f) | 0x80, fd);
  putc((c & 0x3f) | 0x80, fd);
}


x86 assembly (clang, -O0):
<utf8_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x80,%eax
jge    1147 <utf8_putc+0x37>
mov    -0x2(%rbp),%ax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
jmp    11d6 <utf8_putc+0xc6>
movzwl -0x2(%rbp),%eax
cmp    $0x800,%eax
jge    118b <utf8_putc+0x7b>
movzwl -0x2(%rbp),%eax
sar    $0x6,%eax
or     $0xc0,%eax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
movzwl -0x2(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
jmp    11d6 <utf8_putc+0xc6>
movzwl -0x2(%rbp),%eax
sar    $0xc,%eax
or     $0xe0,%eax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
movzwl -0x2(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
movzwl -0x2(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_putc>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
cmp    $0x80,%edi
jb     116a <utf8_putc+0x5a>
movzwl %bp,%ebx
cmp    $0x7ff,%ebx
ja     1137 <utf8_putc+0x27>
shr    $0x6,%ebx
or     $0xc0,%ebx
jmp    1156 <utf8_putc+0x46>
mov    %ebx,%edi
shr    $0xc,%edi
or     $0xe0,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
shr    $0x6,%ebx
and    $0x3f,%ebx
or     $0x80,%ebx
movzwl %bx,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
and    $0x3f,%ebp
or     $0x80,%ebp
movzwl %bp,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putc@plt>

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

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