char *mvp_itoh(int integer) {
  char *str_hex = ((void *)0);
  char *phex;
  unsigned int ui = (unsigned int)integer;
  char half_byte;
  int length;
  int pos;
  int i;
  if (ui <= 0xffffffff) {
    if (ui > 0xffff) {
      length = 8;
    } else if (ui > 0xff) {
      length = 4;
    } else {
      length = 2;
    }
    str_hex = (char *)malloc(length + 4);
    if (((void *)0) != str_hex) {
      phex = str_hex;
      *phex++ = '0';
      *phex++ = 'x';
      for (i = 0; i < length; i++) {
        pos = ((length - i) - 1) * 4;
        half_byte = ((ui & (0x0000000f << pos)) >> pos) & 0x0f;
        if ((half_byte >= 0) && (half_byte <= 9)) {
          *phex++ = '0' + half_byte;
        } else if (half_byte > 9) {
          *phex++ = 'a' + (half_byte - 10);
        }
      }
      *phex = 0;
    }
  }
  return str_hex;
}


x86 assembly (clang, -O0):
<mvp_itoh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
ja     1280 <mvp_itoh+0x170>
cmpl   $0xffff,-0x1c(%rbp)
jbe    114c <mvp_itoh+0x3c>
movl   $0x8,-0x24(%rbp)
jmp    1171 <mvp_itoh+0x61>
cmpl   $0xff,-0x1c(%rbp)
jbe    1165 <mvp_itoh+0x55>
movl   $0x4,-0x24(%rbp)
jmp    116c <mvp_itoh+0x5c>
movl   $0x2,-0x24(%rbp)
jmp    1171 <mvp_itoh+0x61>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
movslq %eax,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     127b <mvp_itoh+0x16b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x30,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x78,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1274 <mvp_itoh+0x164>
mov    -0x24(%rbp),%eax
sub    -0x2c(%rbp),%eax
sub    $0x1,%eax
shl    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%ecx
mov    $0xf,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    -0x28(%rbp),%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
jl     1232 <mvp_itoh+0x122>
movsbl -0x1d(%rbp),%eax
cmp    $0x9,%eax
jg     1232 <mvp_itoh+0x122>
movsbl -0x1d(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1261 <mvp_itoh+0x151>
movsbl -0x1d(%rbp),%eax
cmp    $0x9,%eax
jle    125c <mvp_itoh+0x14c>
movsbl -0x1d(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1261 <mvp_itoh+0x151>
jmp    1266 <mvp_itoh+0x156>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c2 <mvp_itoh+0xb2>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1280 <mvp_itoh+0x170>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvp_itoh>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %edi,%r14d
xor    %eax,%eax
cmp    $0x100,%edi
setae  %al
cmp    $0x10000,%edi
lea    0x2(%rax,%rax,1),%eax
mov    $0x8,%ebx
cmovb  %eax,%ebx
lea    0x4(%rbx),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1525 <mvp_itoh+0x415>
mov    %rax,%rcx
movw   $0x7830,(%rax)
add    $0x2,%rcx
lea    -0x2(%rbx),%r8d
xor    %esi,%esi
cmp    $0xe,%r8d
jae    1169 <mvp_itoh+0x59>
mov    %rcx,%rdx
jmp    14dd <mvp_itoh+0x3cd>
add    $0x2,%r8
mov    %r8,%rsi
and    $0xfffffffffffffff0,%rsi
lea    (%rcx,%rsi,1),%rdx
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,0x40(%rsp)
movd   %r14d,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,0x30(%rsp)
movdqa 0xe61(%rip),%xmm2
movdqa 0xe69(%rip),%xmm3
movdqa 0xe71(%rip),%xmm1
movdqa 0xe78(%rip),%xmm13
xor    %edi,%edi
movdqa 0xe8d(%rip),%xmm15
movdqa 0x30(%rsp),%xmm14
nopw   0x0(%rax,%rax,1)
movdqa %xmm1,(%rsp)
movdqa %xmm3,0x10(%rsp)
movdqa %xmm2,0x20(%rsp)
movdqa 0x20(%rsp),%xmm2
pcmpeqd %xmm0,%xmm0
pxor   %xmm0,%xmm2
movdqa 0x10(%rsp),%xmm3
pxor   %xmm0,%xmm3
movdqa (%rsp),%xmm1
pxor   %xmm0,%xmm1
movdqa %xmm13,%xmm7
pxor   %xmm0,%xmm7
movdqa 0x40(%rsp),%xmm0
paddd  %xmm0,%xmm7
paddd  %xmm0,%xmm1
paddd  %xmm0,%xmm3
paddd  %xmm0,%xmm2
movdqa %xmm2,%xmm0
movdqa %xmm3,%xmm11
pslld  $0x2,%xmm11
movdqa %xmm1,%xmm9
pslld  $0x2,%xmm9
movdqa %xmm7,%xmm12
pslld  $0x2,%xmm12
pslld  $0x19,%xmm7
movdqa 0xded(%rip),%xmm4
paddd  %xmm4,%xmm7
cvttps2dq %xmm7,%xmm7
pshufd $0xf5,%xmm7,%xmm6
pmuludq %xmm15,%xmm7
pshufd $0xe8,%xmm7,%xmm7
pmuludq %xmm15,%xmm6
pshufd $0xe8,%xmm6,%xmm6
punpckldq %xmm6,%xmm7
pslld  $0x19,%xmm1
paddd  %xmm4,%xmm1
cvttps2dq %xmm1,%xmm1
pshufd $0xf5,%xmm1,%xmm6
pmuludq %xmm15,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm15,%xmm6
pshufd $0xe8,%xmm6,%xmm6
punpckldq %xmm6,%xmm1
pslld  $0x19,%xmm3
paddd  %xmm4,%xmm3
cvttps2dq %xmm3,%xmm3
pshufd $0xf5,%xmm3,%xmm6
pmuludq %xmm15,%xmm3
pshufd $0xe8,%xmm3,%xmm10
pmuludq %xmm15,%xmm6
pshufd $0xe8,%xmm6,%xmm3
punpckldq %xmm3,%xmm10
pslld  $0x19,%xmm2
paddd  %xmm4,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm15,%xmm2
pshufd $0xe8,%xmm2,%xmm8
pmuludq %xmm15,%xmm3
pshufd $0xe8,%xmm3,%xmm2
punpckldq %xmm2,%xmm8
pand   %xmm14,%xmm10
pand   %xmm14,%xmm1
pand   %xmm14,%xmm7
pshufd $0xee,%xmm12,%xmm2
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm7,%xmm6
psrld  %xmm3,%xmm6
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm7,%xmm3
psrld  %xmm2,%xmm3
punpckhqdq %xmm6,%xmm3
pshuflw $0xfe,%xmm12,%xmm2
movdqa %xmm7,%xmm6
psrld  %xmm2,%xmm6
pshuflw $0x54,%xmm12,%xmm2
psrld  %xmm2,%xmm7
punpcklqdq %xmm6,%xmm7
shufps $0xcc,%xmm3,%xmm7
pshufd $0xee,%xmm9,%xmm2
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm1,%xmm6
psrld  %xmm3,%xmm6
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm1,%xmm3
psrld  %xmm2,%xmm3
punpckhqdq %xmm6,%xmm3
pshuflw $0xfe,%xmm9,%xmm2
movdqa %xmm1,%xmm6
psrld  %xmm2,%xmm6
pshuflw $0x54,%xmm9,%xmm2
psrld  %xmm2,%xmm1
pshufd $0xee,%xmm11,%xmm2
pshuflw $0xfe,%xmm2,%xmm4
movdqa %xmm10,%xmm5
psrld  %xmm4,%xmm5
pslld  $0x2,%xmm0
pand   %xmm14,%xmm8
punpcklqdq %xmm6,%xmm1
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm10,%xmm4
psrld  %xmm2,%xmm4
shufps $0xcc,%xmm3,%xmm1
pshuflw $0xfe,%xmm11,%xmm2
movdqa %xmm10,%xmm3
psrld  %xmm2,%xmm3
punpckhqdq %xmm5,%xmm4
pshuflw $0x54,%xmm11,%xmm2
psrld  %xmm2,%xmm10
pshufd $0xee,%xmm0,%xmm2
pshuflw $0xfe,%xmm2,%xmm5
movdqa %xmm8,%xmm6
psrld  %xmm5,%xmm6
punpcklqdq %xmm3,%xmm10
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm8,%xmm3
psrld  %xmm2,%xmm3
shufps $0xcc,%xmm4,%xmm10
pshuflw $0xfe,%xmm0,%xmm2
movdqa %xmm8,%xmm4
psrld  %xmm2,%xmm4
punpckhqdq %xmm6,%xmm3
pshuflw $0x54,%xmm0,%xmm0
psrld  %xmm0,%xmm8
punpcklqdq %xmm4,%xmm8
shufps $0xcc,%xmm3,%xmm8
andps  %xmm15,%xmm8
andps  %xmm15,%xmm10
andps  %xmm15,%xmm1
andps  %xmm15,%xmm7
movdqa 0xc1c(%rip),%xmm3
movdqa %xmm3,%xmm0
pcmpgtd %xmm7,%xmm0
movdqa %xmm3,%xmm2
pcmpgtd %xmm1,%xmm2
packssdw %xmm2,%xmm0
movdqa %xmm3,%xmm2
pcmpgtd %xmm10,%xmm2
pcmpgtd %xmm8,%xmm3
packssdw %xmm3,%xmm2
movdqa 0x10(%rsp),%xmm3
packsswb %xmm2,%xmm0
movdqa 0x20(%rsp),%xmm2
packuswb %xmm1,%xmm7
packuswb %xmm8,%xmm10
packuswb %xmm10,%xmm7
movdqa %xmm7,%xmm1
paddb  0xbdc(%rip),%xmm1
por    0xbe4(%rip),%xmm7
pand   %xmm0,%xmm7
pandn  %xmm1,%xmm0
movdqa (%rsp),%xmm1
por    %xmm7,%xmm0
movdqu %xmm0,(%rcx,%rdi,1)
add    $0x10,%rdi
movdqa 0xbd2(%rip),%xmm0
paddd  %xmm0,%xmm13
paddd  %xmm0,%xmm1
paddd  %xmm0,%xmm3
paddd  %xmm0,%xmm2
cmp    %rdi,%rsi
jne    11d0 <mvp_itoh+0xc0>
cmp    %rsi,%r8
je     1522 <mvp_itoh+0x412>
sub    %esi,%ebx
lea    -0x4(,%rbx,4),%ecx
cs nopw 0x0(%rax,%rax,1)
mov    $0xf,%esi
shl    %cl,%esi
and    %r14d,%esi
shr    %cl,%esi
and    $0xf,%esi
lea    0x57(%rsi),%edi
lea    0x30(%rsi),%ebp
cmp    $0xa,%esi
movzbl %bpl,%esi
movzbl %dil,%edi
cmovb  %esi,%edi
mov    %dil,(%rdx)
add    $0x1,%rdx
add    $0xfffffffc,%ecx
add    $0xffffffff,%ebx
jne    14f0 <mvp_itoh+0x3e0>
movb   $0x0,(%rdx)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @mvp_itoh(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %3
%10 = load i32, i32* %2
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp ule i32 %11, -1
br i1 %12, label %13, label %88
13: ; preds = %1
%14 = load i32, i32* %5
%15 = icmp ugt i32 %14, 65535
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 8, i32* %7
br label %23
17: ; preds = %13
%18 = load i32, i32* %5
%19 = icmp ugt i32 %18, 255
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 4, i32* %7
br label %22
21: ; preds = %17
store i32 2, i32* %7
br label %22
22: ; preds = %21, %20
br label %23
23: ; preds = %22, %16
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 4
%26 = sext i32 %25 to i64
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %3
%28 = load i8*, i8** %3
%29 = icmp ne i8* null, %28
br i1 %29, label %30, label %87
30: ; preds = %23
%31 = load i8*, i8** %3
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 48, i8* %32
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
store i8 120, i8* %34
store i32 0, i32* %9
br label %36
36: ; preds = %82, %30
%37 = load i32, i32* %9
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %85
40: ; preds = %36
%41 = load i32, i32* %7
%42 = load i32, i32* %9
%43 = sub nsw i32 %41, %42
%44 = sub nsw i32 %43, 1
%45 = mul nsw i32 %44, 4
store i32 %45, i32* %8
%46 = load i32, i32* %5
%47 = load i32, i32* %8
%48 = shl i32 15, %47
%49 = and i32 %46, %48
%50 = load i32, i32* %8
%51 = lshr i32 %49, %50
%52 = and i32 %51, 15
%53 = trunc i32 %52 to i8
store i8 %53, i8* %6
%54 = load i8, i8* %6
%55 = sext i8 %54 to i32
%56 = icmp sge i32 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %40
%58 = load i8, i8* %6
%59 = sext i8 %58 to i32
%60 = icmp sle i32 %59, 9
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i8, i8* %6
%63 = sext i8 %62 to i32
%64 = add nsw i32 48, %63
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %4
store i8 %65, i8* %66
br label %81
68: ; preds = %57, %40
%69 = load i8, i8* %6
%70 = sext i8 %69 to i32
%71 = icmp sgt i32 %70, 9
br i1 %71, label %72, label %80
72: ; preds = %68
%73 = load i8, i8* %6
%74 = sext i8 %73 to i32
%75 = sub nsw i32 %74, 10
%76 = add nsw i32 97, %75
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %4
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %4
store i8 %77, i8* %78
br label %80
80: ; preds = %72, %68
br label %81
81: ; preds = %80, %61
br label %82
82: ; preds = %81
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 1
store i32 %84, i32* %9
br label %36
85: ; preds = %36
%86 = load i8*, i8** %4
store i8 0, i8* %86
br label %87
87: ; preds = %85, %23
br label %88
88: ; preds = %87, %1
%89 = load i8*, i8** %3
ret i8* %89
}

LLVM IR (-O2):
define noalias i8* @mvp_itoh(i32 %0) {
%2 = icmp ugt i32 %0, 65535
%3 = icmp ugt i32 %0, 255
%4 = select i1 %3, i32 4, i32 2
%5 = select i1 %2, i32 8, i32 %4
%6 = add nuw nsw i32 %5, 4
%7 = zext i32 %6 to i64
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %70, label %10
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 48, i8* %8
%12 = getelementptr inbounds i8, i8* %8, i64 2
store i8 120, i8* %11
%13 = add nsw i32 %5, -2
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 2
%16 = icmp ult i32 %13, 14
br i1 %16, label %47, label %17
17: ; preds = %10
%18 = and i64 %15, 8589934576
%19 = trunc i64 %18 to i32
%20 = getelementptr i8, i8* %12, i64 %18
%21 = insertelement <16 x i32> poison, i32 %5, i64 0
%22 = shufflevector <16 x i32> %21, <16 x i32> poison, <16 x i32> zeroinitializer
%23 = insertelement <16 x i32> poison, i32 %0, i64 0
%24 = shufflevector <16 x i32> %23, <16 x i32> poison, <16 x i32> zeroinitializer
br label %25
25: ; preds = %25, %17
%26 = phi i64 [ 0, %17 ], [ %42, %25 ]
%27 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %17 ], [ %43, %25 ]
%28 = getelementptr i8, i8* %12, i64 %26
%29 = xor <16 x i32> %27, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%30 = add nsw <16 x i32> %22, %29
%31 = shl nsw <16 x i32> %30, <i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2>
%32 = shl <16 x i32> <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>, %31
%33 = and <16 x i32> %32, %24
%34 = lshr <16 x i32> %33, %31
%35 = and <16 x i32> %34, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
%36 = icmp ult <16 x i32> %35, <i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10>
%37 = trunc <16 x i32> %35 to <16 x i8>
%38 = add nuw nsw <16 x i8> %37, <i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87>
%39 = or <16 x i8> %37, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%40 = select <16 x i1> %36, <16 x i8> %39, <16 x i8> %38
%41 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> %40, <16 x i8>* %41
%42 = add nuw i64 %26, 16
%43 = add <16 x i32> %27, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%44 = icmp eq i64 %42, %18
br i1 %44, label %45, label %25
45: ; preds = %25
%46 = icmp eq i64 %15, %18
br i1 %46, label %68, label %47
47: ; preds = %10, %45
%48 = phi i32 [ 0, %10 ], [ %19, %45 ]
%49 = phi i8* [ %12, %10 ], [ %20, %45 ]
br label %50
50: ; preds = %47, %50
%51 = phi i32 [ %66, %50 ], [ %48, %47 ]
%52 = phi i8* [ %65, %50 ], [ %49, %47 ]
%53 = xor i32 %51, -1
%54 = add nsw i32 %5, %53
%55 = shl nsw i32 %54, 2
%56 = shl i32 15, %55
%57 = and i32 %56, %0
%58 = lshr i32 %57, %55
%59 = and i32 %58, 15
%60 = icmp ult i32 %59, 10
%61 = trunc i32 %59 to i8
%62 = add nuw nsw i8 %61, 87
%63 = or i8 %61, 48
%64 = select i1 %60, i8 %63, i8 %62
%65 = getelementptr inbounds i8, i8* %52, i64 1
store i8 %64, i8* %52
%66 = add nuw nsw i32 %51, 1
%67 = icmp eq i32 %66, %5
br i1 %67, label %68, label %50
68: ; preds = %50, %45
%69 = phi i8* [ %20, %45 ], [ %65, %50 ]
store i8 0, i8* %69
br label %70
70: ; preds = %1, %68
ret i8* %8
}