#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 *, unsigned long);
int /*<<< orphan*/ vTwoOne(unsigned char *, int, unsigned char *);
void vL2Bcd(unsigned long ulLongNumber, int iLength,
            unsigned char *psBcdString) {
  unsigned char sTmp[24 + 1];
  ;
  if (iLength > 12 || iLength < 0)
    return;
  sprintf((char *)sTmp, "%024lu", ulLongNumber);
  vTwoOne(sTmp + 24 - iLength * 2, iLength * 2, psBcdString);
}


x86 assembly (clang, -O0):
<vL2Bcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0xc,-0xc(%rbp)
jg     1147 <vL2Bcd+0x27>
cmpl   $0x0,-0xc(%rbp)
jge    114c <vL2Bcd+0x2c>
jmp    1188 <vL2Bcd+0x68>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea5(%rip),%rsi
call   1030 <sprintf@plt>
lea    -0x40(%rbp),%rdi
add    $0x18,%rdi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
movslq %eax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
shl    $0x1,%esi
mov    -0x18(%rbp),%rdx
call   1040 <vTwoOne@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vL2Bcd>:
cmp    $0xc,%esi
ja     116a <vL2Bcd+0x4a>
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rdx
lea    0xec2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
add    %r15d,%r15d
sub    %r15,%rbx
add    $0x18,%rbx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1040 <vTwoOne@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%024lu\00"
define void @vL2Bcd(i64 %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [25 x i8]
store i64 %0, i64* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 12
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %29
14: ; preds = %10
%15 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%16 = load i64, i64* %4
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 24
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = sub i64 0, %22
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, 2
%27 = load i8*, i8** %6
%28 = call i32 @vTwoOne(i8* %24, i32 %26, i8* %27)
br label %29
29: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%024lu\00"
define void @vL2Bcd(i64 %0, i32 %1, i8* %2) {
%4 = alloca [25 x i8]
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%6 = icmp ugt i32 %1, 12
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %0)
%9 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 24
%10 = shl nuw nsw i32 %1, 1
%11 = zext i32 %10 to i64
%12 = sub nsw i64 0, %11
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = call i32 @vTwoOne(i8* %13, i32 %10, i8* %2)
br label %15
15: ; preds = %3, %7
ret void
}