#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ isspace(char);
int /*<<< orphan*/ stderr;
double strtod(char const *, char **);
double parse_double_optional_fraction(const char *input, double fallback,
                                      char **end) {
  const char *full_expr = input;
  double value = strtod(input, end);
  if (*end == input)
    return fallback;
  for (;;) {
    while (isspace(**end))
      ++*end;
    const char op = **end;
    if (op != '/' && op != '*') {
      return value;
    }
    ++*end;
    while (isspace(**end))
      ++*end;
    input = *end;
    double operand;
    if (*input == '(') {
      operand = parse_double_optional_fraction(input + 1, 1.0, end);
      if (**end != ')') {
        fprintf(stderr, "Mismatching parenthesis in '%s'\n", full_expr);
        return fallback;
      } else {
        ++*end;
      }
    } else {
      operand = strtod(input, end);
    }
    if (*end == input)
      return fallback;
    if (op == '/')
      value /= operand;
    else if (op == '*')
      value *= operand;
  }
  return value;
}


x86 assembly (clang, -O0):
<parse_double_optional_fraction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jne    118f <parse_double_optional_fraction+0x4f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1338 <parse_double_optional_fraction+0x1f8>
jmp    1194 <parse_double_optional_fraction+0x54>
jmp    1199 <parse_double_optional_fraction+0x59>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11c5 <parse_double_optional_fraction+0x85>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1199 <parse_double_optional_fraction+0x59>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x2f,%eax
je     11fa <parse_double_optional_fraction+0xba>
movsbl -0x31(%rbp),%eax
cmp    $0x2a,%eax
je     11fa <parse_double_optional_fraction+0xba>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1338 <parse_double_optional_fraction+0x1f8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1234 <parse_double_optional_fraction+0xf4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1208 <parse_double_optional_fraction+0xc8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    12bb <parse_double_optional_fraction+0x17b>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
movsd  0xd9d(%rip),%xmm0
call   1040 <parse_double_optional_fraction@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     12a8 <parse_double_optional_fraction+0x168>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd74(%rip),%rsi
call   1060 <fprintf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1338 <parse_double_optional_fraction+0x1f8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    12cd <parse_double_optional_fraction+0x18d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jne    12ed <parse_double_optional_fraction+0x1ad>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1338 <parse_double_optional_fraction+0x1f8>
movsbl -0x31(%rbp),%eax
cmp    $0x2f,%eax
jne    1312 <parse_double_optional_fraction+0x1d2>
movsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1333 <parse_double_optional_fraction+0x1f3>
movsbl -0x31(%rbp),%eax
cmp    $0x2a,%eax
jne    132e <parse_double_optional_fraction+0x1ee>
movsd  -0x40(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1333 <parse_double_optional_fraction+0x1f3>
jmp    1194 <parse_double_optional_fraction+0x54>
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_double_optional_fraction>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%r14
call   1030 <strtod@plt>
mov    (%rbx),%rax
cmp    %r14,%rax
je     1278 <parse_double_optional_fraction+0x138>
movsd  %xmm0,0x8(%rsp)
jmp    1250 <parse_double_optional_fraction+0x110>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1180 <parse_double_optional_fraction+0x40>
mov    (%rbx),%rax
mov    (%rax),%bpl
cmp    $0x2f,%bpl
je     11b3 <parse_double_optional_fraction+0x73>
cmp    $0x2a,%bpl
je     11b3 <parse_double_optional_fraction+0x73>
jmp    1258 <parse_double_optional_fraction+0x118>
nop
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11b0 <parse_double_optional_fraction+0x70>
mov    (%rbx),%r15
cmpb   $0x28,(%r15)
jne    11fb <parse_double_optional_fraction+0xbb>
lea    0x1(%r15),%rdi
movsd  0xe23(%rip),%xmm0
mov    %rbx,%rsi
call   1040 <parse_double_optional_fraction@plt>
mov    (%rbx),%rax
cmpb   $0x29,(%rax)
jne    1260 <parse_double_optional_fraction+0x120>
add    $0x1,%rax
mov    %rax,(%rbx)
cmp    %r15,%rax
jne    120e <parse_double_optional_fraction+0xce>
jmp    1278 <parse_double_optional_fraction+0x138>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strtod@plt>
mov    (%rbx),%rax
cmp    %r15,%rax
je     1278 <parse_double_optional_fraction+0x138>
cmp    $0x2a,%bpl
je     1232 <parse_double_optional_fraction+0xf2>
cmp    $0x2f,%bpl
jne    1250 <parse_double_optional_fraction+0x110>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsbl (%rax),%edi
jmp    118e <parse_double_optional_fraction+0x4e>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsbl (%rax),%edi
jmp    118e <parse_double_optional_fraction+0x4e>
nopw   0x0(%rax,%rax,1)
movsbl (%rax),%edi
jmp    118e <parse_double_optional_fraction+0x4e>
movsd  0x8(%rsp),%xmm0
jmp    127e <parse_double_optional_fraction+0x13e>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Mismatching parenthesis in '%s'\0A\00"
define double @parse_double_optional_fraction(i8* %0, double %1, i8** %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca double
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca double
%10 = alloca i8
%11 = alloca double
store i8* %0, i8** %5
store double %1, double* %6
store i8** %2, i8*** %7
%12 = load i8*, i8** %5
store i8* %12, i8** %8
%13 = load i8*, i8** %5
%14 = load i8**, i8*** %7
%15 = call double @strtod(i8* %13, i8** %14)
store double %15, double* %9
%16 = load i8**, i8*** %7
%17 = load i8*, i8** %16
%18 = load i8*, i8** %5
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load double, double* %6
store double %21, double* %4
br label %117
22: ; preds = %3
br label %23
23: ; preds = %116, %22
br label %24
24: ; preds = %30, %23
%25 = load i8**, i8*** %7
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = call i64 @isspace(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i8**, i8*** %7
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
br label %24
34: ; preds = %24
%35 = load i8**, i8*** %7
%36 = load i8*, i8** %35
%37 = load i8, i8* %36
store i8 %37, i8* %10
%38 = load i8, i8* %10
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 47
br i1 %40, label %41, label %47
41: ; preds = %34
%42 = load i8, i8* %10
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 42
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load double, double* %9
store double %46, double* %4
br label %117
47: ; preds = %41, %34
%48 = load i8**, i8*** %7
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %48
br label %51
51: ; preds = %57, %47
%52 = load i8**, i8*** %7
%53 = load i8*, i8** %52
%54 = load i8, i8* %53
%55 = call i64 @isspace(i8 signext %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = load i8**, i8*** %7
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %58
br label %51
61: ; preds = %51
%62 = load i8**, i8*** %7
%63 = load i8*, i8** %62
store i8* %63, i8** %5
%64 = load i8*, i8** %5
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 40
br i1 %67, label %68, label %88
68: ; preds = %61
%69 = load i8*, i8** %5
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i8**, i8*** %7
%72 = call double @parse_double_optional_fraction(i8* %70, double 1.000000e+00, i8** %71)
store double %72, double* %11
%73 = load i8**, i8*** %7
%74 = load i8*, i8** %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 41
br i1 %77, label %78, label %83
78: ; preds = %68
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %8
%81 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %80)
%82 = load double, double* %6
store double %82, double* %4
br label %117
83: ; preds = %68
%84 = load i8**, i8*** %7
%85 = load i8*, i8** %84
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %84
br label %87
87: ; preds = %83
br label %92
88: ; preds = %61
%89 = load i8*, i8** %5
%90 = load i8**, i8*** %7
%91 = call double @strtod(i8* %89, i8** %90)
store double %91, double* %11
br label %92
92: ; preds = %88, %87
%93 = load i8**, i8*** %7
%94 = load i8*, i8** %93
%95 = load i8*, i8** %5
%96 = icmp eq i8* %94, %95
br i1 %96, label %97, label %99
97: ; preds = %92
%98 = load double, double* %6
store double %98, double* %4
br label %117
99: ; preds = %92
%100 = load i8, i8* %10
%101 = sext i8 %100 to i32
%102 = icmp eq i32 %101, 47
br i1 %102, label %103, label %107
103: ; preds = %99
%104 = load double, double* %11
%105 = load double, double* %9
%106 = fdiv double %105, %104
store double %106, double* %9
br label %116
107: ; preds = %99
%108 = load i8, i8* %10
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 42
br i1 %110, label %111, label %115
111: ; preds = %107
%112 = load double, double* %11
%113 = load double, double* %9
%114 = fmul double %113, %112
store double %114, double* %9
br label %115
115: ; preds = %111, %107
br label %116
116: ; preds = %115, %103
br label %23
117: ; preds = %97, %78, %45, %20
%118 = load double, double* %4
ret double %118
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Mismatching parenthesis in '%s'\0A\00"
define double @parse_double_optional_fraction(i8* %0, double %1, i8** nocapture %2) {
%4 = tail call double @strtod(i8* %0, i8** %2)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, %0
br i1 %6, label %64, label %7
7: ; preds = %3, %62
%8 = phi i8* [ %54, %62 ], [ %5, %3 ]
%9 = phi double [ %63, %62 ], [ %4, %3 ]
br label %10
10: ; preds = %7, %57
%11 = phi i8* [ %54, %57 ], [ %8, %7 ]
%12 = load i8, i8* %11
%13 = tail call i64 @isspace(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10, %15
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %2
%18 = load i8, i8* %17
%19 = tail call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %10
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
switch i8 %23, label %64 [
i8 47, label %24
i8 42, label %24
]
24: ; preds = %21, %21
%25 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %25, i8** %2
%26 = load i8, i8* %25
%27 = tail call i64 @isspace(i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %24, %29
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %2
%32 = load i8, i8* %31
%33 = tail call i64 @isspace(i8 signext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %29
35: ; preds = %29, %24
%36 = load i8*, i8** %2
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 40
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %36, i64 1
%41 = tail call double @parse_double_optional_fraction(i8* %40, double 1.000000e+00, i8** %2)
%42 = load i8*, i8** %2
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 41
br i1 %44, label %48, label %45
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %64
48: ; preds = %39
%49 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %49, i8** %2
br label %53
50: ; preds = %35
%51 = tail call double @strtod(i8* %36, i8** %2)
%52 = load i8*, i8** %2
br label %53
53: ; preds = %50, %48
%54 = phi i8* [ %49, %48 ], [ %52, %50 ]
%55 = phi double [ %41, %48 ], [ %51, %50 ]
%56 = icmp eq i8* %54, %36
br i1 %56, label %64, label %57
57: ; preds = %53
switch i8 %23, label %10 [
i8 47, label %58
i8 42, label %60
]
58: ; preds = %57
%59 = fdiv double %9, %55
br label %62
60: ; preds = %57
%61 = fmul double %9, %55
br label %62
62: ; preds = %60, %58
%63 = phi double [ %59, %58 ], [ %61, %60 ]
br label %7
64: ; preds = %53, %21, %45, %3
%65 = phi double [ %1, %3 ], [ %1, %45 ], [ %9, %21 ], [ %1, %53 ]
ret double %65
}