#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;
  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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1160 <Printfloat8+0x50>
mov    -0x1c(%rbp),%eax
cmp    $0x7f800000,%rax
jne    1160 <Printfloat8+0x50>
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    126f <Printfloat8+0x15f>
cmpl   $0x0,-0x18(%rbp)
jne    1195 <Printfloat8+0x85>
mov    -0x1c(%rbp),%eax
mov    $0xff800000,%ecx
cmp    %rcx,%rax
jne    1195 <Printfloat8+0x85>
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    126a <Printfloat8+0x15a>
mov    -0x1c(%rbp),%eax
movabs $0xfff00000,%rcx
and    %rcx,%rax
cmp    $0x7ff00000,%rax
jne    11d1 <Printfloat8+0xc1>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1265 <Printfloat8+0x155>
mov    -0x1c(%rbp),%eax
movabs $0xfff00000,%rcx
and    %rcx,%rax
mov    $0xfff00000,%ecx
cmp    %rcx,%rax
jne    120f <Printfloat8+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1260 <Printfloat8+0x150>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1241 <Printfloat8+0x131>
jp     1241 <Printfloat8+0x131>
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    125b <Printfloat8+0x14b>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe07(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1260 <Printfloat8+0x150>
jmp    1265 <Printfloat8+0x155>
jmp    126a <Printfloat8+0x15a>
jmp    126f <Printfloat8+0x15f>
mov    -0x14(%rbp),%eax
add    $0x20,%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 i32
%7 = alloca i32
store i8* %0, i8** %3
store double %1, double* %4
%8 = bitcast double* %4 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 0
%10 = load i32, i32* %9
store i32 %10, i32* %6
%11 = bitcast double* %4 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
store i32 %13, i32* %7
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = icmp eq i64 %18, 2139095040
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %5
br label %67
23: ; preds = %16, %2
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = icmp eq i64 %28, 4286578688
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %3
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 %32, i32* %5
br label %66
33: ; preds = %26, %23
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = and i64 %35, 4293918720
%37 = icmp eq i64 %36, 2146435072
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %41)
store i32 %42, i32* %5
br label %65
43: ; preds = %33
%44 = load i32, i32* %7
%45 = zext i32 %44 to i64
%46 = and i64 %45, 4293918720
%47 = icmp eq i64 %46, 4293918720
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = load i8*, i8** %3
%50 = load i32, i32* %7
%51 = load i32, i32* %6
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51)
store i32 %52, i32* %5
br label %64
53: ; preds = %43
%54 = load double, double* %4
%55 = fcmp oeq double %54, 0.000000e+00
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %3
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32 %58, i32* %5
br label %63
59: ; preds = %53
%60 = load i8*, i8** %3
%61 = load double, double* %4
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %61)
store i32 %62, i32* %5
br label %63
63: ; preds = %59, %56
br label %64
64: ; preds = %63, %48
br label %65
65: ; preds = %64, %38
br label %66
66: ; preds = %65, %30
br label %67
67: ; preds = %66, %20
%68 = load i32, i32* %5
ret i32 %68
}

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
}