#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 uint16_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ append_code(char *, int, char const *(*)(int));
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
const char *convert_to_string(uint16_t code, const char *(*lookup)(uint16_t)) {
  static char buf[256];
  uint16_t current_code, last_code = 0;
  if (code == 0)
    return lookup(0);
  memset(buf, 0, sizeof(buf));
  current_code = code & 0xf000;
  if (current_code != last_code)
    append_code(buf, current_code, lookup);
  last_code = current_code;
  current_code = code & 0xff00;
  if (current_code != last_code)
    append_code(buf, current_code, lookup);
  last_code = current_code;
  current_code = code & 0xfff0;
  if (current_code != last_code)
    append_code(buf, current_code, lookup);
  last_code = current_code;
  current_code = code & 0xffff;
  if (current_code != last_code)
    append_code(buf, current_code, lookup);
  last_code = current_code;
  return buf;
}


x86 assembly (clang, -O0):
<convert_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114e <convert_to_string+0x2e>
xor    %edi,%edi
call   *-0x18(%rbp)
mov    %rax,-0x8(%rbp)
jmp    122c <convert_to_string+0x10c>
lea    0x2eeb(%rip),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
and    $0xf000,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     118b <convert_to_string+0x6b>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0x2eba(%rip),%rdi
call   1030 <append_code@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff00,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11bb <convert_to_string+0x9b>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0x2e8a(%rip),%rdi
call   1030 <append_code@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0xfff0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11eb <convert_to_string+0xcb>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0x2e5a(%rip),%rdi
call   1030 <append_code@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     121b <convert_to_string+0xfb>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0x2e2a(%rip),%rdi
call   1030 <append_code@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0x2e18(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_string>:
test   %edi,%edi
je     11c9 <convert_to_string+0xa9>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %rsi,%r15
lea    0x2f04(%rip),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    %r14d,%ebx
and    $0xf000,%ebx
je     1164 <convert_to_string+0x44>
lea    0x2ee6(%rip),%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1030 <append_code@plt>
mov    %r14d,%ebp
and    $0xff00,%ebp
cmp    %ebx,%ebp
je     1182 <convert_to_string+0x62>
lea    0x2ec8(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1030 <append_code@plt>
mov    %r14d,%ebx
and    $0xfff0,%ebx
cmp    %ebp,%ebx
je     11a0 <convert_to_string+0x80>
lea    0x2eaa(%rip),%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1030 <append_code@plt>
movzwl %r14w,%esi
cmp    %ebx,%esi
je     11b7 <convert_to_string+0x97>
lea    0x2e91(%rip),%rdi
mov    %r15,%rdx
call   1030 <append_code@plt>
lea    0x2e82(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
jmp    *%rsi

LLVM IR (-O0):
@convert_to_string.buf = internal global [256 x i8] zeroinitializer
define i8* @convert_to_string(i32 %0, i8* (i32)* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8* (i32)*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* (i32)* %1, i8* (i32)** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8* (i32)*, i8* (i32)** %5
%12 = call i8* %11(i32 0)
store i8* %12, i8** %3
br label %59
13: ; preds = %2
%14 = call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 0, i32 256)
%15 = load i32, i32* %4
%16 = and i32 %15, 61440
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i32, i32* %6
%22 = load i8* (i32)*, i8* (i32)** %5
%23 = call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %21, i8* (i32)* %22)
br label %24
24: ; preds = %20, %13
%25 = load i32, i32* %6
store i32 %25, i32* %7
%26 = load i32, i32* %4
%27 = and i32 %26, 65280
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32, i32* %6
%33 = load i8* (i32)*, i8* (i32)** %5
%34 = call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %32, i8* (i32)* %33)
br label %35
35: ; preds = %31, %24
%36 = load i32, i32* %6
store i32 %36, i32* %7
%37 = load i32, i32* %4
%38 = and i32 %37, 65520
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* %6
%44 = load i8* (i32)*, i8* (i32)** %5
%45 = call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %43, i8* (i32)* %44)
br label %46
46: ; preds = %42, %35
%47 = load i32, i32* %6
store i32 %47, i32* %7
%48 = load i32, i32* %4
%49 = and i32 %48, 65535
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i32, i32* %6
%55 = load i8* (i32)*, i8* (i32)** %5
%56 = call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %54, i8* (i32)* %55)
br label %57
57: ; preds = %53, %46
%58 = load i32, i32* %6
store i32 %58, i32* %7
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i8** %3
br label %59
59: ; preds = %57, %10
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@convert_to_string.buf = internal global [256 x i8] zeroinitializer
define i8* @convert_to_string(i32 %0, i8* (i32)* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* %1(i32 0)
br label %27
6: ; preds = %2
%7 = tail call i32 @memset(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 0, i32 256)
%8 = and i32 %0, 61440
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %8, i8* (i32)* %1)
br label %12
12: ; preds = %10, %6
%13 = and i32 %0, 65280
%14 = icmp eq i32 %13, %8
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %13, i8* (i32)* %1)
br label %17
17: ; preds = %15, %12
%18 = and i32 %0, 65520
%19 = icmp eq i32 %18, %13
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %18, i8* (i32)* %1)
br label %22
22: ; preds = %20, %17
%23 = and i32 %0, 65535
%24 = icmp eq i32 %23, %18
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @append_code(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), i32 %23, i8* (i32)* %1)
br label %27
27: ; preds = %22, %25, %4
%28 = phi i8* [ %5, %4 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), %25 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @convert_to_string.buf, i64 0, i64 0), %22 ]
ret i8* %28
}