#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*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, float, ...);
int float2BCD(float val, int dig, int prec, unsigned char bcdBuf[],
              int buflen) {
  char _tmpBuffer[20];
  char _fmtBuffer[20];
  sprintf(_fmtBuffer, "%%%d.%df", dig, prec);
  sprintf(_tmpBuffer, _fmtBuffer, val);
  printf("float - result is: %s\n", _tmpBuffer);
  while (*_tmpBuffer != '\0') {
    switch (*_tmpBuffer) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      break;
    case '.':
    case ',':
      break;
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<float2BCD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x50(%rbp),%rdi
cvtsi2ssl -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edx
lea    0xeb3(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
movss  -0x4(%rbp),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
je     11ce <float2BCD+0xae>
movsbl -0x30(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x2c,%eax
je     11c4 <float2BCD+0xa4>
jmp    119a <float2BCD+0x7a>
mov    -0x54(%rbp),%eax
sub    $0x2e,%eax
je     11c4 <float2BCD+0xa4>
jmp    11ab <float2BCD+0x8b>
mov    -0x54(%rbp),%eax
add    $0xffffffd0,%eax
sub    $0x9,%eax
ja     11c9 <float2BCD+0xa9>
jmp    11bf <float2BCD+0x9f>
jmp    11c9 <float2BCD+0xa9>
jmp    11c9 <float2BCD+0xa9>
jmp    1178 <float2BCD+0x58>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float2BCD>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %esi,%edx
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %edi,%xmm0
lea    0xec3(%rip),%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
movss  0xc(%rsp),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
cmpb   $0x0,0x10(%rsp)
je     1182 <float2BCD+0x62>
nopw   0x0(%rax,%rax,1)
jmp    1180 <float2BCD+0x60>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%%%d.%df\00"
@.str.1 = [23 x i8] c"float - result is: %s\0A\00"
define i32 @float2BCD(float %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [20 x i8]
%12 = alloca [20 x i8]
store float %0, float* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to float
%16 = load i32, i32* %8
%17 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), float %15, i32 %16)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%20 = load float, float* %6
%21 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %18, i8* %19, float %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %35, %5
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
switch i32 %32, label %35 [
i32 48, label %33
i32 49, label %33
i32 50, label %33
i32 51, label %33
i32 52, label %33
i32 53, label %33
i32 54, label %33
i32 55, label %33
i32 56, label %33
i32 57, label %33
i32 46, label %34
i32 44, label %34
]
33: ; preds = %29, %29, %29, %29, %29, %29, %29, %29, %29, %29
br label %35
34: ; preds = %29, %29
br label %35
35: ; preds = %29, %34, %33
br label %24
36: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%%%d.%df\00"
@.str.1 = [23 x i8] c"float - result is: %s\0A\00"
define i32 @float2BCD(float %0, i32 %1, i32 %2, i8* nocapture readnone %3, i32 %4) {
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%10 = sitofp i32 %1 to float
%11 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), float %10, i32 %2)
%12 = call i32 (i8*, i8*, float, ...) @sprintf(i8* %8, i8* %9, float %0)
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %5, %16
br label %16
17: ; preds = %5
ret i32 0
}