#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 */
int /*<<< orphan*/ analyzeForDouble(char *, int, double *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ isprint(int);
char *malloc(int);
char *realloc(char *, int);
double getDouble(FILE *file) {
  int count = 0;
  int capacity = 10;
  char *expression = malloc(capacity);
  int c;
  while (isprint(c = fgetc(file))) {
    if (count >= capacity) {
      capacity *= 2;
      expression = realloc(expression, capacity);
    }
    expression[count++] = c;
  }
  expression[count] = '\0';
  double value;
  analyzeForDouble(expression, count, &value);
  free(expression);
  return value;
}


x86 assembly (clang, -O0):
<getDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xa,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    %edi,-0x1c(%rbp)
call   1080 <isprint@plt>
cmp    $0x0,%rax
je     11e7 <getDouble+0x87>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11c8 <getDouble+0x68>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1186 <getDouble+0x26>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1040 <analyzeForDouble@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDouble>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0xa,%r12d
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <isprint@plt>
xor    %ebx,%ebx
jmp    11b9 <getDouble+0x59>
nopw   0x0(%rax,%rax,1)
mov    %bpl,(%r15,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <isprint@plt>
test   %rax,%rax
je     11d9 <getDouble+0x79>
movslq %r12d,%rax
cmp    %rax,%rbx
jl     11a0 <getDouble+0x40>
add    %r12d,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
jmp    11a0 <getDouble+0x40>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <analyzeForDouble@plt>
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @getDouble(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 10, i32* %4
%8 = load i32, i32* %4
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %5
br label %10
10: ; preds = %25, %1
%11 = load i32*, i32** %2
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %6
%13 = call i64 @isprint(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 2
store i32 %21, i32* %4
%22 = load i8*, i8** %5
%23 = load i32, i32* %4
%24 = call i8* @realloc(i8* %22, i32 %23)
store i8* %24, i8** %5
br label %25
25: ; preds = %19, %15
%26 = load i32, i32* %6
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %5
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
br label %10
33: ; preds = %10
%34 = load i8*, i8** %5
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %5
%39 = load i32, i32* %3
%40 = call i32 @analyzeForDouble(i8* %38, i32 %39, double* %7)
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
%43 = load double, double* %7
ret double %43
}

LLVM IR (-O2):
define double @getDouble(i32* nocapture %0) {
%2 = alloca double
%3 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%4 = tail call i32 @fgetc(i32* %0)
%5 = tail call i64 @isprint(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %1, %17
%8 = phi i64 [ %21, %17 ], [ 0, %1 ]
%9 = phi i32 [ %23, %17 ], [ %4, %1 ]
%10 = phi i8* [ %19, %17 ], [ %3, %1 ]
%11 = phi i32 [ %18, %17 ], [ 10, %1 ]
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %8, %12
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = shl nsw i32 %11, 1
%16 = tail call i8* @realloc(i8* %10, i32 %15)
br label %17
17: ; preds = %14, %7
%18 = phi i32 [ %15, %14 ], [ %11, %7 ]
%19 = phi i8* [ %16, %14 ], [ %10, %7 ]
%20 = trunc i32 %9 to i8
%21 = add nuw i64 %8, 1
%22 = getelementptr inbounds i8, i8* %19, i64 %8
store i8 %20, i8* %22
%23 = tail call i32 @fgetc(i32* %0)
%24 = tail call i64 @isprint(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %7
26: ; preds = %17
%27 = trunc i64 %21 to i32
br label %28
28: ; preds = %26, %1
%29 = phi i8* [ %3, %1 ], [ %19, %26 ]
%30 = phi i32 [ 0, %1 ], [ %27, %26 ]
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = bitcast double* %2 to i8*
%34 = call i32 @analyzeForDouble(i8* %29, i32 %30, double* %2)
%35 = call i32 @free(i8* %29)
%36 = load double, double* %2
ret double %36
}