#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 /*<<< orphan*/ FILE;

/* Variables and functions */
double NAN;
int fscanf(int /*<<< orphan*/ *, char *, char *);
int sscanf(char *, char *, double *);
char *strchr(char *, char);
double de_ascii_get_fortran_double(FILE *f) {
  char reals[100 + 1];
  if (fscanf(f, "%100s", reals) == 1) {
    char *Dptr = strchr(reals, 'D');
    if (Dptr) {
      *Dptr = 'e';
    }
    double val;
    if (sscanf(reals, "%lg", &val) == 1) {
      return val;
    }
  }
  return NAN;
}


x86 assembly (clang, -O0):
<de_ascii_get_fortran_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xeb2(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11c0 <de_ascii_get_fortran_double+0x90>
lea    -0x80(%rbp),%rdi
mov    $0x44,%esi
call   1030 <strchr@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1189 <de_ascii_get_fortran_double+0x59>
mov    -0x88(%rbp),%rax
movb   $0x65,(%rax)
lea    -0x80(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    -0x90(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11bb <de_ascii_get_fortran_double+0x8b>
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
jmp    11d0 <de_ascii_get_fortran_double+0xa0>
jmp    11c0 <de_ascii_get_fortran_double+0x90>
mov    0x2e31(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<de_ascii_get_fortran_double>:
sub    $0x78,%rsp
lea    0xec5(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1187 <de_ascii_get_fortran_double+0x57>
lea    0x10(%rsp),%rdi
mov    $0x44,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1161 <de_ascii_get_fortran_double+0x31>
movb   $0x65,(%rax)
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1187 <de_ascii_get_fortran_double+0x57>
movsd  0x8(%rsp),%xmm0
add    $0x78,%rsp
ret
mov    0x2e6a(%rip),%rax
movsd  (%rax),%xmm0
add    $0x78,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%100s\00"
@.str.1 = [4 x i8] c"%lg\00"
@NAN = global double 0.000000e+00
define double @de_ascii_get_fortran_double(i32* %0) {
%2 = alloca double
%3 = alloca i32*
%4 = alloca [101 x i8]
%5 = alloca i8*
%6 = alloca double
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%9 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %25
11: ; preds = %1
%12 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 68)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %5
store i8 101, i8* %17
br label %18
18: ; preds = %16, %11
%19 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %6)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load double, double* %6
store double %23, double* %2
br label %27
24: ; preds = %18
br label %25
25: ; preds = %24, %1
%26 = load double, double* @NAN
store double %26, double* %2
br label %27
27: ; preds = %25, %22
%28 = load double, double* %2
ret double %28
}

LLVM IR (-O2):
@.str = [6 x i8] c"%100s\00"
@.str.1 = [4 x i8] c"%lg\00"
@NAN = global double 0.000000e+00
define double @de_ascii_get_fortran_double(i32* nocapture %0) {
%2 = alloca [101 x i8]
%3 = alloca double
%4 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%5 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = call i8* @strchr(i8* %4, i8 signext 68)
%9 = icmp eq i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i8 101, i8* %8
br label %11
11: ; preds = %10, %7
%12 = bitcast double* %3 to i8*
%13 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%14 = icmp eq i32 %13, 1
%15 = load double, double* %3
br i1 %14, label %18, label %16
16: ; preds = %11, %1
%17 = load double, double* @NAN
br label %18
18: ; preds = %11, %16
%19 = phi double [ %17, %16 ], [ %15, %11 ]
ret double %19
}