#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 sprintf(char *, char *, ...);
int Printfloat8(char *s, double d) {
  int k;
  void *D = &d;
  unsigned int lod, hid;
  lod = ((unsigned int *)D)[0];
  hid = ((unsigned int *)D)[1];
  if (lod == 0 && hid == 0x7F800000L)
    k = sprintf(s, "+INF 7F800000 00000000");
  else if (lod == 0 && hid == 0xFF800000L)
    k = sprintf(s, "-INF FF800000 00000000");
  else if ((hid & 0xFFF00000L) == 0x7FF00000)
    k = sprintf(s,
                "+NAN "
                "0x%08x"
                " "
                "0x%08x",
                hid, lod);
  else if ((hid & 0xFFF00000L) == 0xFFF00000)
    k = sprintf(s,
                "-NAN "
                "0x%08x"
                " "
                "0x%08x",
                hid, lod);
  else if (d == 0.0)
    k = sprintf(s, "0.0");
  else
    k = sprintf(s, "%#.16lg", d);
  return k;
}


x86 assembly (clang, -O0):
<Printfloat8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    116f <Printfloat8+0x5f>
mov    -0x28(%rbp),%eax
cmp    $0x7f800000,%rax
jne    116f <Printfloat8+0x5f>
mov    -0x8(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    127e <Printfloat8+0x16e>
cmpl   $0x0,-0x24(%rbp)
jne    11a4 <Printfloat8+0x94>
mov    -0x28(%rbp),%eax
mov    $0xff800000,%ecx
cmp    %rcx,%rax
jne    11a4 <Printfloat8+0x94>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1279 <Printfloat8+0x169>
mov    -0x28(%rbp),%eax
movabs $0xfff00000,%rcx
and    %rcx,%rax
cmp    $0x7ff00000,%rax
jne    11e0 <Printfloat8+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1274 <Printfloat8+0x164>
mov    -0x28(%rbp),%eax
movabs $0xfff00000,%rcx
and    %rcx,%rax
mov    $0xfff00000,%ecx
cmp    %rcx,%rax
jne    121e <Printfloat8+0x10e>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    126f <Printfloat8+0x15f>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1250 <Printfloat8+0x140>
jp     1250 <Printfloat8+0x140>
mov    -0x8(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    126a <Printfloat8+0x15a>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xdf8(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    126f <Printfloat8+0x15f>
jmp    1274 <Printfloat8+0x164>
jmp    1279 <Printfloat8+0x169>
jmp    127e <Printfloat8+0x16e>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Printfloat8>:
movq   %xmm0,%rcx
mov    %rcx,%rdx
shr    $0x20,%rdx
test   %ecx,%ecx
jne    1131 <Printfloat8+0x21>
cmp    $0x7f800000,%edx
jne    1131 <Printfloat8+0x21>
movups 0xed1(%rip),%xmm0
jmp    1144 <Printfloat8+0x34>
test   %ecx,%ecx
jne    115b <Printfloat8+0x4b>
cmp    $0xff800000,%edx
jne    115b <Printfloat8+0x4b>
movups 0xed3(%rip),%xmm0
movups %xmm0,(%rdi)
movabs $0x30303030303030,%rax
mov    %rax,0xf(%rdi)
mov    $0x16,%eax
ret
mov    %edx,%eax
and    $0xfff00000,%eax
cmp    $0xfff00000,%eax
je     117e <Printfloat8+0x6e>
cmp    $0x7ff00000,%eax
jne    118c <Printfloat8+0x7c>
lea    0xeb7(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xebc(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a4 <Printfloat8+0x94>
jp     11a4 <Printfloat8+0x94>
movl   $0x302e30,(%rdi)
mov    $0x3,%eax
ret
lea    0xea9(%rip),%rsi
mov    $0x1,%al
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"+INF 7F800000 00000000\00"
@.str.1 = [23 x i8] c"-INF FF800000 00000000\00"
@.str.2 = [19 x i8] c"+NAN 0x%08x 0x%08x\00"
@.str.3 = [19 x i8] c"-NAN 0x%08x 0x%08x\00"
@.str.4 = [4 x i8] c"0.0\00"
@.str.5 = [8 x i8] c"%#.16lg\00"
define i32 @Printfloat8(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store double %1, double* %4
%9 = bitcast double* %4 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = bitcast i8* %10 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
store i32 %13, i32* %7
%14 = load i8*, i8** %6
%15 = bitcast i8* %14 to i32*
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
store i32 %17, i32* %8
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %2
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = icmp eq i64 %22, 2139095040
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 %26, i32* %5
br label %71
27: ; preds = %20, %2
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %8
%32 = zext i32 %31 to i64
%33 = icmp eq i64 %32, 4286578688
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i8*, i8** %3
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 %36, i32* %5
br label %70
37: ; preds = %30, %27
%38 = load i32, i32* %8
%39 = zext i32 %38 to i64
%40 = and i64 %39, 4293918720
%41 = icmp eq i64 %40, 2146435072
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %3
%44 = load i32, i32* %8
%45 = load i32, i32* %7
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45)
store i32 %46, i32* %5
br label %69
47: ; preds = %37
%48 = load i32, i32* %8
%49 = zext i32 %48 to i64
%50 = and i64 %49, 4293918720
%51 = icmp eq i64 %50, 4293918720
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load i8*, i8** %3
%54 = load i32, i32* %8
%55 = load i32, i32* %7
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %55)
store i32 %56, i32* %5
br label %68
57: ; preds = %47
%58 = load double, double* %4
%59 = fcmp oeq double %58, 0.000000e+00
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i8*, i8** %3
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32 %62, i32* %5
br label %67
63: ; preds = %57
%64 = load i8*, i8** %3
%65 = load double, double* %4
%66 = call i32 (i8*, i8*, ...) @sprintf(i8* %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %65)
store i32 %66, i32* %5
br label %67
67: ; preds = %63, %60
br label %68
68: ; preds = %67, %52
br label %69
69: ; preds = %68, %42
br label %70
70: ; preds = %69, %34
br label %71
71: ; preds = %70, %24
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
@.str = [23 x i8] c"+INF 7F800000 00000000\00"
@.str.1 = [23 x i8] c"-INF FF800000 00000000\00"
@.str.2 = [19 x i8] c"+NAN 0x%08x 0x%08x\00"
@.str.3 = [19 x i8] c"-NAN 0x%08x 0x%08x\00"
@.str.5 = [8 x i8] c"%#.16lg\00"
define i32 @Printfloat8(i8* nocapture writeonly %0, double %1) {
%3 = bitcast double %1 to i64
%4 = trunc i64 %3 to i32
%5 = lshr i64 %3, 32
%6 = trunc i64 %5 to i32
%7 = icmp eq i32 %4, 0
%8 = icmp eq i64 %5, 2139095040
%9 = and i1 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(23) %0, i8* align 1 dereferenceable(23) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 23, i1 false)
br label %27
11: ; preds = %2
%12 = icmp eq i64 %5, 4286578688
%13 = and i1 %7, %12
br i1 %13, label %14, label %15
14: ; preds = %11
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(23) %0, i8* align 1 dereferenceable(23) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 23, i1 false)
br label %27
15: ; preds = %11
%16 = and i32 %6, -1048576
switch i32 %16, label %21 [
i32 2146435072, label %17
i32 -1048576, label %19
]
17: ; preds = %15
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %4)
br label %27
19: ; preds = %15
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %4)
br label %27
21: ; preds = %15
%22 = fcmp oeq double %1, 0.000000e+00
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = bitcast i8* %0 to i32*
store i32 3157552, i32* %24
br label %27
25: ; preds = %21
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %1)
br label %27
27: ; preds = %14, %19, %25, %23, %17, %10
%28 = phi i32 [ 22, %10 ], [ 22, %14 ], [ %18, %17 ], [ %20, %19 ], [ 3, %23 ], [ %26, %25 ]
ret i32 %28
}