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


x86 assembly (clang, -O0):
<__nanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a9 <__nanf+0x79>
mov    -0x10(%rbp),%rdi
call   1030 <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   1040 <strtof@plt>
movss  %xmm0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    11b9 <__nanf+0x89>
mov    0x2e48(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__nanf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     117f <__nanf+0x4f>
mov    %rdi,%r14
call   1030 <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   1040 <strtof@plt>
mov    %r15,%rsp
jmp    118a <__nanf+0x5a>
mov    0x2e72(%rip),%rax
movss  (%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 float 0.000000e+00
define float @__nanf(i8* %0) {
%2 = alloca float
%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 float @strtof(i8* %17, i32* null)
store float %20, float* %2
%21 = load i8*, i8** %4
br label %24
22: ; preds = %1
%23 = load float, float* @NAN
store float %23, float* %2
br label %24
24: ; preds = %22, %11
%25 = load float, float* %2
ret float %25
}

LLVM IR (-O2):
@.str = [8 x i8] c"NAN(%s)\00"
@NAN = global float 0.000000e+00
define float @__nanf(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 float @strtof(i8* nocapture %9, i32* null)
tail call void @llvm.stackrestore(i8* %8)
br label %14
12: ; preds = %1
%13 = load float, float* @NAN
br label %14
14: ; preds = %12, %4
%15 = phi float [ %11, %4 ], [ %13, %12 ]
ret float %15
}