#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 checkConvertedTermValue(int, int, char *);
int getNextConvertableValue(char, char, int *);
int /*<<< orphan*/ resetTermOccurrences();
int strlen(char *);
int convertRomanNumeralStringToBaseTenInt(char *numeralString) {
  resetTermOccurrences();
  int total = 0;
  int i = 0;
  do {
    int conversionResultOfSingleTerm =
        getNextConvertableValue(numeralString[i], numeralString[i + 1], &i);
    total = checkConvertedTermValue(conversionResultOfSingleTerm, total,
                                    numeralString);
    i++;
  } while ((i < strlen(numeralString)) && (total > 0));
  return total;
}


x86 assembly (clang, -O0):
<convertRomanNumeralStringToBaseTenInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <resetTermOccurrences@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%sil
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
lea    -0x10(%rbp),%rdx
movsbl %sil,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <getNextConvertableValue@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <checkConvertedTermValue@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    11d4 <convertRomanNumeralStringToBaseTenInt+0x94>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1161 <convertRomanNumeralStringToBaseTenInt+0x21>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertRomanNumeralStringToBaseTenInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <resetTermOccurrences@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movslq %r15d,%rax
movsbl (%r12,%rax,1),%edi
movsbl 0x1(%r12,%rax,1),%esi
mov    %r14,%rdx
call   1030 <getNextConvertableValue@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    %r12,%rdx
call   1060 <checkConvertedTermValue@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%ebx
add    $0x1,%ebx
mov    %ebx,0xc(%rsp)
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebx
jge    11b6 <convertRomanNumeralStringToBaseTenInt+0x76>
test   %ebp,%ebp
jle    11b6 <convertRomanNumeralStringToBaseTenInt+0x76>
mov    0xc(%rsp),%r15d
jmp    1170 <convertRomanNumeralStringToBaseTenInt+0x30>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @convertRomanNumeralStringToBaseTenInt(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (...) @resetTermOccurrences()
store i32 0, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %34, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @getNextConvertableValue(i8 signext %12, i8 signext %18, i32* %4)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = load i8*, i8** %2
%23 = call i32 @checkConvertedTermValue(i32 %20, i32 %21, i8* %22)
store i32 %23, i32* %3
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %7
%27 = load i32, i32* %4
%28 = load i8*, i8** %2
%29 = call i32 @strlen(i8* %28)
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 0
br label %34
34: ; preds = %31, %26
%35 = phi i1 [ false, %26 ], [ %33, %31 ]
br i1 %35, label %7, label %36
36: ; preds = %34
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @convertRomanNumeralStringToBaseTenInt(i8* %0) {
%2 = alloca i32
%3 = tail call i32 (...) @resetTermOccurrences()
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %23, %1
%6 = phi i32 [ 0, %1 ], [ %24, %23 ]
%7 = phi i32 [ 0, %1 ], [ %16, %23 ]
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = add nsw i32 %6, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = call i32 @getNextConvertableValue(i8 signext %10, i8 signext %14, i32* %2)
%16 = call i32 @checkConvertedTermValue(i32 %15, i32 %7, i8* %0)
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
%19 = call i32 @strlen(i8* %0)
%20 = icmp slt i32 %18, %19
%21 = icmp sgt i32 %16, 0
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = load i32, i32* %2
br label %5
25: ; preds = %5
ret i32 %16
}