#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 */
double fabs(double);
scalar_t__ floor(double);
scalar_t__ xprintf_print_integer(char **, int, int, int, int, int, char, int);
int /*<<< orphan*/ xprintf_putchar(char **, int);
int xprintf_print_float(char **out, double d, int width, int pad, int width_dec,
                        int pad_dec) {
  int pad_count = 0;
  int neg = (d < 0.0f);
  pad_count += xprintf_print_integer(out, (int)d, 10, 1, width, pad, 'a', neg);
  if (neg)
    d = -d;
  d -= (int)floor(d);
  if ((!(pad_dec | (1 << 0))) && (fabs(d) < 0.00000000000001)) {
    return pad_count;
  } else {
    if (width_dec == 0)
      width_dec = 8;
    xprintf_putchar(out, '.');
    while (width_dec--) {
      d = d * (double)10.0f;
      xprintf_putchar(out, '0' + ((int)floor(d)));
      d -= (int)floor(d);
    }
  }
  return pad_count;
}


x86 assembly (clang, -O0):
<xprintf_print_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
cvttsd2si -0x18(%rbp),%esi
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    $0xa,%edx
mov    $0x1,%ecx
movl   $0x61,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <xprintf_print_integer@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11ce <xprintf_print_float+0x9e>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%eax
or     $0x1,%eax
cmp    $0x0,%eax
jne    1226 <xprintf_print_float+0xf6>
movsd  -0x18(%rbp),%xmm1
movaps 0xe0b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1226 <xprintf_print_float+0xf6>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b7 <xprintf_print_float+0x187>
cmpl   $0x0,-0x24(%rbp)
jne    1237 <xprintf_print_float+0x107>
movl   $0x8,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <xprintf_putchar@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     12ac <xprintf_print_float+0x17c>
movsd  0xda7(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
add    $0x30,%esi
call   1050 <xprintf_putchar@plt>
movsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1245 <xprintf_print_float+0x115>
jmp    12b1 <xprintf_print_float+0x181>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xprintf_print_float>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r15d
mov    %edx,%r9d
mov    %esi,%r8d
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
cvttsd2si %xmm0,%esi
mov    %eax,0x8(%rsp)
movl   $0x61,(%rsp)
jbe    116c <xprintf_print_float+0x3c>
xorpd  0xe94(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    $0xa,%edx
mov    $0x1,%ecx
call   1030 <xprintf_print_integer@plt>
mov    %rax,%r14
movaps 0x10(%rsp),%xmm0
call   1040 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <xprintf_putchar@plt>
test   %r15d,%r15d
mov    $0x8,%ebp
cmovne %r15d,%ebp
movapd 0x10(%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
mulsd  0xe38(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
call   1040 <floor@plt>
lea    0x30(%rax),%esi
mov    %rbx,%rdi
call   1050 <xprintf_putchar@plt>
movaps 0x10(%rsp),%xmm0
call   1040 <floor@plt>
movapd 0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
add    $0xffffffff,%ebp
jne    11d0 <xprintf_print_float+0xa0>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @xprintf_print_float(i8** %0, double %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8** %0, i8*** %8
store double %1, double* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %14
%16 = load double, double* %9
%17 = fcmp olt double %16, 0.000000e+00
%18 = zext i1 %17 to i32
store i32 %18, i32* %15
%19 = load i8**, i8*** %8
%20 = load double, double* %9
%21 = fptosi double %20 to i32
%22 = load i32, i32* %10
%23 = load i32, i32* %11
%24 = load i32, i32* %15
%25 = call i64 @xprintf_print_integer(i8** %19, i32 %21, i32 10, i32 1, i32 %22, i32 %23, i8 signext 97, i32 %24)
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %14
%30 = load i32, i32* %15
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %6
%33 = load double, double* %9
%34 = fneg double %33
store double %34, double* %9
br label %35
35: ; preds = %32, %6
%36 = load double, double* %9
%37 = call i64 @floor(double %36)
%38 = trunc i64 %37 to i32
%39 = sitofp i32 %38 to double
%40 = load double, double* %9
%41 = fsub double %40, %39
store double %41, double* %9
%42 = load i32, i32* %13
%43 = or i32 %42, 1
%44 = icmp ne i32 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %35
%46 = load double, double* %9
%47 = call double @llvm.fabs.f64(double %46)
%48 = fcmp olt double %47, 0x3D06849B86A12B9B
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32, i32* %14
store i32 %50, i32* %7
br label %80
51: ; preds = %45, %35
%52 = load i32, i32* %12
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 8, i32* %12
br label %55
55: ; preds = %54, %51
%56 = load i8**, i8*** %8
%57 = call i32 @xprintf_putchar(i8** %56, i32 46)
br label %58
58: ; preds = %62, %55
%59 = load i32, i32* %12
%60 = add nsw i32 %59, -1
store i32 %60, i32* %12
%61 = icmp ne i32 %59, 0
br i1 %61, label %62, label %77
62: ; preds = %58
%63 = load double, double* %9
%64 = fmul double %63, 1.000000e+01
store double %64, double* %9
%65 = load i8**, i8*** %8
%66 = load double, double* %9
%67 = call i64 @floor(double %66)
%68 = trunc i64 %67 to i32
%69 = add nsw i32 48, %68
%70 = call i32 @xprintf_putchar(i8** %65, i32 %69)
%71 = load double, double* %9
%72 = call i64 @floor(double %71)
%73 = trunc i64 %72 to i32
%74 = sitofp i32 %73 to double
%75 = load double, double* %9
%76 = fsub double %75, %74
store double %76, double* %9
br label %58
77: ; preds = %58
br label %78
78: ; preds = %77
%79 = load i32, i32* %14
store i32 %79, i32* %7
br label %80
80: ; preds = %78, %49
%81 = load i32, i32* %7
ret i32 %81
}

LLVM IR (-O2):
define i32 @xprintf_print_float(i8** %0, double %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = fcmp olt double %1, 0.000000e+00
%8 = zext i1 %7 to i32
%9 = fptosi double %1 to i32
%10 = tail call i64 @xprintf_print_integer(i8** %0, i32 %9, i32 10, i32 1, i32 %2, i32 %3, i8 signext 97, i32 %8)
%11 = fneg double %1
%12 = select i1 %7, double %11, double %1
%13 = tail call i64 @floor(double %12)
%14 = trunc i64 %13 to i32
%15 = sitofp i32 %14 to double
%16 = fsub double %12, %15
%17 = icmp eq i32 %4, 0
%18 = tail call i32 @xprintf_putchar(i8** %0, i32 46)
%19 = select i1 %17, i32 8, i32 %4
br label %20
20: ; preds = %6, %20
%21 = phi double [ %16, %6 ], [ %32, %20 ]
%22 = phi i32 [ %19, %6 ], [ %23, %20 ]
%23 = add nsw i32 %22, -1
%24 = fmul double %21, 1.000000e+01
%25 = tail call i64 @floor(double %24)
%26 = trunc i64 %25 to i32
%27 = add nsw i32 %26, 48
%28 = tail call i32 @xprintf_putchar(i8** %0, i32 %27)
%29 = tail call i64 @floor(double %24)
%30 = trunc i64 %29 to i32
%31 = sitofp i32 %30 to double
%32 = fsub double %24, %31
%33 = icmp eq i32 %23, 0
br i1 %33, label %34, label %20
34: ; preds = %20
%35 = trunc i64 %10 to i32
ret i32 %35
}