#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 */
unsigned char *xxmalloc(int);
unsigned char *int2utf8str(int codepoint) {
  unsigned char *value;
  value = xxmalloc(sizeof(unsigned char) * 5);
  if (codepoint < 0x80) {
    *(value) = (unsigned char)(codepoint);
    *(value + 1) = 0;
    return (value);
  } else if (codepoint < 0x800) {
    *(value) = (0xc0 | (unsigned char)(codepoint >> 6));
    *(value + 1) = (0x80 | (unsigned char)(codepoint & 0x3f));
    *(value + 2) = 0;
    return (value);
  } else if (codepoint < 0x10000) {
    *(value) = (0xe0 | (unsigned char)(codepoint >> 12));
    *(value + 1) = (0x80 | (unsigned char)((codepoint >> 6) & 0x3f));
    *(value + 2) = (0x80 | (unsigned char)(codepoint & 0x3f));
    *(value + 3) = 0;
    return (value);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<int2utf8str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x5,%edi
call   1030 <xxmalloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1156 <int2utf8str+0x46>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <int2utf8str+0x106>
cmpl   $0x800,-0xc(%rbp)
jge    11a5 <int2utf8str+0x95>
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
movzbl %al,%eax
or     $0xc0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
movzbl %al,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <int2utf8str+0x106>
cmpl   $0x10000,-0xc(%rbp)
jge    120e <int2utf8str+0xfe>
mov    -0xc(%rbp),%eax
sar    $0xc,%eax
movzbl %al,%eax
or     $0xe0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
movzbl %al,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
movzbl %al,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <int2utf8str+0x106>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2utf8str>:
push   %rbx
mov    %edi,%ebx
mov    $0x5,%edi
call   1030 <xxmalloc@plt>
cmp    $0x7f,%ebx
jg     112b <int2utf8str+0x1b>
mov    %bl,(%rax)
mov    $0x1,%ecx
jmp    117b <int2utf8str+0x6b>
cmp    $0x7ff,%ebx
ja     114d <int2utf8str+0x3d>
mov    %ebx,%ecx
shr    $0x6,%ecx
or     $0xc0,%cl
mov    %cl,(%rax)
and    $0x3f,%bl
or     $0x80,%bl
mov    %bl,0x1(%rax)
mov    $0x2,%ecx
jmp    117b <int2utf8str+0x6b>
cmp    $0xffff,%ebx
ja     1181 <int2utf8str+0x71>
mov    %ebx,%ecx
shr    $0xc,%ecx
or     $0xe0,%cl
mov    %cl,(%rax)
mov    %ebx,%ecx
shr    $0x6,%ecx
and    $0x3f,%cl
or     $0x80,%cl
mov    %cl,0x1(%rax)
and    $0x3f,%bl
or     $0x80,%bl
mov    %bl,0x2(%rax)
mov    $0x3,%ecx
movb   $0x0,(%rax,%rcx,1)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @int2utf8str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = call i8* @xxmalloc(i32 5)
store i8* %5, i8** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 128
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* %3
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %4
store i8 %10, i8* %11
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %13
%14 = load i8*, i8** %4
store i8* %14, i8** %2
br label %69
15: ; preds = %1
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 2048
br i1 %17, label %18, label %37
18: ; preds = %15
%19 = load i32, i32* %3
%20 = ashr i32 %19, 6
%21 = trunc i32 %20 to i8
%22 = zext i8 %21 to i32
%23 = or i32 192, %22
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
store i8 %24, i8* %25
%26 = load i32, i32* %3
%27 = and i32 %26, 63
%28 = trunc i32 %27 to i8
%29 = zext i8 %28 to i32
%30 = or i32 128, %29
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 %31, i8* %33
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8 0, i8* %35
%36 = load i8*, i8** %4
store i8* %36, i8** %2
br label %69
37: ; preds = %15
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 65536
br i1 %39, label %40, label %68
40: ; preds = %37
%41 = load i32, i32* %3
%42 = ashr i32 %41, 12
%43 = trunc i32 %42 to i8
%44 = zext i8 %43 to i32
%45 = or i32 224, %44
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %4
store i8 %46, i8* %47
%48 = load i32, i32* %3
%49 = ashr i32 %48, 6
%50 = and i32 %49, 63
%51 = trunc i32 %50 to i8
%52 = zext i8 %51 to i32
%53 = or i32 128, %52
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8 %54, i8* %56
%57 = load i32, i32* %3
%58 = and i32 %57, 63
%59 = trunc i32 %58 to i8
%60 = zext i8 %59 to i32
%61 = or i32 128, %60
%62 = trunc i32 %61 to i8
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 2
store i8 %62, i8* %64
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i64 3
store i8 0, i8* %66
%67 = load i8*, i8** %4
store i8* %67, i8** %2
br label %69
68: ; preds = %37
store i8* null, i8** %2
br label %69
69: ; preds = %68, %40, %18, %8
%70 = load i8*, i8** %2
ret i8* %70
}

LLVM IR (-O2):
define i8* @int2utf8str(i32 %0) {
%2 = tail call i8* @xxmalloc(i32 5)
%3 = icmp slt i32 %0, 128
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = trunc i32 %0 to i8
store i8 %5, i8* %2
br label %31
6: ; preds = %1
%7 = icmp ult i32 %0, 2048
br i1 %7, label %8, label %16
8: ; preds = %6
%9 = lshr i32 %0, 6
%10 = trunc i32 %9 to i8
%11 = or i8 %10, -64
store i8 %11, i8* %2
%12 = trunc i32 %0 to i8
%13 = and i8 %12, 63
%14 = or i8 %13, -128
%15 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %14, i8* %15
br label %31
16: ; preds = %6
%17 = icmp ult i32 %0, 65536
br i1 %17, label %18, label %34
18: ; preds = %16
%19 = lshr i32 %0, 12
%20 = trunc i32 %19 to i8
%21 = or i8 %20, -32
store i8 %21, i8* %2
%22 = lshr i32 %0, 6
%23 = trunc i32 %22 to i8
%24 = and i8 %23, 63
%25 = or i8 %24, -128
%26 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %25, i8* %26
%27 = trunc i32 %0 to i8
%28 = and i8 %27, 63
%29 = or i8 %28, -128
%30 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %29, i8* %30
br label %31
31: ; preds = %4, %8, %18
%32 = phi i64 [ 3, %18 ], [ 2, %8 ], [ 1, %4 ]
%33 = getelementptr inbounds i8, i8* %2, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %31, %16
%35 = phi i8* [ null, %16 ], [ %2, %31 ]
ret i8* %35
}