#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 */
double CHAR_MAX;
int errno;
int /*<<< orphan*/ free(char *);
char *getString(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, char *, char *);
double stringtod(char *);
double getDouble(void) {
  while (true) {
    char *line = getString(0);
    if (line == NULL) {
      errno = 1;
      return CHAR_MAX;
    }
    char *extract;
    double d;
    char c;
    extract = malloc(sizeof(double));
    if (sscanf(line, " %s %c", extract, &c) == 1) {
      d = stringtod(extract);
      free(line);
      return d;
    } else {
      free(line);
      printf("Retry: ");
    }
  }
}


x86 assembly (clang, -O0):
<getDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %edi,%edi
call   1030 <getString@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <getDouble+0x40>
mov    0x2e53(%rip),%rax
movl   $0x1,(%rax)
mov    0x2e56(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120f <getDouble+0xaf>
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
lea    -0x21(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11f5 <getDouble+0x95>
mov    -0x18(%rbp),%rdi
call   1060 <stringtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120f <getDouble+0xaf>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
jmp    1168 <getDouble+0x8>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDouble>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <getString@plt>
test   %rax,%rax
je     11d2 <getDouble+0x72>
mov    %rax,%r13
lea    0xe7d(%rip),%r14
lea    0x7(%rsp),%r15
lea    0xe78(%rip),%r12
nop
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11ec <getDouble+0x8c>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <getString@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1190 <getDouble+0x30>
mov    0x2dff(%rip),%rax
movl   $0x1,(%rax)
mov    0x2e02(%rip),%rax
movsd  (%rax),%xmm0
jmp    1208 <getDouble+0xa8>
mov    %rbx,%rdi
call   1060 <stringtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
call   1040 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@CHAR_MAX = global double 0.000000e+00
@.str = [7 x i8] c" %s %c\00"
@.str.1 = [8 x i8] c"Retry: \00"
define double @getDouble() {
%1 = alloca double
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
%5 = alloca i8
br label %6
6: ; preds = %0, %28
%7 = call i8* @getString(i32 0)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
store i32 1, i32* @errno
%11 = load double, double* @CHAR_MAX
store double %11, double* %1
br label %29
12: ; preds = %6
%13 = call i8* @malloc(i32 8)
store i8* %13, i8** %3
%14 = load i8*, i8** %2
%15 = load i8*, i8** %3
%16 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %5)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = call double @stringtod(i8* %19)
store double %20, double* %4
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
%23 = load double, double* %4
store double %23, double* %1
br label %29
24: ; preds = %12
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %24
br label %6
29: ; preds = %18, %10
%30 = load double, double* %1
ret double %30
}

LLVM IR (-O2):
@errno = global i32 0
@CHAR_MAX = global double 0.000000e+00
@.str = [7 x i8] c" %s %c\00"
@.str.1 = [8 x i8] c"Retry: \00"
define double @getDouble() {
%1 = alloca i8
%2 = call i8* @getString(i32 0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %14, %0
store i32 1, i32* @errno
%5 = load double, double* @CHAR_MAX
br label %19
6: ; preds = %0, %14
%7 = phi i8* [ %17, %14 ], [ %2, %0 ]
%8 = call dereferenceable_or_null(8) i8* @malloc(i32 8)
%9 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call double @stringtod(i8* %8)
%13 = call i32 @free(i8* %7)
br label %19
14: ; preds = %6
%15 = call i32 @free(i8* %7)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = call i8* @getString(i32 0)
%18 = icmp eq i8* %17, null
br i1 %18, label %4, label %6
19: ; preds = %11, %4
%20 = phi double [ %5, %4 ], [ %12, %11 ]
ret double %20
}