#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 */
char *mls(int, int);
double strtod(char *, char **);
int get_double(int m, int *p, double *d) {
  char *s = mls(m, *p);
  char *endp;
  *d = strtod(s, &endp);
  if (s == endp)
    return -1;
  *p += endp - s;
  return 0;
}


x86 assembly (clang, -O0):
<get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <mls@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1174 <get_double+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <get_double+0x72>
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
sub    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    (%rsi),%esi
call   1040 <mls@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%r15)
mov    0x8(%rsp),%rax
cmp    %rax,%rbx
je     115e <get_double+0x3e>
sub    %ebx,%eax
add    %eax,(%r14)
xor    %eax,%eax
jmp    1163 <get_double+0x43>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_double(i32 %0, i32* %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca double*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %5
store i32* %1, i32** %6
store double* %2, double** %7
%10 = load i32, i32* %5
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = call i8* @mls(i32 %10, i32 %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call double @strtod(i8* %14, i8** %9)
%16 = load double*, double** %7
store double %15, double* %16
%17 = load i8*, i8** %8
%18 = load i8*, i8** %9
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %32
21: ; preds = %3
%22 = load i8*, i8** %9
%23 = load i8*, i8** %8
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %26
%31 = trunc i64 %30 to i32
store i32 %31, i32* %27
store i32 0, i32* %4
br label %32
32: ; preds = %21, %20
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @get_double(i32 %0, i32* nocapture %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = load i32, i32* %1
%6 = tail call i8* @mls(i32 %0, i32 %5)
%7 = bitcast i8** %4 to i8*
%8 = call double @strtod(i8* %6, i8** %4)
store double %8, double* %2
%9 = load i8*, i8** %4
%10 = icmp eq i8* %6, %9
br i1 %10, label %18, label %11
11: ; preds = %3
%12 = ptrtoint i8* %9 to i64
%13 = ptrtoint i8* %6 to i64
%14 = sub i64 %12, %13
%15 = load i32, i32* %1
%16 = trunc i64 %14 to i32
%17 = add i32 %15, %16
store i32 %17, i32* %1
br label %18
18: ; preds = %3, %11
%19 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %19
}