#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 */
typedef int /*<<< orphan*/ targetBuf;

/* Variables and functions */
int /*<<< orphan*/ dumpBCD(unsigned char *, int);
int /*<<< orphan*/ float2BCD(double, int, int, unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int long2BCD(long, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ stderr;
int ulong2BCD(unsigned long, unsigned char *, int);
int main(int argc, char *argv[]) {
  unsigned long v1 = 12223;
  long v2 = -11235;
  unsigned char targetBuf[20];
  int rc;
  memset(targetBuf, '\0', sizeof(targetBuf));
  rc = ulong2BCD(v1, targetBuf, sizeof(targetBuf));
  fprintf(stderr, "ulong2BCD returns %d\n", rc);
  dumpBCD(targetBuf, sizeof(targetBuf));
  memset(targetBuf, '\0', sizeof(targetBuf));
  rc = long2BCD(v2, targetBuf, sizeof(targetBuf));
  fprintf(stderr, "long2BCD returns %d\n", rc);
  dumpBCD(targetBuf, sizeof(targetBuf));
  float2BCD(623322.773, 9, 4, targetBuf, sizeof(targetBuf));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x2fbf,-0x18(%rbp)
movq   $0xffffffffffffd41d,-0x20(%rbp)
ff
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1030 <ulong2BCD@plt>
mov    %eax,-0x44(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x14,%esi
call   1080 <dumpBCD@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1070 <long2BCD@plt>
mov    %eax,-0x44(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xe07(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x14,%esi
call   1080 <dumpBCD@plt>
lea    -0x40(%rbp),%rdx
movsd  0xddf(%rip),%xmm0
mov    $0x9,%edi
mov    $0x4,%esi
mov    $0x14,%ecx
call   1060 <float2BCD@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    $0x2fbf,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1030 <ulong2BCD@plt>
mov    0x2e4e(%rip),%r14
mov    (%r14),%edi
lea    0xe6c(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1080 <dumpBCD@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    $0xffffffffffffd41d,%rdi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1070 <long2BCD@plt>
mov    (%r14),%edi
lea    0xe2c(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1080 <dumpBCD@plt>
movsd  0xe07(%rip),%xmm0
mov    $0x9,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
mov    $0x14,%ecx
call   1060 <float2BCD@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"ulong2BCD returns %d\0A\00"
@.str.1 = [21 x i8] c"long2BCD returns %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca [20 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 12223, i64* %5
store i64 -11235, i64* %6
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 20)
%11 = load i64, i64* %5
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%13 = call i32 @ulong2BCD(i64 %11, i8* %12, i32 20)
store i32 %13, i32* %8
%14 = load i32, i32* @stderr
%15 = load i32, i32* %8
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%18 = call i32 @dumpBCD(i8* %17, i32 20)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i8 signext 0, i32 20)
%21 = load i64, i64* %6
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%23 = call i32 @long2BCD(i64 %21, i8* %22, i32 20)
store i32 %23, i32* %8
%24 = load i32, i32* @stderr
%25 = load i32, i32* %8
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%28 = call i32 @dumpBCD(i8* %27, i32 20)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%30 = call i32 @float2BCD(double 0x412305B58BC6A7F0, i32 9, i32 4, i8* %29, i32 20)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"ulong2BCD returns %d\0A\00"
@.str.1 = [21 x i8] c"long2BCD returns %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 20)
%6 = call i32 @ulong2BCD(i64 12223, i8* %4, i32 20)
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = call i32 @dumpBCD(i8* %4, i32 20)
%10 = call i32 @memset(i8* %4, i8 signext 0, i32 20)
%11 = call i32 @long2BCD(i64 -11235, i8* %4, i32 20)
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%14 = call i32 @dumpBCD(i8* %4, i32 20)
%15 = call i32 @float2BCD(double 0x412305B58BC6A7F0, i32 9, i32 4, i8* %4, i32 20)
ret i32 0
}