#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*/ print_decimal(int);
int /*<<< orphan*/ print_decimal_n(int, int);
int /*<<< orphan*/ putc(char);
void print_float(double val) {
  int ip, fp, sg;
  sg = 0;
  if (val < 0) {
    val = -val;
    sg = 1;
  }
  ip = (int)val;
  fp = (int)((val - ip) * 1000000);
  if (sg)
    putc('-');
  print_decimal(ip);
  putc('.');
  print_decimal_n(fp, 6);
}


x86 assembly (clang, -O0):
<print_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    117a <print_float+0x4a>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe68(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b7 <print_float+0x87>
mov    $0x2d,%edi
call   1030 <putc@plt>
mov    -0xc(%rbp),%edi
call   1040 <print_decimal@plt>
mov    $0x2e,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%edi
mov    $0x6,%esi
call   1050 <print_decimal_n@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_float>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movapd 0xeba(%rip),%xmm2
xorpd  %xmm0,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm0,%xmm3
orpd   %xmm2,%xmm3
cvttsd2si %xmm3,%ebx
jbe    1179 <print_float+0x49>
mov    $0x2d,%edi
movapd %xmm3,(%rsp)
call   1030 <putc@plt>
movapd (%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
subsd  %xmm0,%xmm3
mulsd  0xe84(%rip),%xmm3
cvttsd2si %xmm3,%ebp
mov    %ebx,%edi
call   1040 <print_decimal@plt>
mov    $0x2e,%edi
call   1030 <putc@plt>
mov    %ebp,%edi
mov    $0x6,%esi
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <print_decimal_n@plt>

LLVM IR (-O0):
define void @print_float(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store double %0, double* %2
store i32 0, i32* %5
%6 = load double, double* %2
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load double, double* %2
%10 = fneg double %9
store double %10, double* %2
store i32 1, i32* %5
br label %11
11: ; preds = %8, %1
%12 = load double, double* %2
%13 = fptosi double %12 to i32
store i32 %13, i32* %3
%14 = load double, double* %2
%15 = load i32, i32* %3
%16 = sitofp i32 %15 to double
%17 = fsub double %14, %16
%18 = fmul double %17, 1.000000e+06
%19 = fptosi double %18 to i32
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @putc(i8 signext 45)
br label %24
24: ; preds = %22, %11
%25 = load i32, i32* %3
%26 = call i32 @print_decimal(i32 %25)
%27 = call i32 @putc(i8 signext 46)
%28 = load i32, i32* %4
%29 = call i32 @print_decimal_n(i32 %28, i32 6)
ret void
}

LLVM IR (-O2):
define void @print_float(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = fptosi double %4 to i32
br i1 %2, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @putc(i8 signext 45)
br label %8
8: ; preds = %6, %1
%9 = sitofp i32 %5 to double
%10 = fsub double %4, %9
%11 = fmul double %10, 1.000000e+06
%12 = fptosi double %11 to i32
%13 = tail call i32 @print_decimal(i32 %5)
%14 = tail call i32 @putc(i8 signext 46)
%15 = tail call i32 @print_decimal_n(i32 %12, i32 6)
ret void
}