#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 *calloc(int, int);
double fetch_parameter(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ read_gcode_integer(char const *);
char *skip_gcode_digits(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
double strtod(char *, char **);
double read_gcode_real(const char *line) {
  if (line[0] == '#')
    return fetch_parameter(read_gcode_integer(&line[1]));
  else {
    char *theNumber;
    const char *endPtr;
    double result;
    endPtr = skip_gcode_digits(line);
    theNumber = calloc(endPtr - line + 1, 1);
    strncpy(theNumber, line, endPtr - line);
    result = strtod(theNumber, (char **)NULL);
    free(theNumber);
    return result;
  }
}


x86 assembly (clang, -O0):
<read_gcode_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11aa <read_gcode_real+0x3a>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1070 <read_gcode_integer@plt>
mov    %eax,%edi
call   1050 <fetch_parameter@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1215 <read_gcode_real+0xa5>
mov    -0x10(%rbp),%rdi
call   1090 <skip_gcode_digits@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_gcode_real>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
cmpb   $0x23,(%rdi)
jne    119d <read_gcode_real+0x2d>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <read_gcode_integer@plt>
mov    %eax,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fetch_parameter@plt>
mov    %rbx,%rdi
call   1090 <skip_gcode_digits@plt>
mov    %rax,%r14
sub    %ebx,%r14d
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @read_gcode_real(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca double
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 35
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 @read_gcode_integer(i8* %14)
%16 = call double @fetch_parameter(i32 %15)
store double %16, double* %2
br label %42
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i8* @skip_gcode_digits(i8* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = add nsw i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @calloc(i32 %26, i32 1)
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = load i8*, i8** %3
%30 = load i8*, i8** %5
%31 = load i8*, i8** %3
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i32 @strncpy(i8* %28, i8* %29, i32 %35)
%37 = load i8*, i8** %4
%38 = call double @strtod(i8* %37, i8** null)
store double %38, double* %6
%39 = load i8*, i8** %4
%40 = call i32 @free(i8* %39)
%41 = load double, double* %6
store double %41, double* %2
br label %42
42: ; preds = %17, %12
%43 = load double, double* %2
ret double %43
}

LLVM IR (-O2):
define double @read_gcode_real(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 35
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i32 @read_gcode_integer(i8* %5)
%7 = tail call double @fetch_parameter(i32 %6)
br label %19
8: ; preds = %1
%9 = tail call i8* @skip_gcode_digits(i8* %0)
%10 = ptrtoint i8* %9 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = add i32 %13, 1
%15 = tail call i8* @calloc(i32 %14, i32 1)
%16 = tail call i32 @strncpy(i8* %15, i8* %0, i32 %13)
%17 = tail call double @strtod(i8* nocapture %15, i8** null)
%18 = tail call i32 @free(i8* %15)
br label %19
19: ; preds = %8, %4
%20 = phi double [ %7, %4 ], [ %17, %8 ]
ret double %20
}