#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 strtod(char const *, char **);
int parseDouble(const char *s, double *x) {
  char *end;
  double dval = strtod(s, &end);
  if (end == s || (*end != '\0' && *end != ',')) {
    return -1;
  }
  *x = dval;
  return 0;
}


x86 assembly (clang, -O0):
<parseDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1160 <parseDouble+0x50>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116c <parseDouble+0x5c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     116c <parseDouble+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <parseDouble+0x70>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseDouble>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    (%rsp),%rcx
mov    $0xffffffff,%eax
cmp    %rbx,%rcx
je     1142 <parseDouble+0x32>
mov    (%rcx),%cl
cmp    $0x2c,%cl
je     113b <parseDouble+0x2b>
test   %cl,%cl
jne    1142 <parseDouble+0x32>
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @parseDouble(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8, i8* %6
switch i8 %9, label %11 [
i8 0, label %10
i8 44, label %10
]
10: ; preds = %8, %8
store double %5, double* %1
br label %11
11: ; preds = %2, %8, %10
%12 = phi i32 [ 0, %10 ], [ -1, %8 ], [ -1, %2 ]
ret i32 %12
}