int romanToInt(char *s) {
  int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  char symbols[13][3] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                         "XL", "X",  "IX", "V",  "IV", "I"};
  int i = 0;
  int ret = 0;
  int len = 0;
  while (*s && i < 13) {
    len = strlen(symbols[i]);
    if (!strncmp(s, symbols[i], len)) {
      ret += values[i];
      s += len;
      continue;
    }
    i++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<romanToInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x34,%edx
call   1050 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xee1(%rip),%rsi
mov    $0x27,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x7d(%rbp)
je     119d <romanToInt+0x6d>
cmpl   $0xd,-0x74(%rbp)
setl   %al
mov    %al,-0x7d(%rbp)
mov    -0x7d(%rbp),%al
test   $0x1,%al
jne    11ad <romanToInt+0x7d>
jmp    121b <romanToInt+0xeb>
movslq -0x74(%rbp),%rax
lea    -0x70(%rbp),%rdi
imul   $0x3,%rax,%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x74(%rbp),%rax
lea    -0x70(%rbp),%rsi
imul   $0x3,%rax,%rax
add    %rax,%rsi
movslq -0x7c(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    120d <romanToInt+0xdd>
movslq -0x74(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
add    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x7c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    117e <romanToInt+0x4e>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    117e <romanToInt+0x4e>
mov    -0x78(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<romanToInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     11c4 <romanToInt+0xa4>
mov    %rdi,%r15
xor    %r14d,%r14d
lea    0xebf(%rip),%rax
lea    0xef8(%rip),%rcx
xor    %r13d,%r13d
movslq %r13d,%r13
lea    (%rax,%r13,4),%rbp
lea    0x0(,%r13,2),%rbx
add    %r13,%rbx
add    %rcx,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a0 <romanToInt+0x80>
lea    0x1(%r13),%rax
add    $0x4,%rbp
add    $0x3,%rbx
cmp    $0xc,%r13
mov    %rax,%r13
jl     1160 <romanToInt+0x40>
jmp    11c7 <romanToInt+0xa7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x0(%rbp),%r14d
cmpb   $0x0,(%r15,%r12,1)
je     11c7 <romanToInt+0xa7>
add    %r12,%r15
cmp    $0xd,%r13d
lea    0xe47(%rip),%rax
lea    0xe80(%rip),%rcx
jl     114b <romanToInt+0x2b>
jmp    11c7 <romanToInt+0xa7>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.romanToInt.values = [13 x i32] [i32 1000, i32 900, i32 500, i32 400, i32 100, i32 90, i32 50, i32 40, i32 10, i32 9, i32 5, i32 4, i32 1]
@__const.romanToInt.symbols = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
define i32 @romanToInt(i8* %0) {
%2 = alloca i8*
%3 = alloca [13 x i32]
%4 = alloca [13 x [3 x i8]]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [13 x i32]* %3 to i8*
%9 = bitcast [13 x [3 x i8]]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %47, %36, %1
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 13
br label %18
18: ; preds = %15, %10
%19 = phi i1 [ false, %10 ], [ %17, %15 ]
br i1 %19, label %20, label %50
20: ; preds = %18
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %4, i64 0, i64 %22
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %23, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i8*, i8** %2
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %4, i64 0, i64 %29
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %30, i64 0, i64 0
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = call i32 @strncmp(i8* %27, i8* %31, i64 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %20
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, %40
store i32 %42, i32* %6
%43 = load i32, i32* %7
%44 = load i8*, i8** %2
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %2
br label %10
47: ; preds = %20
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %10
50: ; preds = %18
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
@__const.romanToInt.values = [13 x i32] [i32 1000, i32 900, i32 500, i32 400, i32 100, i32 90, i32 50, i32 40, i32 10, i32 9, i32 5, i32 4, i32 1]
@__const.romanToInt.symbols = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
define i32 @romanToInt(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %31, label %4
4: ; preds = %1, %18
%5 = phi i32 [ %22, %18 ], [ 0, %1 ]
%6 = phi i64 [ %11, %18 ], [ 0, %1 ]
%7 = phi i8* [ %23, %18 ], [ %0, %1 ]
%8 = shl i64 %6, 32
%9 = ashr exact i64 %8, 32
br label %10
10: ; preds = %4, %28
%11 = phi i64 [ %9, %4 ], [ %29, %28 ]
%12 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* @__const.romanToInt.symbols, i64 0, i64 %11, i64 0
%13 = tail call i64 @strlen(i8* %12)
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
%16 = tail call i32 @strncmp(i8* %7, i8* %12, i64 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %10
%19 = trunc i64 %11 to i32
%20 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.romanToInt.values, i64 0, i64 %11
%21 = load i32, i32* %20
%22 = add nsw i32 %21, %5
%23 = getelementptr inbounds i8, i8* %7, i64 %15
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
%26 = icmp slt i32 %19, 13
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %4, label %31
28: ; preds = %10
%29 = add nsw i64 %11, 1
%30 = icmp slt i64 %11, 12
br i1 %30, label %10, label %31
31: ; preds = %18, %28, %1
%32 = phi i32 [ 0, %1 ], [ %5, %28 ], [ %22, %18 ]
ret i32 %32
}