#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ fstr;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, long double);
int sprintf(char *, char *, int);
long double strtold(char *, int /*<<< orphan*/ *);
int test_strtold(void) {
  char buf[300];
  int cnt;
  int result = 0;
  for (cnt = 0; cnt < 200; ++cnt) {
    ssize_t n;
    long double f;
    n = sprintf(buf, "%d", cnt);
    memset(buf + n, '0', cnt);
    sprintf(buf + n + cnt, ".000e-%d", cnt);
    f = strtold(buf, NULL);
    if (f != (long double)cnt) {
      char fstr[128];
      char fcntstr[128];
      snprintf(fstr, sizeof(fstr),
               "%"
               "L"
               "g",
               f);
      snprintf(fcntstr, sizeof(fstr),
               "%"
               "L"
               "g",
               (long double)cnt);
      printf("strto"
             "ld"
             "(\"%s\") "
             "failed for cnt == %d (%s instead of %s)\n",
             buf, cnt, fstr, fcntstr);
      result = 1;
    } else
      printf("strto"
             "ld"
             "() fine for cnt == %d\n",
             cnt);
  }
  return result;
}


x86 assembly (clang, -O0):
<test_strtold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x138(%rbp)
movl   $0x0,-0x134(%rbp)
cmpl   $0xc8,-0x134(%rbp)
jge    12e7 <test_strtold+0x197>
mov    -0x134(%rbp),%edx
lea    0xe7a(%rip),%rsi
lea    -0x130(%rbp),%rdi
mov    %rdi,-0x260(%rbp)
call   1070 <sprintf@plt>
mov    %eax,-0x13c(%rbp)
movslq -0x13c(%rbp),%rax
lea    -0x130(%rbp,%rax,1),%rdi
ff
mov    -0x134(%rbp),%edx
mov    $0x30,%esi
call   1050 <memset@plt>
movslq -0x13c(%rbp),%rax
lea    -0x130(%rbp,%rax,1),%rdi
ff
movslq -0x134(%rbp),%rax
mov    %eax,%edx
add    %rax,%rdi
lea    0xe1a(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x260(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <strtold@plt>
fstpt  -0x150(%rbp)
fldt   -0x150(%rbp)
mov    -0x134(%rbp),%eax
mov    %eax,-0x254(%rbp)
fildl  -0x254(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1230 <test_strtold+0xe0>
jp     1230 <test_strtold+0xe0>
jmp    12ba <test_strtold+0x16a>
fldt   -0x150(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xdc7(%rip),%rdx
lea    -0x1d0(%rbp),%rdi
mov    $0x80,%esi
call   1040 <snprintf@plt>
lea    -0x250(%rbp),%rdi
mov    -0x134(%rbp),%eax
mov    %eax,-0x258(%rbp)
fildl  -0x258(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xd91(%rip),%rdx
mov    $0x80,%esi
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rsi
mov    -0x134(%rbp),%edx
lea    -0x1d0(%rbp),%rcx
lea    -0x250(%rbp),%r8
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x138(%rbp)
jmp    12ce <test_strtold+0x17e>
mov    -0x134(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d3 <test_strtold+0x183>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    116f <test_strtold+0x1f>
mov    -0x138(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strtold>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x258,%rsp
lea    0x20(%rsp),%r13
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    1196 <test_strtold+0x46>
xchg   %ax,%ax
fstp   %st(0)
fstp   %st(0)
lea    0xec9(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r14
cmp    $0xc8,%r14
je     1263 <test_strtold+0x113>
mov    %r13,%rdi
lea    0xe66(%rip),%rsi
mov    %r14d,%edx
call   1070 <sprintf@plt>
movslq %eax,%r12
lea    (%rsp,%r12,1),%rdi
add    $0x20,%rdi
mov    $0x30,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
add    %r14,%r12
lea    (%rsp,%r12,1),%rdi
add    $0x20,%rdi
lea    0xe2e(%rip),%rsi
mov    %r14d,%edx
call   1070 <sprintf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <strtold@plt>
mov    %r14d,0x10(%rsp)
fildl  0x10(%rsp)
fxch   %st(1)
fucomi %st(1),%st
jne    11f9 <test_strtold+0xa9>
jnp    1170 <test_strtold+0x20>
fstpt  (%rsp)
lea    0x1d0(%rsp),%r15
mov    %r15,%rdi
mov    $0x80,%esi
lea    0xdf6(%rip),%rbp
mov    %rbp,%rdx
fstpt  0x14(%rsp)
call   1040 <snprintf@plt>
fldt   0x14(%rsp)
fstpt  (%rsp)
lea    0x150(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1040 <snprintf@plt>
lea    0xdc8(%rip),%rdi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r15d
jmp    1185 <test_strtold+0x35>
mov    %r15d,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c".000e-%d\00"
@.str.2 = [4 x i8] c"%Lg\00"
@.str.3 = [55 x i8] c"strtold(\22%s\22) failed for cnt == %d (%s instead of %s)\0A\00"
@.str.4 = [30 x i8] c"strtold() fine for cnt == %d\0A\00"
define i32 @test_strtold() {
%1 = alloca [300 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca x86_fp80
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 0, i32* %2
br label %8
8: ; preds = %53, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 200
br i1 %10, label %11, label %56
11: ; preds = %8
%12 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%13 = load i32, i32* %2
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %2
%20 = call i32 @memset(i8* %18, i32 48, i32 %19)
%21 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %2
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%31 = call x86_fp80 @strtold(i8* %30, i32* null)
store x86_fp80 %31, x86_fp80* %5
%32 = load x86_fp80, x86_fp80* %5
%33 = load i32, i32* %2
%34 = sitofp i32 %33 to x86_fp80
%35 = fcmp une x86_fp80 %32, %34
br i1 %35, label %36, label %49
36: ; preds = %11
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%38 = load x86_fp80, x86_fp80* %5
%39 = call i32 @snprintf(i8* %37, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %38)
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %2
%42 = sitofp i32 %41 to x86_fp80
%43 = call i32 @snprintf(i8* %40, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %42)
%44 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%45 = load i32, i32* %2
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45, i8* %46, i8* %47)
store i32 1, i32* %3
br label %52
49: ; preds = %11
%50 = load i32, i32* %2
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %36
br label %53
53: ; preds = %52
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %8
56: ; preds = %8
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c".000e-%d\00"
@.str.2 = [4 x i8] c"%Lg\00"
@.str.3 = [55 x i8] c"strtold(\22%s\22) failed for cnt == %d (%s instead of %s)\0A\00"
@.str.4 = [30 x i8] c"strtold() fine for cnt == %d\0A\00"
define i32 @test_strtold() {
%1 = alloca [300 x i8]
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %0, %26
%8 = phi i64 [ 0, %0 ], [ %28, %26 ]
%9 = phi i32 [ 0, %0 ], [ %27, %26 ]
%10 = trunc i64 %8 to i32
%11 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %12
%14 = call i32 @memset(i8* %13, i32 48, i32 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %8
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%17 = call x86_fp80 @strtold(i8* nocapture %4, i32* null)
%18 = sitofp i32 %10 to x86_fp80
%19 = fcmp une x86_fp80 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %7
%21 = call i32 @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %17)
%22 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), x86_fp80 %18)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %10, i8* %5, i8* %6)
br label %26
24: ; preds = %7
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %10)
br label %26
26: ; preds = %24, %20
%27 = phi i32 [ 1, %20 ], [ %9, %24 ]
%28 = add nuw nsw i64 %8, 1
%29 = icmp eq i64 %28, 200
br i1 %29, label %30, label %7
30: ; preds = %26
ret i32 %27
}