#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 */
int parse_special(char const *, double *);
int /*<<< orphan*/ rrd_set_error(char *, char const *, char const *, ...);
double rrd_strtod(char const *, char **);
unsigned int rrd_strtodbl(const char *str, char **endptr, double *dbl,
                          const char *error) {
  char *local_endptr = (char *)str;
  *dbl = rrd_strtod(str, &local_endptr);
  if (endptr)
    *endptr = local_endptr;
  if (local_endptr == (char *)str) {
    if (parse_special(str, dbl) == 2) {
      return 2;
    }
    if (error) {
      rrd_set_error("%s - Cannot convert '%s' to float", error, str);
    }
    return 0;
  } else if (local_endptr[0] != '\0') {
    if (error) {
      rrd_set_error("%s - Converted '%s' to %lf, but cannot convert '%s'",
                    error, str, *dbl, local_endptr);
    }
    return 1;
  } else if (local_endptr[0] == '\0') {
    return 2;
  } else {
    if (error) {
      rrd_set_error("%s - Internal error. Something is seriously wrong '%s'",
                    error, str);
    }
    return 3;
  }
}


x86 assembly (clang, -O0):
<rrd_strtodbl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <rrd_strtod@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     117b <rrd_strtodbl+0x4b>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11d8 <rrd_strtodbl+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <parse_special@plt>
cmp    $0x2,%eax
jne    11ab <rrd_strtodbl+0x7b>
movl   $0x2,-0x4(%rbp)
jmp    1265 <rrd_strtodbl+0x135>
cmpq   $0x0,-0x28(%rbp)
je     11cc <rrd_strtodbl+0x9c>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <rrd_set_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1265 <rrd_strtodbl+0x135>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1221 <rrd_strtodbl+0xf1>
cmpq   $0x0,-0x28(%rbp)
je     1215 <rrd_strtodbl+0xe5>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x30(%rbp),%rcx
lea    0xe14(%rip),%rdi
mov    $0x1,%al
call   1040 <rrd_set_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1265 <rrd_strtodbl+0x135>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    123d <rrd_strtodbl+0x10d>
movl   $0x2,-0x4(%rbp)
jmp    1265 <rrd_strtodbl+0x135>
cmpq   $0x0,-0x28(%rbp)
je     125e <rrd_strtodbl+0x12e>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <rrd_set_error@plt>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rrd_strtodbl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    %rsp,%rsi
call   1030 <rrd_strtod@plt>
movsd  %xmm0,(%r15)
mov    (%rsp),%rcx
test   %rbp,%rbp
je     1161 <rrd_strtodbl+0x31>
mov    %rcx,0x0(%rbp)
cmp    %rbx,%rcx
je     118b <rrd_strtodbl+0x5b>
cmpb   $0x0,(%rcx)
je     11bd <rrd_strtodbl+0x8d>
mov    $0x1,%ebp
test   %r14,%r14
je     11c6 <rrd_strtodbl+0x96>
lea    0xea6(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x1,%al
call   1040 <rrd_set_error@plt>
jmp    11c6 <rrd_strtodbl+0x96>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <parse_special@plt>
mov    $0x2,%ebp
cmp    $0x2,%eax
je     11c6 <rrd_strtodbl+0x96>
test   %r14,%r14
je     11c4 <rrd_strtodbl+0x94>
lea    0xe54(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <rrd_set_error@plt>
jmp    11c6 <rrd_strtodbl+0x96>
mov    $0x2,%ebp
jmp    11c6 <rrd_strtodbl+0x96>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"%s - Cannot convert '%s' to float\00"
@.str.1 = [52 x i8] c"%s - Converted '%s' to %lf, but cannot convert '%s'\00"
@.str.2 = [55 x i8] c"%s - Internal error. Something is seriously wrong '%s'\00"
define i32 @rrd_strtodbl(i8* %0, i8** %1, double* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca double*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store double* %2, double** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
store i8* %11, i8** %10
%12 = load i8*, i8** %6
%13 = call double @rrd_strtod(i8* %12, i8** %10)
%14 = load double*, double** %8
store double %13, double* %14
%15 = load i8**, i8*** %7
%16 = icmp ne i8** %15, null
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load i8*, i8** %10
%19 = load i8**, i8*** %7
store i8* %18, i8** %19
br label %20
20: ; preds = %17, %4
%21 = load i8*, i8** %10
%22 = load i8*, i8** %6
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = load double*, double** %8
%27 = call i32 @parse_special(i8* %25, double* %26)
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 2, i32* %5
br label %70
30: ; preds = %24
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8*, i8** %9
%35 = load i8*, i8** %6
%36 = call i32 (i8*, i8*, i8*, ...) @rrd_set_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %30
store i32 0, i32* %5
br label %70
38: ; preds = %20
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = load i8*, i8** %9
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i8*, i8** %9
%49 = load i8*, i8** %6
%50 = load double*, double** %8
%51 = load double, double* %50
%52 = load i8*, i8** %10
%53 = call i32 (i8*, i8*, i8*, ...) @rrd_set_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %48, i8* %49, double %51, i8* %52)
br label %54
54: ; preds = %47, %44
store i32 1, i32* %5
br label %70
55: ; preds = %38
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %55
store i32 2, i32* %5
br label %70
62: ; preds = %55
%63 = load i8*, i8** %9
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i8*, i8** %9
%67 = load i8*, i8** %6
%68 = call i32 (i8*, i8*, i8*, ...) @rrd_set_error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %66, i8* %67)
br label %69
69: ; preds = %65, %62
store i32 3, i32* %5
br label %70
70: ; preds = %69, %61, %54, %37, %29
%71 = load i32, i32* %5
ret i32 %71
}

LLVM IR (-O2):
@.str = [34 x i8] c"%s - Cannot convert '%s' to float\00"
@.str.1 = [52 x i8] c"%s - Converted '%s' to %lf, but cannot convert '%s'\00"
define i32 @rrd_strtodbl(i8* %0, i8** writeonly %1, double* %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* %0, i8** %5
%7 = call double @rrd_strtod(i8* %0, i8** %5)
store double %7, double* %2
%8 = icmp eq i8** %1, null
%9 = load i8*, i8** %5
br i1 %8, label %11, label %10
10: ; preds = %4
store i8* %9, i8** %1
br label %11
11: ; preds = %4, %10
%12 = icmp eq i8* %9, %0
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = call i32 @parse_special(i8* %0, double* %2)
%15 = icmp eq i32 %14, 2
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = icmp eq i8* %3, null
br i1 %17, label %27, label %18
18: ; preds = %16
%19 = call i32 (i8*, i8*, i8*, ...) @rrd_set_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %0)
br label %27
20: ; preds = %11
%21 = load i8, i8* %9
%22 = icmp eq i8 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = icmp eq i8* %3, null
br i1 %24, label %27, label %25
25: ; preds = %23
%26 = call i32 (i8*, i8*, i8*, ...) @rrd_set_error(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %0, double %7, i8* %9)
br label %27
27: ; preds = %20, %23, %25, %16, %18, %13
%28 = phi i32 [ 2, %13 ], [ 0, %18 ], [ 0, %16 ], [ 1, %25 ], [ 1, %23 ], [ 2, %20 ]
ret i32 %28
}