#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 countchar(char *, char);
int countops(char *, int /*<<< orphan*/);
scalar_t__ evalChunk(char *, int, int);
int firstIndexOf(char *, char, int);
int leftNumIndex(char *, int);
int rightNumIndex(char *, int);
int /*<<< orphan*/ strlen(char *);
double evalMexp(char str[200]) {
  double result = 0;
  int i, n = countops(str, strlen(str));
  int j = firstIndexOf(str, '*', 0);
  int a, b;
  int mults = countchar(str, '*'), divs = countchar(str, '/'),
      plus = countchar(str, '+'), mins = countchar(str, '-');
  for (i = 0; i < mults; i++) {
    a = leftNumIndex(str, j);
    b = rightNumIndex(str, j);
    result += evalChunk(str, a, b);
    j = firstIndexOf(str, '*', j);
  }
  return result;
}


x86 assembly (clang, -O0):
<evalMexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1050 <countops@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2a,%esi
xor    %edx,%edx
call   1060 <firstIndexOf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <countchar@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <countchar@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
call   1030 <countchar@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <countchar@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    126b <evalMexp+0xfb>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <leftNumIndex@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <rightNumIndex@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1090 <evalChunk@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x2a,%esi
call   1060 <firstIndexOf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1201 <evalMexp+0x91>
movsd  -0x10(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evalMexp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <countops@plt>
mov    %r14,%rdi
mov    $0x2a,%esi
xor    %edx,%edx
call   1060 <firstIndexOf@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x2a,%esi
call   1030 <countchar@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <countchar@plt>
mov    %r14,%rdi
mov    $0x2b,%esi
call   1030 <countchar@plt>
mov    %r14,%rdi
mov    $0x2d,%esi
call   1030 <countchar@plt>
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
jle    1232 <evalMexp+0xc2>
movsd  %xmm0,(%rsp)
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <leftNumIndex@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <rightNumIndex@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1090 <evalChunk@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r14,%rdi
mov    $0x2a,%esi
mov    %ebp,%edx
call   1060 <firstIndexOf@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebx
jne    11e0 <evalMexp+0x70>
jmp    1237 <evalMexp+0xc7>
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @evalMexp(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %2
store double 0.000000e+00, double* %3
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @countops(i8* %13, i32 %15)
store i32 %16, i32* %5
%17 = load i8*, i8** %2
%18 = call i32 @firstIndexOf(i8* %17, i8 signext 42, i32 0)
store i32 %18, i32* %6
%19 = load i8*, i8** %2
%20 = call i32 @countchar(i8* %19, i8 signext 42)
store i32 %20, i32* %9
%21 = load i8*, i8** %2
%22 = call i32 @countchar(i8* %21, i8 signext 47)
store i32 %22, i32* %10
%23 = load i8*, i8** %2
%24 = call i32 @countchar(i8* %23, i8 signext 43)
store i32 %24, i32* %11
%25 = load i8*, i8** %2
%26 = call i32 @countchar(i8* %25, i8 signext 45)
store i32 %26, i32* %12
store i32 0, i32* %4
br label %27
27: ; preds = %48, %1
%28 = load i32, i32* %4
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %51
31: ; preds = %27
%32 = load i8*, i8** %2
%33 = load i32, i32* %6
%34 = call i32 @leftNumIndex(i8* %32, i32 %33)
store i32 %34, i32* %7
%35 = load i8*, i8** %2
%36 = load i32, i32* %6
%37 = call i32 @rightNumIndex(i8* %35, i32 %36)
store i32 %37, i32* %8
%38 = load i8*, i8** %2
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = call i64 @evalChunk(i8* %38, i32 %39, i32 %40)
%42 = sitofp i64 %41 to double
%43 = load double, double* %3
%44 = fadd double %43, %42
store double %44, double* %3
%45 = load i8*, i8** %2
%46 = load i32, i32* %6
%47 = call i32 @firstIndexOf(i8* %45, i8 signext 42, i32 %46)
store i32 %47, i32* %6
br label %48
48: ; preds = %31
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %27
51: ; preds = %27
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
define double @evalMexp(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @countops(i8* %0, i32 %2)
%4 = tail call i32 @firstIndexOf(i8* %0, i8 signext 42, i32 0)
%5 = tail call i32 @countchar(i8* %0, i8 signext 42)
%6 = tail call i32 @countchar(i8* %0, i8 signext 47)
%7 = tail call i32 @countchar(i8* %0, i8 signext 43)
%8 = tail call i32 @countchar(i8* %0, i8 signext 45)
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %22
10: ; preds = %1, %10
%11 = phi double [ %18, %10 ], [ 0.000000e+00, %1 ]
%12 = phi i32 [ %20, %10 ], [ 0, %1 ]
%13 = phi i32 [ %19, %10 ], [ %4, %1 ]
%14 = tail call i32 @leftNumIndex(i8* %0, i32 %13)
%15 = tail call i32 @rightNumIndex(i8* %0, i32 %13)
%16 = tail call i64 @evalChunk(i8* %0, i32 %14, i32 %15)
%17 = sitofp i64 %16 to double
%18 = fadd double %11, %17
%19 = tail call i32 @firstIndexOf(i8* %0, i8 signext 42, i32 %13)
%20 = add nuw nsw i32 %12, 1
%21 = icmp eq i32 %20, %5
br i1 %21, label %22, label %10
22: ; preds = %10, %1
%23 = phi double [ 0.000000e+00, %1 ], [ %18, %10 ]
ret double %23
}