#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 E2BIG;
scalar_t__ printDec(char *, int, unsigned long, int, char *, int /*<<< orphan*/,
                    int, int, int /*<<< orphan*/);
int printFloat(char *buf, int bufLen, float f) {
  int ret = 0;
  if (f < 0) {
    do {
      if (ret == bufLen) {
        return -E2BIG;
      }
      buf[ret++] = '-';
    } while (0);
    f = -f;
  }
  unsigned long i = f;
  ret += printDec(&buf[ret], bufLen - ret, i, false, "", 0, -1, -1, 0);
  do {
    if (ret == bufLen) {
      return -E2BIG;
    }
    buf[ret++] = '.';
  } while (0);
  f = (f - i) * 1000000 + 0.5;
  ret += printDec(&buf[ret], bufLen - ret, (unsigned long)f, false, "", 0, -1,
                  6, 0);
  return ret;
}


x86 assembly (clang, -O0):
<printFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1189 <printFloat+0x79>
jmp    113d <printFloat+0x2d>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    115c <printFloat+0x4c>
xor    %eax,%eax
mov    0x2e96(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <printFloat+0x21b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
movss  -0x18(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xe6a(%rip),%xmm2
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
cvttss2si %xmm1,%rcx
cvttss2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
xor    %r9d,%r9d
lea    0xe39(%rip),%r8
mov    %r9d,%ecx
movl   $0xffffffff,(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0x0,0x10(%rsp)
call   1030 <printDec@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1222 <printFloat+0x112>
xor    %eax,%eax
mov    0x2dd0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <printFloat+0x21b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x30(%rbp)
test   %rax,%rax
movss  %xmm0,-0x2c(%rbp)
js     127f <printFloat+0x16f>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x34(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  0xd6f(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd63(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
mov    %ecx,%eax
add    %rcx,%rdi
mov    -0x14(%rbp),%esi
sub    %eax,%esi
movss  -0x18(%rbp),%xmm0
movss  0xd2f(%rip),%xmm2
movaps %xmm0,%xmm1
subss  %xmm2,%xmm1
cvttss2si %xmm1,%rax
cvttss2si %xmm0,%rdx
mov    %rdx,%rcx
sar    $0x3f,%rcx
and    %rcx,%rax
or     %rax,%rdx
xor    %r9d,%r9d
lea    0xd17(%rip),%r8
mov    %r9d,%ecx
movl   $0xffffffff,(%rsp)
movl   $0x6,0x8(%rsp)
movl   $0x0,0x10(%rsp)
call   1030 <printDec@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFloat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
xor    %r13d,%r13d
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    1149 <printFloat+0x39>
test   %r15d,%r15d
je     11d1 <printFloat+0xc1>
movb   $0x2d,(%r14)
xorps  0xebd(%rip),%xmm0
mov    $0x1,%r13d
cvttss2si %xmm0,%rax
mov    %rax,%rcx
movaps %xmm0,(%rsp)
subss  0xeb3(%rip),%xmm0
sar    $0x3f,%rcx
cvttss2si %xmm0,%rbp
and    %rcx,%rbp
or     %rax,%rbp
mov    %r13d,%edi
add    %r14,%rdi
mov    %r15d,%esi
sub    %r13d,%esi
sub    $0x8,%rsp
lea    0xe99(%rip),%r8
xor    %ebx,%ebx
mov    %rbp,%rdx
xor    %ecx,%ecx
xor    %r9d,%r9d
push   $0x0
push   $0xffffffffffffffff
push   $0xffffffffffffffff
call   1030 <printDec@plt>
add    $0x20,%rsp
mov    %rax,%r12
add    %r13d,%r12d
cmp    %r15d,%r12d
jne    11b5 <printFloat+0xa5>
mov    0x2e3a(%rip),%rax
sub    (%rax),%ebx
jmp    1264 <printFloat+0x154>
lea    0x1(%r12),%eax
movslq %r12d,%rcx
movb   $0x2e,(%r14,%rcx,1)
test   %rbp,%rbp
js     11e1 <printFloat+0xd1>
xorps  %xmm0,%xmm0
cvtsi2ss %rbp,%xmm0
jmp    11f9 <printFloat+0xe9>
mov    0x2e10(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    1264 <printFloat+0x154>
mov    %rbp,%rdx
shr    %rdx
and    $0x1,%ebp
or     %rdx,%rbp
xorps  %xmm0,%xmm0
cvtsi2ss %rbp,%xmm0
addss  %xmm0,%xmm0
movaps (%rsp),%xmm1
subss  %xmm0,%xmm1
mulss  0xe0b(%rip),%xmm1
addss  0xe07(%rip),%xmm1
lea    (%r14,%rcx,1),%rdi
add    $0x1,%rdi
cvttss2si %xmm1,%rcx
sub    %eax,%r15d
mov    %rcx,%rax
sar    $0x3f,%rax
subss  0xde0(%rip),%xmm1
cvttss2si %xmm1,%rdx
and    %rax,%rdx
or     %rcx,%rdx
sub    $0x8,%rsp
lea    0xdd6(%rip),%r8
mov    %r15d,%esi
xor    %ecx,%ecx
xor    %r9d,%r9d
push   $0x0
push   $0x6
push   $0xffffffffffffffff
call   1030 <printDec@plt>
add    $0x20,%rsp
lea    (%r12,%rax,1),%ebx
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@E2BIG = global i32 0
@.str = [1 x i8] zeroinitializer
define i32 @printFloat(i8* %0, i32 %1, float %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store float %2, float* %7
store i32 0, i32* %8
%10 = load float, float* %7
%11 = fcmp olt float %10, 0.000000e+00
br i1 %11, label %12, label %29
12: ; preds = %3
br label %13
13: ; preds = %12
%14 = load i32, i32* %8
%15 = load i32, i32* %6
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @E2BIG
%19 = sub nsw i32 0, %18
store i32 %19, i32* %4
br label %82
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 45, i8* %25
br label %26
26: ; preds = %20
%27 = load float, float* %7
%28 = fneg float %27
store float %28, float* %7
br label %29
29: ; preds = %26, %3
%30 = load float, float* %7
%31 = fptoui float %30 to i64
store i64 %31, i64* %9
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %6
%37 = load i32, i32* %8
%38 = sub nsw i32 %36, %37
%39 = load i64, i64* %9
%40 = call i64 @printDec(i8* %35, i32 %38, i64 %39, i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1, i32 -1, i32 0)
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %8
br label %45
45: ; preds = %29
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* @E2BIG
%51 = sub nsw i32 0, %50
store i32 %51, i32* %4
br label %82
52: ; preds = %45
%53 = load i8*, i8** %5
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 46, i8* %57
br label %58
58: ; preds = %52
%59 = load float, float* %7
%60 = load i64, i64* %9
%61 = uitofp i64 %60 to float
%62 = fsub float %59, %61
%63 = fmul float %62, 1.000000e+06
%64 = fpext float %63 to double
%65 = fadd double %64, 5.000000e-01
%66 = fptrunc double %65 to float
store float %66, float* %7
%67 = load i8*, i8** %5
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i32, i32* %6
%72 = load i32, i32* %8
%73 = sub nsw i32 %71, %72
%74 = load float, float* %7
%75 = fptoui float %74 to i64
%76 = call i64 @printDec(i8* %70, i32 %73, i64 %75, i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1, i32 6, i32 0)
%77 = load i32, i32* %8
%78 = sext i32 %77 to i64
%79 = add nsw i64 %78, %76
%80 = trunc i64 %79 to i32
store i32 %80, i32* %8
%81 = load i32, i32* %8
store i32 %81, i32* %4
br label %82
82: ; preds = %58, %49, %17
%83 = load i32, i32* %4
ret i32 %83
}

LLVM IR (-O2):
@E2BIG = global i32 0
@.str = [1 x i8] zeroinitializer
define i32 @printFloat(i8* %0, i32 %1, float %2) {
%4 = fcmp olt float %2, 0.000000e+00
br i1 %4, label %5, label %12
5: ; preds = %3
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = load i32, i32* @E2BIG
%9 = sub nsw i32 0, %8
br label %41
10: ; preds = %5
store i8 45, i8* %0
%11 = fneg float %2
br label %12
12: ; preds = %10, %3
%13 = phi float [ %11, %10 ], [ %2, %3 ]
%14 = phi i32 [ 1, %10 ], [ 0, %3 ]
%15 = fptoui float %13 to i64
%16 = zext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = sub nsw i32 %1, %14
%19 = tail call i64 @printDec(i8* %17, i32 %18, i64 %15, i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1, i32 -1, i32 0)
%20 = trunc i64 %19 to i32
%21 = add i32 %14, %20
%22 = icmp eq i32 %21, %1
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* @E2BIG
%25 = sub nsw i32 0, %24
br label %41
26: ; preds = %12
%27 = add nsw i32 %21, 1
%28 = sext i32 %21 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 46, i8* %29
%30 = uitofp i64 %15 to float
%31 = fsub float %13, %30
%32 = fmul float %31, 1.000000e+06
%33 = fadd float %32, 5.000000e-01
%34 = sext i32 %27 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = sub nsw i32 %1, %27
%37 = fptoui float %33 to i64
%38 = tail call i64 @printDec(i8* %35, i32 %36, i64 %37, i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1, i32 6, i32 0)
%39 = trunc i64 %38 to i32
%40 = add i32 %27, %39
br label %41
41: ; preds = %23, %26, %7
%42 = phi i32 [ %9, %7 ], [ %25, %23 ], [ %40, %26 ]
ret i32 %42
}