#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, double,
                           ...);
char *grisu3_parse_double(char *, int, double *);
int grisu3_print_double(double, char *);
int /*<<< orphan*/ isinf(double);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
void check_double(double x1, double x2, char *id, int line, int *fail) {
  char tmp[50];
  const char *k;
  int n;
  int failed = 0;
  double v;
  if (x1 != x2) {
    failed = 1;
    fprintf(stderr, "%d: fail (%s): %.17g != %.17g\n", line, id, x1, x2);
  } else {
    n = grisu3_print_double(x1, tmp);
    if (n >= 30) {
      failed = 1;
      fprintf(stderr,
              "%d: fail (%s): print length exceeded max: %d, input: %.17g\n",
              line, id, n, x1);
    } else if ((int)strlen(tmp) != n) {
      failed = 1;
      fprintf(stderr,
              "%d: fail (%s): print length does not match strlen of output, "
              "input: %.17g, got: %s\n",
              line, id, x1, tmp);
    } else if (!isinf(x1)) {
      k = grisu3_parse_double(tmp, n, &v);
      if (k == 0 || k == tmp) {
        failed = 1;
        fprintf(stderr,
                "%d: fail (%s): roundtrip parse failed "
                "input: %g, printed value %s\n",
                line, id, x1, tmp);
      } else if (x1 != v) {
        failed = 1;
        fprintf(stderr,
                "%d: fail (%s): print/parse roundtrip mismatch for "
                "input: %.17g, got %.17g\n",
                line, id, x1, v);
      }
    }
  }
  *fail += failed;
}


x86 assembly (clang, -O0):
<check_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
movl   $0x0,-0x70(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1192 <check_double+0x42>
jp     1192 <check_double+0x42>
jmp    11c6 <check_double+0x76>
movl   $0x1,-0x70(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe46(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
jmp    1333 <check_double+0x1e3>
movsd  -0x8(%rbp),%xmm0
lea    -0x60(%rbp),%rdi
call   1060 <grisu3_print_double@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x1e,-0x6c(%rbp)
jl     1215 <check_double+0xc5>
movl   $0x1,-0x70(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
cvtsi2sdl -0x6c(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
lea    0xe16(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
jmp    132e <check_double+0x1de>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x6c(%rbp),%eax
je     125a <check_double+0x10a>
movl   $0x1,-0x70(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
movsd  -0x8(%rbp),%xmm0
lea    -0x60(%rbp),%r8
lea    0xe0d(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    1329 <check_double+0x1d9>
movsd  -0x8(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%eax
jne    1324 <check_double+0x1d4>
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
lea    -0x78(%rbp),%rdx
call   1050 <grisu3_parse_double@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     129d <check_double+0x14d>
mov    -0x68(%rbp),%rax
lea    -0x60(%rbp),%rcx
cmp    %rcx,%rax
jne    12d0 <check_double+0x180>
movl   $0x1,-0x70(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
movsd  -0x8(%rbp),%xmm0
lea    -0x60(%rbp),%r8
lea    0xdeb(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    131f <check_double+0x1cf>
movsd  -0x8(%rbp),%xmm0
ucomisd -0x78(%rbp),%xmm0
jne    12eb <check_double+0x19b>
jp     12eb <check_double+0x19b>
jmp    131a <check_double+0x1ca>
movl   $0x1,-0x70(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
movsd  -0x8(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm1
lea    0xddf(%rip),%rsi
mov    $0x2,%al
call   1040 <fprintf@plt>
jmp    131f <check_double+0x1cf>
jmp    1324 <check_double+0x1d4>
jmp    1329 <check_double+0x1d9>
jmp    132e <check_double+0x1de>
jmp    1333 <check_double+0x1e3>
mov    -0x70(%rbp),%ecx
mov    -0x28(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%r15
ucomisd %xmm1,%xmm0
jne    116f <check_double+0x1f>
jnp    1187 <check_double+0x37>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %r13d,%edx
mov    %r15,%rcx
jmp    11bf <check_double+0x6f>
lea    0x10(%rsp),%rdi
movsd  %xmm0,(%rsp)
call   1060 <grisu3_print_double@plt>
mov    %eax,%ebx
cmp    $0x1e,%eax
jl     11dd <check_double+0x8d>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
lea    0xe6b(%rip),%rsi
mov    %r13d,%edx
mov    %r15,%rcx
movsd  (%rsp),%xmm1
mov    $0x2,%al
call   1040 <fprintf@plt>
mov    $0x1,%ebp
add    %ebp,(%r14)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jne    123f <check_double+0xef>
movsd  (%rsp),%xmm0
call   1070 <isinf@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11cb <check_double+0x7b>
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <grisu3_parse_double@plt>
test   %rax,%rax
je     126b <check_double+0x11b>
cmp    %r12,%rax
je     126b <check_double+0x11b>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
ucomisd %xmm0,%xmm1
jne    122a <check_double+0xda>
jnp    11cb <check_double+0x7b>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
jmp    117f <check_double+0x2f>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
lea    0x10(%rsp),%r8
mov    %r13d,%edx
mov    %r15,%rcx
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11c6 <check_double+0x76>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
jmp    124f <check_double+0xff>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"%d: fail (%s): %.17g != %.17g\0A\00"
@.str.1 = [60 x i8] c"%d: fail (%s): print length exceeded max: %d, input: %.17g\0A\00"
@.str.2 = [84 x i8] c"%d: fail (%s): print length does not match strlen of output, input: %.17g, got: %s\0A\00"
@.str.3 = [67 x i8] c"%d: fail (%s): roundtrip parse failed input: %g, printed value %s\0A\00"
@.str.4 = [75 x i8] c"%d: fail (%s): print/parse roundtrip mismatch for input: %.17g, got %.17g\0A\00"
define void @check_double(double %0, double %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [50 x i8]
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store double %0, double* %6
store double %1, double* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
store i32 0, i32* %14
%16 = load double, double* %6
%17 = load double, double* %7
%18 = fcmp une double %16, %17
br i1 %18, label %19, label %26
19: ; preds = %5
store i32 1, i32* %14
%20 = load i32, i32* @stderr
%21 = load i32, i32* %9
%22 = load i8*, i8** %8
%23 = load double, double* %6
%24 = load double, double* %7
%25 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %22, double %23, double %24)
br label %90
26: ; preds = %5
%27 = load double, double* %6
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%29 = call i32 @grisu3_print_double(double %27, i8* %28)
store i32 %29, i32* %13
%30 = load i32, i32* %13
%31 = icmp sge i32 %30, 30
br i1 %31, label %32, label %40
32: ; preds = %26
store i32 1, i32* %14
%33 = load i32, i32* @stderr
%34 = load i32, i32* %9
%35 = load i8*, i8** %8
%36 = load i32, i32* %13
%37 = sitofp i32 %36 to double
%38 = load double, double* %6
%39 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* %35, double %37, double %38)
br label %89
40: ; preds = %26
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = trunc i64 %42 to i32
%44 = load i32, i32* %13
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %53
46: ; preds = %40
store i32 1, i32* %14
%47 = load i32, i32* @stderr
%48 = load i32, i32* %9
%49 = load i8*, i8** %8
%50 = load double, double* %6
%51 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%52 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i32 %48, i8* %49, double %50, i8* %51)
br label %88
53: ; preds = %40
%54 = load double, double* %6
%55 = call i32 @isinf(double %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %87, label %57
57: ; preds = %53
%58 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%59 = load i32, i32* %13
%60 = call i8* @grisu3_parse_double(i8* %58, i32 %59, double* %15)
store i8* %60, i8** %12
%61 = load i8*, i8** %12
%62 = icmp eq i8* %61, null
br i1 %62, label %67, label %63
63: ; preds = %57
%64 = load i8*, i8** %12
%65 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%66 = icmp eq i8* %64, %65
br i1 %66, label %67, label %74
67: ; preds = %63, %57
store i32 1, i32* %14
%68 = load i32, i32* @stderr
%69 = load i32, i32* %9
%70 = load i8*, i8** %8
%71 = load double, double* %6
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%73 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %69, i8* %70, double %71, i8* %72)
br label %86
74: ; preds = %63
%75 = load double, double* %6
%76 = load double, double* %15
%77 = fcmp une double %75, %76
br i1 %77, label %78, label %85
78: ; preds = %74
store i32 1, i32* %14
%79 = load i32, i32* @stderr
%80 = load i32, i32* %9
%81 = load i8*, i8** %8
%82 = load double, double* %6
%83 = load double, double* %15
%84 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %80, i8* %81, double %82, double %83)
br label %85
85: ; preds = %78, %74
br label %86
86: ; preds = %85, %67
br label %87
87: ; preds = %86, %53
br label %88
88: ; preds = %87, %46
br label %89
89: ; preds = %88, %32
br label %90
90: ; preds = %89, %19
%91 = load i32, i32* %14
%92 = load i32*, i32** %10
%93 = load i32, i32* %92
%94 = add nsw i32 %93, %91
store i32 %94, i32* %92
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"%d: fail (%s): %.17g != %.17g\0A\00"
@.str.1 = [60 x i8] c"%d: fail (%s): print length exceeded max: %d, input: %.17g\0A\00"
@.str.2 = [84 x i8] c"%d: fail (%s): print length does not match strlen of output, input: %.17g, got: %s\0A\00"
@.str.3 = [67 x i8] c"%d: fail (%s): roundtrip parse failed input: %g, printed value %s\0A\00"
@.str.4 = [75 x i8] c"%d: fail (%s): print/parse roundtrip mismatch for input: %.17g, got %.17g\0A\00"
define void @check_double(double %0, double %1, i8* %2, i32 %3, i32* nocapture %4) {
%6 = alloca [50 x i8]
%7 = alloca double
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%9 = bitcast double* %7 to i8*
%10 = fcmp une double %0, %1
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2, double %0, double %1)
br label %45
14: ; preds = %5
%15 = call i32 @grisu3_print_double(double %0, i8* %8)
%16 = icmp sgt i32 %15, 29
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = sitofp i32 %15 to double
%20 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %3, i8* %2, double %19, double %0)
br label %45
21: ; preds = %14
%22 = call i64 @strlen(i8* %8)
%23 = trunc i64 %22 to i32
%24 = icmp eq i32 %15, %23
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i32 %3, i8* %2, double %0, i8* %8)
br label %45
28: ; preds = %21
%29 = call i32 @isinf(double %0)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = call i8* @grisu3_parse_double(i8* %8, i32 %15, double* %7)
%33 = icmp eq i8* %32, null
%34 = icmp eq i8* %32, %8
%35 = or i1 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %3, i8* %2, double %0, i8* %8)
br label %45
39: ; preds = %31
%40 = load double, double* %7
%41 = fcmp une double %40, %0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, i32, i8*, double, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %3, i8* %2, double %0, double %40)
br label %45
45: ; preds = %17, %28, %39, %42, %36, %25, %11
%46 = phi i32 [ 1, %11 ], [ 1, %17 ], [ 1, %25 ], [ 0, %28 ], [ 1, %36 ], [ 1, %42 ], [ 0, %39 ]
%47 = load i32, i32* %4
%48 = add nsw i32 %47, %46
store i32 %48, i32* %4
ret void
}