#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 */
void *gx_tohex(int);
void gx_convert_int_to_ascii(char *from, char *to, int n) {
  int nib;
  int ch;
  while (n--) {
    ch = *from++;
    nib = ((ch & 0xf0) >> 4) & 0x0f;
    *to++ = gx_tohex(nib);
    nib = ch & 0x0f;
    *to++ = gx_tohex(nib);
  }
  *to = 0;
}


x86 assembly (clang, -O0):
<gx_convert_int_to_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11a1 <gx_convert_int_to_ascii+0x91>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <gx_tohex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <gx_tohex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1123 <gx_convert_int_to_ascii+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gx_convert_int_to_ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
test   %edx,%edx
je     1162 <gx_convert_int_to_ascii+0x52>
mov    %rdi,%r14
mov    %edx,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
shr    $0x4,%edi
call   1030 <gx_tohex@plt>
mov    %al,(%r15,%rbx,2)
and    $0xf,%ebp
mov    %ebp,%edi
call   1030 <gx_tohex@plt>
mov    %al,0x1(%r15,%rbx,2)
add    $0x1,%rbx
add    $0xfffffffffffffffe,%r13
cmp    %ebx,%r12d
jne    1130 <gx_convert_int_to_ascii+0x20>
sub    %r13,%r15
movb   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gx_convert_int_to_ascii(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %9
9: ; preds = %13, %3
%10 = load i32, i32* %6
%11 = add nsw i32 %10, -1
store i32 %11, i32* %6
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = and i32 %18, 240
%20 = ashr i32 %19, 4
%21 = and i32 %20, 15
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i8* @gx_tohex(i32 %22)
%24 = ptrtoint i8* %23 to i8
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
store i8 %24, i8* %25
%27 = load i32, i32* %8
%28 = and i32 %27, 15
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i8* @gx_tohex(i32 %29)
%31 = ptrtoint i8* %30 to i8
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
store i8 %31, i8* %32
br label %9
34: ; preds = %9
%35 = load i8*, i8** %5
store i8 0, i8* %35
ret void
}

LLVM IR (-O2):
define void @gx_convert_int_to_ascii(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %10, %5 ], [ %0, %3 ]
%7 = phi i8* [ %22, %5 ], [ %1, %3 ]
%8 = phi i32 [ %9, %5 ], [ %2, %3 ]
%9 = add nsw i32 %8, -1
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = lshr i32 %12, 4
%14 = tail call i8* @gx_tohex(i32 %13)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i8
%17 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %16, i8* %7
%18 = and i32 %12, 15
%19 = tail call i8* @gx_tohex(i32 %18)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i8
%22 = getelementptr inbounds i8, i8* %7, i64 2
store i8 %21, i8* %17
%23 = icmp eq i32 %9, 0
br i1 %23, label %24, label %5
24: ; preds = %5, %3
%25 = phi i8* [ %1, %3 ], [ %22, %5 ]
store i8 0, i8* %25
ret void
}