#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
double strtod(char *, char **);
int ijs_server_parse_float(const char *value, int size, double *result) {
  char buf[256];
  char *tail;
  if (size + 1 > sizeof(buf))
    return -12;
  memcpy(buf, value, size);
  buf[size] = 0;
  *result = strtod(buf, &tail);
  if (tail == buf)
    return -7;
  return 0;
}


x86 assembly (clang, -O0):
<ijs_server_parse_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
cmp    $0x100,%rax
jbe    1156 <ijs_server_parse_float+0x36>
movl   $0xfffffff4,-0x4(%rbp)
jmp    11ba <ijs_server_parse_float+0x9a>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
lea    -0x128(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x128(%rbp),%rax
lea    -0x120(%rbp),%rcx
cmp    %rcx,%rax
jne    11b3 <ijs_server_parse_float+0x93>
movl   $0xfffffff9,-0x4(%rbp)
jmp    11ba <ijs_server_parse_float+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ijs_server_parse_float>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%ebx
lea    -0x100(%rbx),%ecx
mov    $0xfffffff4,%eax
cmp    $0xfffffeff,%ecx
jb     117f <ijs_server_parse_float+0x5f>
mov    %rdx,%r14
mov    %rdi,%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%r14)
xor    %ecx,%ecx
cmp    %r15,0x8(%rsp)
mov    $0xfffffff9,%eax
cmovne %ecx,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @ijs_server_parse_float(i8* %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
%8 = add i32 %1, -256
%9 = icmp ult i32 %8, -257
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = call i32 @memcpy(i8* %6, i8* %0, i32 %1)
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %12
store i8 0, i8* %13
%14 = call double @strtod(i8* %6, i8** %5)
store double %14, double* %2
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, %6
%17 = select i1 %16, i32 -7, i32 0
br label %18
18: ; preds = %10, %3
%19 = phi i32 [ -12, %3 ], [ %17, %10 ]
ret i32 %19
}