#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 */
scalar_t__ isdigit(char const);
double strtod(char const *, int /*<<< orphan*/ *);
double getNumber(const char *str) {
  while (*str && !(isdigit(*str) ||
                   ((*str == '-' || *str == '+') && isdigit(*(str + 1))))) {
    str++;
  }
  return strtod(str, NULL);
}


x86 assembly (clang, -O0):
<getNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
je     11a9 <getNumber+0x89>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xa(%rbp)
jne    11a1 <getNumber+0x81>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1184 <getNumber+0x64>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2b,%ecx
mov    %al,-0xb(%rbp)
jne    119b <getNumber+0x7b>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
xor    $0xff,%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11b9 <getNumber+0x99>
jmp    11ca <getNumber+0xaa>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <getNumber+0xc>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumber>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%al
jmp    1146 <getNumber+0x26>
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1164 <getNumber+0x44>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1164 <getNumber+0x44>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1164 <getNumber+0x44>
movzbl (%rbx),%eax
cmp    $0x2d,%al
je     1130 <getNumber+0x10>
cmp    $0x2b,%al
je     1130 <getNumber+0x10>
jmp    113e <getNumber+0x1e>
mov    %rbx,%rdi
xor    %esi,%esi
pop    %rbx
jmp    1040 <strtod@plt>

LLVM IR (-O0):
define double @getNumber(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %36, %1
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %3
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 43
br i1 %22, label %23, label %29
23: ; preds = %18, %13
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = call i64 @isdigit(i8 signext %26)
%28 = icmp ne i64 %27, 0
br label %29
29: ; preds = %23, %18
%30 = phi i1 [ false, %18 ], [ %28, %23 ]
br label %31
31: ; preds = %29, %8
%32 = phi i1 [ true, %8 ], [ %30, %29 ]
%33 = xor i1 %32, true
br label %34
34: ; preds = %31, %3
%35 = phi i1 [ false, %3 ], [ %33, %31 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %2
br label %3
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = call double @strtod(i8* %40, i32* null)
ret double %41
}

LLVM IR (-O2):
define double @getNumber(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %18, %16 ], [ %2, %1 ]
%6 = phi i8* [ %17, %16 ], [ %0, %1 ]
%7 = tail call i64 @isdigit(i8 signext %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %4
%10 = load i8, i8* %6
switch i8 %10, label %16 [
i8 45, label %11
i8 43, label %11
]
11: ; preds = %9, %9
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = load i8, i8* %12
%14 = tail call i64 @isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9, %11
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %11, %16, %4, %1
%21 = phi i8* [ %0, %1 ], [ %6, %4 ], [ %17, %16 ], [ %6, %11 ]
%22 = tail call double @strtod(i8* nocapture %21, i32* null)
ret double %22
}