#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*/ asc2hex(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void int2bcd(int inInt, unsigned char *BCDData, int NLen) {
  unsigned char Tmp[20];
  unsigned char Fmt[20];
  sprintf((char *)Fmt, "%%0%dd", NLen);
  sprintf((char *)Tmp, (char *)Fmt, inInt);
  asc2hex(Tmp, BCDData, NLen / 2);
}


x86 assembly (clang, -O0):
<int2bcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xec0(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1030 <asc2hex@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2bcd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xec6(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1040 <sprintf@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <sprintf@plt>
mov    %ebx,%edx
shr    $0x1f,%edx
add    %ebx,%edx
sar    %edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <asc2hex@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%%0%dd\00"
define void @int2bcd(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca [20 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%10 = load i32, i32* %6
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @sprintf(i8* %12, i8* %13, i32 %14)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = sdiv i32 %18, 2
%20 = call i32 @asc2hex(i8* %16, i8* %17, i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%0%dd\00"
define void @int2bcd(i32 %0, i8* %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %2)
%9 = call i32 @sprintf(i8* %6, i8* %7, i32 %0)
%10 = sdiv i32 %2, 2
%11 = call i32 @asc2hex(i8* %6, i8* %1, i32 %10)
ret void
}