#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
const char *utf8(int c, char cl, FILE *f) {
  static unsigned char utf[4];
  if (c < 0x80) {
    utf[0] = (unsigned char)c;
    utf[1] = 0;
  } else if (c < 0x800) {
    utf[0] = 0xC0 | (c >> 6);
    utf[1] = 0x80 | (c & 0x3F);
    utf[2] = 0;
  } else if (c < 0x10000) {
    utf[0] = 0xE0 | (c >> 12);
    utf[1] = 0x80 | ((c >> 6) & 0x3F);
    utf[2] = 0x80 | (c & 0x3F);
    utf[3] = 0;
  } else {
    utf[0] = 0;
  }
  if (cl) {
    fprintf(f, "<td class=%c> %s ", cl, utf);
  } else {
    fprintf(f, "<td> %s ", utf);
  }
}


x86 assembly (clang, -O0):
<utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1147 <utf8+0x37>
mov    -0xc(%rbp),%eax
mov    %al,0x2eee(%rip)
movb   $0x0,0x2ee8(%rip)
jmp    11e2 <utf8+0xd2>
cmpl   $0x800,-0xc(%rbp)
jge    1182 <utf8+0x72>
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
or     $0xc0,%eax
mov    %al,0x2ec4(%rip)
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,0x2eb4(%rip)
movb   $0x0,0x2eae(%rip)
jmp    11dd <utf8+0xcd>
cmpl   $0x10000,-0xc(%rbp)
jge    11d1 <utf8+0xc1>
mov    -0xc(%rbp),%eax
sar    $0xc,%eax
or     $0xe0,%eax
mov    %al,0x2e89(%rip)
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,0x2e76(%rip)
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,0x2e66(%rip)
movb   $0x0,0x2e60(%rip)
jmp    11d8 <utf8+0xc8>
movb   $0x0,0x2e51(%rip)
jmp    11dd <utf8+0xcd>
jmp    11e2 <utf8+0xd2>
cmpb   $0x0,-0xd(%rbp)
je     120e <utf8+0xfe>
mov    -0x18(%rbp),%rdi
movsbl -0xd(%rbp),%edx
lea    0xe05(%rip),%rsi
lea    0x2e27(%rip),%rcx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1227 <utf8+0x117>
mov    -0x18(%rbp),%rdi
lea    0xdf9(%rip),%rsi
lea    0x2e09(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8>:
push   %rax
mov    %rdx,%rax
cmp    $0x7f,%edi
jg     1129 <utf8+0x19>
mov    %dil,0x2f09(%rip)
lea    0x2f03(%rip),%rcx
jmp    119d <utf8+0x8d>
cmp    $0x7ff,%edi
ja     1157 <utf8+0x47>
mov    %edi,%ecx
shr    $0x6,%ecx
or     $0xc0,%cl
mov    %cl,0x2eea(%rip)
and    $0x3f,%dil
or     $0x80,%dil
mov    %dil,0x2edc(%rip)
lea    0x2ed6(%rip),%rcx
jmp    119d <utf8+0x8d>
cmp    $0xffff,%edi
ja     1196 <utf8+0x86>
mov    %edi,%ecx
shr    $0xc,%ecx
or     $0xe0,%cl
mov    %cl,0x2ebc(%rip)
mov    %edi,%ecx
shr    $0x6,%ecx
and    $0x3f,%cl
or     $0x80,%cl
mov    %cl,0x2eac(%rip)
and    $0x3f,%dil
or     $0x80,%dil
mov    %dil,0x2e9e(%rip)
lea    0x2e98(%rip),%rcx
jmp    119d <utf8+0x8d>
lea    0x2e8c(%rip),%rcx
movb   $0x0,(%rcx)
test   %sil,%sil
je     11c3 <utf8+0xb3>
movsbl %sil,%edx
lea    0xe50(%rip),%rsi
lea    0x2e72(%rip),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
pop    %rcx
ret
lea    0xe48(%rip),%rsi
lea    0x2e58(%rip),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
pop    %rcx
ret

LLVM IR (-O0):
@utf8.utf = internal global [4 x i8] zeroinitializer
@.str = [18 x i8] c"<td class=%c> %s \00"
@.str.1 = [9 x i8] c"<td> %s \00"
define i8* @utf8(i32 %0, i8 signext %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32* %2, i32** %7
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 128
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* %5
%12 = trunc i32 %11 to i8
store i8 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1)
br label %45
13: ; preds = %3
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 2048
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %5
%18 = ashr i32 %17, 6
%19 = or i32 192, %18
%20 = trunc i32 %19 to i8
store i8 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
%21 = load i32, i32* %5
%22 = and i32 %21, 63
%23 = or i32 128, %22
%24 = trunc i32 %23 to i8
store i8 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1)
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 2)
br label %44
25: ; preds = %13
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 65536
br i1 %27, label %28, label %42
28: ; preds = %25
%29 = load i32, i32* %5
%30 = ashr i32 %29, 12
%31 = or i32 224, %30
%32 = trunc i32 %31 to i8
store i8 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
%33 = load i32, i32* %5
%34 = ashr i32 %33, 6
%35 = and i32 %34, 63
%36 = or i32 128, %35
%37 = trunc i32 %36 to i8
store i8 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1)
%38 = load i32, i32* %5
%39 = and i32 %38, 63
%40 = or i32 128, %39
%41 = trunc i32 %40 to i8
store i8 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 2)
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 3)
br label %43
42: ; preds = %25
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
br label %43
43: ; preds = %42, %28
br label %44
44: ; preds = %43, %16
br label %45
45: ; preds = %44, %10
%46 = load i8, i8* %6
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i32*, i32** %7
%50 = load i8, i8* %6
%51 = sext i8 %50 to i32
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0))
br label %56
53: ; preds = %45
%54 = load i32*, i32** %7
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0))
br label %56
56: ; preds = %53, %48
%57 = load i8*, i8** %4
ret i8* %57
}

LLVM IR (-O2):
@utf8.utf = internal global [4 x i8] zeroinitializer
@.str = [18 x i8] c"<td class=%c> %s \00"
@.str.1 = [9 x i8] c"<td> %s \00"
define noalias i8* @utf8(i32 %0, i8 signext %1, i32* nocapture %2) {
%4 = icmp slt i32 %0, 128
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = trunc i32 %0 to i8
store i8 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
br label %29
7: ; preds = %3
%8 = icmp ult i32 %0, 2048
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = lshr i32 %0, 6
%11 = trunc i32 %10 to i8
%12 = or i8 %11, -64
store i8 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
%13 = trunc i32 %0 to i8
%14 = and i8 %13, 63
%15 = or i8 %14, -128
store i8 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1)
br label %29
16: ; preds = %7
%17 = icmp ult i32 %0, 65536
br i1 %17, label %18, label %29
18: ; preds = %16
%19 = lshr i32 %0, 12
%20 = trunc i32 %19 to i8
%21 = or i8 %20, -32
store i8 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0)
%22 = lshr i32 %0, 6
%23 = trunc i32 %22 to i8
%24 = and i8 %23, 63
%25 = or i8 %24, -128
store i8 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1)
%26 = trunc i32 %0 to i8
%27 = and i8 %26, 63
%28 = or i8 %27, -128
store i8 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 2)
br label %29
29: ; preds = %16, %9, %18, %5
%30 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 2), %9 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 3), %18 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 1), %5 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0), %16 ]
store i8 0, i8* %30
%31 = icmp eq i8 %1, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = sext i8 %1 to i32
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0))
br label %37
35: ; preds = %29
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @utf8.utf, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
ret i8* undef
}