#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*/ hxtoa(char *, char const *, unsigned int const);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
char *hxtostr(char *dst, const char *src, unsigned int length,
              const char *delimiter, const unsigned int delSize,
              const unsigned int padding) {
  char *ret = dst;
  int i, j;
  strcpy(ret, "");
  char temp[4];
  for (i = 0; i < length; i++) {
    if (i != 0 && delimiter != NULL) {
      for (j = 0; j < delSize; j++) {
        strcat(ret, delimiter);
      }
    }
    hxtoa(temp, src + i, padding);
    strcat(ret, temp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<hxtostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11f4 <hxtostr+0xc4>
cmpl   $0x0,-0x34(%rbp)
je     11c2 <hxtostr+0x92>
cmpq   $0x0,-0x20(%rbp)
je     11c2 <hxtostr+0x92>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11bd <hxtostr+0x8d>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1196 <hxtostr+0x66>
jmp    11c2 <hxtostr+0x92>
lea    -0x3c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x28(%rbp),%edx
call   1050 <hxtoa@plt>
mov    -0x30(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116e <hxtostr+0x3e>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hxtostr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %edx,%r13d
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbp
lea    0xea5(%rip),%rsi
call   1030 <strcpy@plt>
test   %r13d,%r13d
je     11d3 <hxtostr+0xa3>
mov    %r13d,%eax
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
lea    0x24(%rsp),%r13
jmp    11ab <hxtostr+0x7b>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rax
lea    (%rax,%r12,1),%rsi
mov    %r13,%rdi
mov    0xc(%rsp),%edx
call   1050 <hxtoa@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <strcat@plt>
add    $0x1,%r12
cmp    0x10(%rsp),%r12
je     11d3 <hxtostr+0xa3>
test   %rbx,%rbx
je     1180 <hxtostr+0x50>
test   %r12,%r12
je     1180 <hxtostr+0x50>
test   %r14d,%r14d
je     1180 <hxtostr+0x50>
mov    %r14d,%r15d
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcat@plt>
add    $0xffffffff,%r15d
jne    11c0 <hxtostr+0x90>
jmp    1180 <hxtostr+0x50>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @hxtostr(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [4 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%17 = load i8*, i8** %7
store i8* %17, i8** %13
%18 = load i8*, i8** %13
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %14
br label %20
20: ; preds = %54, %6
%21 = load i32, i32* %14
%22 = load i32, i32* %9
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %57
24: ; preds = %20
%25 = load i32, i32* %14
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i8*, i8** %10
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %43
30: ; preds = %27
store i32 0, i32* %15
br label %31
31: ; preds = %39, %30
%32 = load i32, i32* %15
%33 = load i32, i32* %11
%34 = icmp ult i32 %32, %33
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load i8*, i8** %13
%37 = load i8*, i8** %10
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %39
39: ; preds = %35
%40 = load i32, i32* %15
%41 = add nsw i32 %40, 1
store i32 %41, i32* %15
br label %31
42: ; preds = %31
br label %43
43: ; preds = %42, %27, %24
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%45 = load i8*, i8** %8
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i32, i32* %12
%50 = call i32 @hxtoa(i8* %44, i8* %48, i32 %49)
%51 = load i8*, i8** %13
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
%53 = call i32 @strcat(i8* %51, i8* %52)
br label %54
54: ; preds = %43
%55 = load i32, i32* %14
%56 = add nsw i32 %55, 1
store i32 %56, i32* %14
br label %20
57: ; preds = %20
%58 = load i8*, i8** %13
ret i8* %58
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @hxtostr(i8* returned %0, i8* %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca [4 x i8]
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%10 = icmp eq i32 %2, 0
br i1 %10, label %31, label %11
11: ; preds = %6
%12 = icmp eq i8* %3, null
%13 = icmp eq i32 %4, 0
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %11, %25
%16 = phi i64 [ 0, %11 ], [ %29, %25 ]
%17 = icmp eq i64 %16, 0
%18 = or i1 %12, %17
%19 = or i1 %18, %13
br i1 %19, label %25, label %20
20: ; preds = %15, %20
%21 = phi i32 [ %23, %20 ], [ 0, %15 ]
%22 = call i32 @strcat(i8* %0, i8* %3)
%23 = add nuw i32 %21, 1
%24 = icmp eq i32 %23, %4
br i1 %24, label %25, label %20
25: ; preds = %20, %15
%26 = getelementptr inbounds i8, i8* %1, i64 %16
%27 = call i32 @hxtoa(i8* %9, i8* %26, i32 %5)
%28 = call i32 @strcat(i8* %0, i8* %9)
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %31, label %15
31: ; preds = %25, %6
ret i8* %0
}