#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*/ free(char *);
int /*<<< orphan*/ get_input(char *, int);
char *malloc(int);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int strlen(char *);
double get_input_double(int *error) {
  char *input = malloc(sizeof(char) * 32);
  get_input(input, 32);
  if (error != NULL) {
    int i = 0, len = strlen(input);
    *error = 0;
    for (i = 0; i < len; i++) {
      if ((*(input + i) >= '0' && *(input + i) <= '9') || *(input + i) == '.' ||
          *(input + i) == '-') {
        continue;
      }
      *error = i + 1;
      break;
    }
  }
  double result = 0;
  sscanf(input, "%lf", &result);
  free(input);
  return result;
}


x86 assembly (clang, -O0):
<get_input_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1070 <get_input@plt>
cmpq   $0x0,-0x8(%rbp)
je     1230 <get_input_double+0xe0>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    122b <get_input_double+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     11dd <get_input_double+0x8d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jle    1207 <get_input_double+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1207 <get_input_double+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    120c <get_input_double+0xbc>
jmp    121d <get_input_double+0xcd>
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    122b <get_input_double+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <get_input_double+0x57>
jmp    1230 <get_input_double+0xe0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdbd(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_double>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x20,%esi
call   1070 <get_input@plt>
test   %r14,%r14
je     11b4 <get_input_double+0x64>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movl   $0x0,(%r14)
test   %eax,%eax
jle    11b4 <get_input_double+0x64>
mov    %eax,%ecx
xor    %eax,%eax
jmp    1199 <get_input_double+0x49>
nop
add    $0x1,%rax
cmp    %rax,%rcx
je     11b4 <get_input_double+0x64>
movzbl (%rbx,%rax,1),%edx
lea    -0x30(%rdx),%esi
cmp    $0xa,%sil
jb     1190 <get_input_double+0x40>
add    $0xd3,%dl
cmp    $0x2,%dl
jb     1190 <get_input_double+0x40>
add    $0x1,%eax
mov    %eax,(%r14)
movq   $0x0,(%rsp)
lea    0xe3d(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define double @get_input_double(i32* writeonly %0) {
%2 = alloca double
%3 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%4 = tail call i32 @get_input(i8* %3, i32 32)
%5 = icmp eq i32* %0, null
br i1 %5, label %26, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %3)
store i32 0, i32* %0
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %23
%12 = phi i64 [ 0, %9 ], [ %24, %23 ]
%13 = getelementptr inbounds i8, i8* %3, i64 %12
%14 = load i8, i8* %13
%15 = add i8 %14, -48
%16 = icmp ult i8 %15, 10
%17 = add i8 %14, -45
%18 = icmp ult i8 %17, 2
%19 = or i1 %16, %18
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = trunc i64 %12 to i32
%22 = add nuw nsw i32 %21, 1
store i32 %22, i32* %0
br label %26
23: ; preds = %11
%24 = add nuw nsw i64 %12, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %11
26: ; preds = %23, %6, %20, %1
%27 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%28 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %2)
%29 = call i32 @free(i8* %3)
%30 = load double, double* %2
ret double %30
}