#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 NAN;
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strlen(char const *);
double strtod(char *, int /*<<< orphan*/ *);
double __nan(const char *tagp) {
  if (tagp[0] != '\0') {
    char buf[6 + strlen(tagp)];
    sprintf(buf, "NAN(%s)", tagp);
    return strtod(buf, NULL);
  }
  return NAN;
}


x86 assembly (clang, -O0):
<__nan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a9 <__nan+0x79>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x6,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe7a(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    11b9 <__nan+0x89>
mov    0x2e48(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__nan>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     117f <__nan+0x4f>
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rsp,%r15
add    $0x6,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
mov    %r15,%rsp
jmp    118a <__nan+0x5a>
mov    0x2e72(%rip),%rax
movsd  (%rax),%xmm0
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"NAN(%s)\00"
@NAN = global double 0.000000e+00
define double @__nan(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 6, %13
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = alloca i8, i64 %15
store i64 %15, i64* %5
%18 = load i8*, i8** %3
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call double @strtod(i8* %17, i32* null)
store double %20, double* %2
%21 = load i8*, i8** %4
br label %24
22: ; preds = %1
%23 = load double, double* @NAN
store double %23, double* %2
br label %24
24: ; preds = %22, %11
%25 = load double, double* %2
ret double %25
}

LLVM IR (-O2):
@.str = [8 x i8] c"NAN(%s)\00"
@NAN = global double 0.000000e+00
define double @__nan(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 6
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call double @strtod(i8* nocapture %9, i32* null)
tail call void @llvm.stackrestore(i8* %8)
br label %14
12: ; preds = %1
%13 = load double, double* @NAN
br label %14
14: ; preds = %12, %4
%15 = phi double [ %11, %4 ], [ %13, %12 ]
ret double %15
}