#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 atof(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ json_getNumber(char const *, int const, int *);
scalar_t__ json_util_allocSubstring(char const *, int const, int, char **);
int json_number_toDouble(const char *input_string,
                         const int input_string_startIndex,
                         double *output_double) {
  int endIndex;
  if (json_getNumber(input_string, input_string_startIndex, &endIndex) != 0) {
    return -1;
  }
  char *string;
  if (json_util_allocSubstring(input_string, input_string_startIndex, endIndex,
                               &string) != 0) {
    return -1;
  }
  *output_double = atof(string);
  free(string);
  return 0;
}


x86 assembly (clang, -O0):
<json_number_toDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x24(%rbp),%rdx
call   1050 <json_getNumber@plt>
cmp    $0x0,%rax
je     1179 <json_number_toDouble+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <json_number_toDouble+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1060 <json_util_allocSubstring@plt>
cmp    $0x0,%rax
je     11a2 <json_number_toDouble+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <json_number_toDouble+0x83>
mov    -0x30(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_number_toDouble>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x4(%rsp),%rdx
call   1050 <json_getNumber@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11a3 <json_number_toDouble+0x63>
mov    0x4(%rsp),%edx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <json_util_allocSubstring@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11a3 <json_number_toDouble+0x63>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @json_number_toDouble(i8* %0, i32 %1, double* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store double* %2, double** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i64 @json_getNumber(i8* %10, i32 %11, i32* %8)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %28
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %8
%19 = call i64 @json_util_allocSubstring(i8* %16, i32 %17, i32 %18, i8** %9)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %4
br label %28
22: ; preds = %15
%23 = load i8*, i8** %9
%24 = call double @atof(i8* %23)
%25 = load double*, double** %7
store double %24, double* %25
%26 = load i8*, i8** %9
%27 = call i32 @free(i8* %26)
store i32 0, i32* %4
br label %28
28: ; preds = %22, %21, %14
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @json_number_toDouble(i8* %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @json_getNumber(i8* %0, i32 %1, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = bitcast i8** %5 to i8*
%11 = load i32, i32* %4
%12 = call i64 @json_util_allocSubstring(i8* %0, i32 %1, i32 %11, i8** %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = call double @atof(i8* %15)
store double %16, double* %2
%17 = call i32 @free(i8* %15)
br label %18
18: ; preds = %9, %14
%19 = phi i32 [ 0, %14 ], [ -1, %9 ]
br label %20
20: ; preds = %3, %18
%21 = phi i32 [ %19, %18 ], [ -1, %3 ]
ret i32 %21
}