#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ vLongToStr(unsigned long, int, unsigned char *);
int /*<<< orphan*/ vOneTwo(unsigned char *, int, unsigned char *);
void vLongToHex(unsigned long ulLongNumber, int iLength,
                unsigned char *psHexString) {
  unsigned char sBuf[4], szBuf[8];
  vLongToStr(ulLongNumber, 4, sBuf);
  vOneTwo(sBuf, 4, szBuf);
  memset(psHexString, '0', iLength);
  if (iLength > 8)
    memcpy(psHexString + iLength - 8, szBuf, 8);
  else
    memcpy(psHexString, szBuf + 8 - iLength, iLength);
}


x86 assembly (clang, -O0):
<vLongToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rdx
mov    $0x4,%esi
call   1050 <vLongToStr@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x24(%rbp),%rdx
mov    $0x4,%esi
call   1060 <vOneTwo@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x30,%esi
call   1030 <memset@plt>
cmpl   $0x8,-0xc(%rbp)
jle    11b4 <vLongToHex+0x74>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
jmp    11d4 <vLongToHex+0x94>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
add    $0x8,%rsi
movslq -0xc(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vLongToHex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
lea    0xc(%rsp),%r14
mov    $0x4,%esi
mov    %r14,%rdx
call   1050 <vLongToStr@plt>
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
call   1060 <vOneTwo@plt>
mov    %rbx,%rdi
mov    $0x30,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
cmp    $0x9,%ebp
jl     119b <vLongToHex+0x5b>
mov    %ebp,%eax
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffff8,%rdi
lea    0x4(%rsp),%rsi
mov    $0x8,%edx
jmp    11ae <vLongToHex+0x6e>
movslq %ebp,%rax
neg    %rax
lea    (%rsp,%rax,1),%rsi
add    $0xc,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @vLongToHex(i64 %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [4 x i8]
%8 = alloca [8 x i8]
store i64 %0, i64* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i64, i64* %4
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%11 = call i32 @vLongToStr(i64 %9, i32 4, i8* %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%14 = call i32 @vOneTwo(i8* %12, i32 4, i8* %13)
%15 = load i8*, i8** %6
%16 = load i32, i32* %5
%17 = call i32 @memset(i8* %15, i32 48, i32 %16)
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 8
br i1 %19, label %20, label %28
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -8
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%27 = call i32 @memcpy(i8* %25, i8* %26, i32 8)
br label %38
28: ; preds = %3
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 8
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = sub i64 0, %33
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i32, i32* %5
%37 = call i32 @memcpy(i8* %29, i8* %35, i32 %36)
br label %38
38: ; preds = %28, %20
ret void
}

LLVM IR (-O2):
define void @vLongToHex(i64 %0, i32 %1, i8* %2) {
%4 = alloca [4 x i8]
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = call i32 @vLongToStr(i64 %0, i32 4, i8* %6)
%9 = call i32 @vOneTwo(i8* %6, i32 4, i8* %7)
%10 = call i32 @memset(i8* %2, i32 48, i32 %1)
%11 = icmp sgt i32 %1, 8
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = zext i32 %1 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -8
%16 = call i32 @memcpy(i8* %15, i8* %7, i32 8)
br label %23
17: ; preds = %3
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 8
%19 = sext i32 %1 to i64
%20 = sub nsw i64 0, %19
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32 @memcpy(i8* %2, i8* %21, i32 %1)
br label %23
23: ; preds = %17, %12
ret void
}