#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 */
int /*<<< orphan*/ sprintf(char *, char *, char const);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int const strlen(char *);
char *hxtoa(char *dst, const char *src, const unsigned int padding) {
  int src1 = src[0];
  const char *chars = "0123456789abcdef";
  char *ret = dst, temp[3], temp2[strlen(ret)];
  unsigned int division;
  strcpy(ret, "");
  if (src1 < 0) {
    src1 += 256;
  }
  while (1) {
    division = src1 / 16;
    if (division > 0) {
      sprintf(temp, "%c", chars[division]);
      strcat(ret, temp);
      src1 -= (16 * division);
    } else {
      sprintf(temp, "%c", chars[src1 % 16]);
      strcat(ret, temp);
      break;
    }
  }
  if (ret == NULL || strlen(ret) < 1) {
    strcpy(ret, "00");
  }
  while (strlen(ret) < padding) {
    strcpy(temp2, ret);
    strcpy(ret, "0");
    strcat(ret, temp2);
  }
  return ret;
}


x86 assembly (clang, -O0):
<hxtoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x18(%rbp)
jge    11c3 <hxtoa+0x83>
mov    -0x18(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x18(%rbp)
jmp    11c8 <hxtoa+0x88>
jmp    11cd <hxtoa+0x8d>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jbe    1220 <hxtoa+0xe0>
lea    -0x2b(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
lea    0xe1a(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x44(%rbp),%ecx
shl    $0x4,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1260 <hxtoa+0x120>
lea    -0x2b(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x58(%rbp),%rax
movslq %edx,%rcx
lea    0xdcc(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1265 <hxtoa+0x125>
jmp    11c8 <hxtoa+0x88>
cmpq   $0x0,-0x28(%rbp)
je     1282 <hxtoa+0x142>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jae    1292 <hxtoa+0x152>
mov    -0x28(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1297 <hxtoa+0x157>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jae    12d8 <hxtoa+0x198>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdi
call   1050 <strcat@plt>
jmp    1297 <hxtoa+0x157>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hxtoa>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x30(%rbp)
mov    %rdi,%rbx
movsbl (%rsi),%r14d
call   1040 <strlen@plt>
mov    %rsp,-0x38(%rbp)
mov    %eax,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x100(%r14),%r13d
test   %r14d,%r14d
cmovns %r14d,%r13d
lea    0xf(%r13),%eax
cmp    $0x1f,%eax
jae    1192 <hxtoa+0x62>
mov    %r13d,%eax
jmp    11ea <hxtoa+0xba>
lea    -0x2b(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
lea    0xf(%r13),%r14d
test   %r13d,%r13d
cmovns %r13d,%r14d
mov    %r14d,%eax
sar    $0x4,%eax
lea    0xe48(%rip),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %al,-0x2b(%rbp)
movb   $0x0,-0x2a(%rbp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
and    $0xfffffff0,%r14d
mov    %r13d,%eax
sub    %r14d,%eax
neg    %r14d
lea    (%r14,%r13,1),%ecx
add    $0xf,%ecx
mov    %eax,%r13d
cmp    $0x1e,%ecx
ja     11a0 <hxtoa+0x70>
mov    %eax,%ecx
sar    $0x7,%cl
shr    $0x4,%cl
add    %al,%cl
and    $0xf0,%cl
sub    %cl,%al
movsbq %al,%rax
lea    0xdfc(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2b(%rbp)
movb   $0x0,-0x2a(%rbp)
lea    -0x2b(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
test   %rbx,%rbx
je     122b <hxtoa+0xfb>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jne    123a <hxtoa+0x10a>
lea    0xddf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%r14d
cmp    %r14d,%eax
jae    128e <hxtoa+0x15e>
lea    0xdc0(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r14d,%eax
jb     1260 <hxtoa+0x130>
mov    -0x38(%rbp),%rsp
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"00\00"
@.str.4 = [2 x i8] c"0\00"
define i8* @hxtoa(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [3 x i8]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
store i32 %17, i32* %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %8
%18 = load i8*, i8** %4
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = call i32 @strlen(i8* %19)
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %11
%23 = alloca i8, i64 %21
store i64 %21, i64* %12
%24 = load i8*, i8** %9
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %3
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 256
store i32 %30, i32* %7
br label %31
31: ; preds = %28, %3
br label %32
32: ; preds = %65, %31
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = sdiv i32 %34, 16
store i32 %35, i32* %13
%36 = load i32, i32* %13
%37 = icmp ugt i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %33
%39 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%40 = load i8*, i8** %8
%41 = load i32, i32* %13
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %44)
%46 = load i8*, i8** %9
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = load i32, i32* %13
%50 = mul i32 16, %49
%51 = load i32, i32* %7
%52 = sub i32 %51, %50
store i32 %52, i32* %7
br label %65
53: ; preds = %33
%54 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%55 = load i8*, i8** %8
%56 = load i32, i32* %7
%57 = srem i32 %56, 16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %60)
%62 = load i8*, i8** %9
%63 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%64 = call i32 @strcat(i8* %62, i8* %63)
br label %66
65: ; preds = %38
br label %32
66: ; preds = %53
%67 = load i8*, i8** %9
%68 = icmp eq i8* %67, null
br i1 %68, label %73, label %69
69: ; preds = %66
%70 = load i8*, i8** %9
%71 = call i32 @strlen(i8* %70)
%72 = icmp ult i32 %71, 1
br i1 %72, label %73, label %76
73: ; preds = %69, %66
%74 = load i8*, i8** %9
%75 = call i32 @strcpy(i8* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %76
76: ; preds = %73, %69
br label %77
77: ; preds = %82, %76
%78 = load i8*, i8** %9
%79 = call i32 @strlen(i8* %78)
%80 = load i32, i32* %6
%81 = icmp ult i32 %79, %80
br i1 %81, label %82, label %89
82: ; preds = %77
%83 = load i8*, i8** %9
%84 = call i32 @strcpy(i8* %23, i8* %83)
%85 = load i8*, i8** %9
%86 = call i32 @strcpy(i8* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%87 = load i8*, i8** %9
%88 = call i32 @strcat(i8* %87, i8* %23)
br label %77
89: ; preds = %77
%90 = load i8*, i8** %9
%91 = load i8*, i8** %11
ret i8* %90
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.3 = [3 x i8] c"00\00"
@.str.4 = [2 x i8] c"0\00"
define i8* @hxtoa(i8* returned %0, i8* nocapture %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = load i8, i8* %1
%6 = sext i8 %5 to i32
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %0)
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp slt i8 %5, 0
%14 = add nsw i32 %6, 256
%15 = select i1 %13, i32 %14, i32 %6
%16 = add nsw i32 %15, 15
%17 = icmp ult i32 %16, 31
br i1 %17, label %31, label %18
18: ; preds = %3
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ %15, %18 ], [ %28, %20 ]
%22 = sdiv i32 %21, 16
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %7
store i8 0, i8* %19
%26 = call i32 @strcat(i8* %0, i8* %7)
%27 = mul i32 %22, -16
%28 = add i32 %27, %21
%29 = add i32 %28, 15
%30 = icmp ult i32 %29, 31
br i1 %30, label %31, label %20
31: ; preds = %20, %3
%32 = phi i32 [ %15, %3 ], [ %28, %20 ]
%33 = trunc i32 %32 to i8
%34 = srem i8 %33, 16
%35 = sext i8 %34 to i64
%36 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %35
%37 = load i8, i8* %36
store i8 %37, i8* %7
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 0, i8* %38
%39 = call i32 @strcat(i8* %0, i8* %7)
%40 = icmp eq i8* %0, null
br i1 %40, label %44, label %41
41: ; preds = %31
%42 = call i32 @strlen(i8* %0)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41, %31
%45 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = call i32 @strlen(i8* %0)
%48 = icmp ult i32 %47, %2
br i1 %48, label %49, label %55
49: ; preds = %46, %49
%50 = call i32 @strcpy(i8* %11, i8* %0)
%51 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @strcat(i8* %0, i8* %11)
%53 = call i32 @strlen(i8* %0)
%54 = icmp ult i32 %53, %2
br i1 %54, label %49, label %55
55: ; preds = %49, %46
ret i8* %0
}