#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_int(int);
int /*<<< orphan*/ putch(long);
void print_double(double x, int p) {
  long d;
  if (x < 0) {
    putch('-');
    x = -x;
  }
  d = x;
  print_int((int)d);
  putch('.');
  while (p--) {
    x = (x - d) * 10;
    d = x;
    putch('0' + d);
  }
}


x86 assembly (clang, -O0):
<print_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1169 <print_double+0x49>
mov    $0x2d,%edi
call   1040 <putch@plt>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1030 <print_int@plt>
mov    $0x2e,%edi
call   1040 <putch@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11d8 <print_double+0xb8>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe4d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x30,%rdi
call   1040 <putch@plt>
jmp    1188 <print_double+0x68>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_double>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    114e <print_double+0x2e>
mov    $0x2d,%edi
movapd %xmm0,(%rsp)
call   1040 <putch@plt>
movapd (%rsp),%xmm0
xorpd  0xeb2(%rip),%xmm0
movapd %xmm0,(%rsp)
cvttsd2si %xmm0,%rbx
mov    %ebx,%edi
call   1030 <print_int@plt>
mov    $0x2e,%edi
call   1040 <putch@plt>
test   %ebp,%ebp
je     11a1 <print_double+0x81>
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movapd (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe87(%rip),%xmm1
movapd %xmm1,(%rsp)
cvttsd2si %xmm1,%rbx
lea    0x30(%rbx),%rdi
call   1040 <putch@plt>
add    $0xffffffff,%ebp
jne    1170 <print_double+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @print_double(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i64
store double %0, double* %3
store i32 %1, i32* %4
%6 = load double, double* %3
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @putch(i64 45)
%10 = load double, double* %3
%11 = fneg double %10
store double %11, double* %3
br label %12
12: ; preds = %8, %2
%13 = load double, double* %3
%14 = fptosi double %13 to i64
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = trunc i64 %15 to i32
%17 = call i32 @print_int(i32 %16)
%18 = call i32 @putch(i64 46)
br label %19
19: ; preds = %23, %12
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
%22 = icmp ne i32 %20, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load double, double* %3
%25 = load i64, i64* %5
%26 = sitofp i64 %25 to double
%27 = fsub double %24, %26
%28 = fmul double %27, 1.000000e+01
store double %28, double* %3
%29 = load double, double* %3
%30 = fptosi double %29 to i64
store i64 %30, i64* %5
%31 = load i64, i64* %5
%32 = add nsw i64 48, %31
%33 = call i32 @putch(i64 %32)
br label %19
34: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @print_double(double %0, i32 %1) {
%3 = fcmp olt double %0, 0.000000e+00
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @putch(i64 45)
%6 = fneg double %0
br label %7
7: ; preds = %4, %2
%8 = phi double [ %6, %4 ], [ %0, %2 ]
%9 = fptosi double %8 to i64
%10 = trunc i64 %9 to i32
%11 = tail call i32 @print_int(i32 %10)
%12 = tail call i32 @putch(i64 46)
%13 = icmp eq i32 %1, 0
br i1 %13, label %26, label %14
14: ; preds = %7, %14
%15 = phi i64 [ %22, %14 ], [ %9, %7 ]
%16 = phi i32 [ %18, %14 ], [ %1, %7 ]
%17 = phi double [ %21, %14 ], [ %8, %7 ]
%18 = add nsw i32 %16, -1
%19 = sitofp i64 %15 to double
%20 = fsub double %17, %19
%21 = fmul double %20, 1.000000e+01
%22 = fptosi double %21 to i64
%23 = add nsw i64 %22, 48
%24 = tail call i32 @putch(i64 %23)
%25 = icmp eq i32 %18, 0
br i1 %25, label %26, label %14
26: ; preds = %14, %7
ret void
}