#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);
double strtod(char *, int /*<<< orphan*/ *);
double unsafe_numeric_eater(char *str) {
  size_t position = 0;
  while (str[position] != '\0') {
    if (isdigit(str[position])) {
      position++;
      continue;
    }
    if (str[position] == ',')
      str[position] = '.';
    break;
  }
  return strtod(str, NULL);
}


x86 assembly (clang, -O0):
<unsafe_numeric_eater>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119b <unsafe_numeric_eater+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1175 <unsafe_numeric_eater+0x55>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <unsafe_numeric_eater+0x14>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    1196 <unsafe_numeric_eater+0x76>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
jmp    119b <unsafe_numeric_eater+0x7b>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsafe_numeric_eater>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     1153 <unsafe_numeric_eater+0x33>
mov    %r14,%rbx
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     114b <unsafe_numeric_eater+0x2b>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <unsafe_numeric_eater+0x10>
jmp    1153 <unsafe_numeric_eater+0x33>
cmpb   $0x2c,(%rbx)
jne    1153 <unsafe_numeric_eater+0x33>
movb   $0x2e,(%rbx)
mov    %r14,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strtod@plt>

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

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