#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 sscanf(char *, char *, double *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ReadFortranReal(char *line, int istart, int ilen, double *pdblval) {
  char chrtmp[1024], *chrpos;
  int istat, n;
  chrpos = strchr(line, '\0');
  if (chrpos - line < istart + ilen - 1)
    return (-1);
  strncpy(chrtmp, line + (istart - 1), ilen);
  chrtmp[ilen] = '\0';
  for (n = 0; n < ilen; n++) {
    if (chrtmp[n] != ' ')
      break;
  }
  if (n == ilen) {
    *pdblval = 0.0;
    return (1);
  }
  istat = sscanf(chrtmp, "%lf", pdblval);
  return (istat);
}


x86 assembly (clang, -O0):
<ReadFortranReal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    118a <ReadFortranReal+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <ReadFortranReal+0x11f>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1203 <ReadFortranReal+0xd3>
movslq -0x430(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
je     11ea <ReadFortranReal+0xba>
jmp    1203 <ReadFortranReal+0xd3>
jmp    11ef <ReadFortranReal+0xbf>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    11be <ReadFortranReal+0x8e>
mov    -0x430(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1229 <ReadFortranReal+0xf9>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    124f <ReadFortranReal+0x11f>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1050 <sscanf@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFortranReal>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rcx
lea    (%rbx,%r15,1),%eax
add    $0xffffffff,%eax
movslq %eax,%rdx
mov    $0xffffffff,%eax
cmp    %rdx,%rcx
jl     11c8 <ReadFortranReal+0x98>
add    $0xffffffff,%ebx
movslq %ebx,%rax
add    %rax,%r12
mov    %rsp,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,(%rsp,%rax,1)
test   %r15d,%r15d
jle    11a1 <ReadFortranReal+0x71>
mov    %r15d,%ecx
xor    %eax,%eax
nopl   (%rax)
cmpb   $0x20,(%rsp,%rax,1)
jne    11a3 <ReadFortranReal+0x73>
add    $0x1,%rax
cmp    %rax,%rcx
jne    1190 <ReadFortranReal+0x60>
jmp    11a8 <ReadFortranReal+0x78>
xor    %eax,%eax
cmp    %r15d,%eax
jne    11b6 <ReadFortranReal+0x86>
movq   $0x0,(%r14)
mov    $0x1,%eax
jmp    11c8 <ReadFortranReal+0x98>
lea    0xe43(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i32 @ReadFortranReal(i8* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double* %3, double** %9
%14 = load i8*, i8** %6
%15 = call i8* @strchr(i8* %14, i8 signext 0)
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = load i8*, i8** %6
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = add nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %20, %25
br i1 %26, label %27, label %28
27: ; preds = %4
store i32 -1, i32* %5
br label %67
28: ; preds = %4
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i32, i32* %8
%36 = call i32 @strncpy(i8* %29, i8* %34, i32 %35)
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %38
store i8 0, i8* %39
store i32 0, i32* %13
br label %40
40: ; preds = %53, %28
%41 = load i32, i32* %13
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 32
br i1 %50, label %51, label %52
51: ; preds = %44
br label %56
52: ; preds = %44
br label %53
53: ; preds = %52
%54 = load i32, i32* %13
%55 = add nsw i32 %54, 1
store i32 %55, i32* %13
br label %40
56: ; preds = %51, %40
%57 = load i32, i32* %13
%58 = load i32, i32* %8
%59 = icmp eq i32 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load double*, double** %9
store double 0.000000e+00, double* %61
store i32 1, i32* %5
br label %67
62: ; preds = %56
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%64 = load double*, double** %9
%65 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %64)
store i32 %65, i32* %12
%66 = load i32, i32* %12
store i32 %66, i32* %5
br label %67
67: ; preds = %62, %60, %27
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i32 @ReadFortranReal(i8* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add i32 %1, -1
%9 = add i32 %8, %2
%10 = sext i32 %9 to i64
%11 = icmp slt i64 %7, %10
br i1 %11, label %37, label %12
12: ; preds = %4
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = call i32 @strncpy(i8* %6, i8* %14, i32 %2)
%16 = sext i32 %2 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %17
%18 = icmp sgt i32 %2, 0
br i1 %18, label %19, label %31
19: ; preds = %12
%20 = zext i32 %2 to i64
br label %21
21: ; preds = %19, %26
%22 = phi i64 [ 0, %19 ], [ %27, %26 ]
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 32
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %20
br i1 %28, label %34, label %21
29: ; preds = %21
%30 = trunc i64 %22 to i32
br label %31
31: ; preds = %29, %12
%32 = phi i32 [ 0, %12 ], [ %30, %29 ]
%33 = icmp eq i32 %32, %2
br i1 %33, label %34, label %35
34: ; preds = %26, %31
store double 0.000000e+00, double* %3
br label %37
35: ; preds = %31
%36 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
br label %37
37: ; preds = %4, %35, %34
%38 = phi i32 [ 1, %34 ], [ %36, %35 ], [ -1, %4 ]
ret i32 %38
}