#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*/ replace(char *, size_t, char *, int, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int rnc_normalize(char *buf, size_t buflen) {
  replace(buf, buflen, "IIIII", sizeof("IIIII") - sizeof(""), "V",
          sizeof("V") - sizeof(""));
  replace(buf, buflen, "IIII", sizeof("IIII") - sizeof(""), "IV",
          sizeof("IV") - sizeof(""));
  replace(buf, buflen, "VV", sizeof("VV") - sizeof(""), "X",
          sizeof("X") - sizeof(""));
  replace(buf, buflen, "VIV", sizeof("VIV") - sizeof(""), "IX",
          sizeof("IX") - sizeof(""));
  replace(buf, buflen, "XXXXX", sizeof("XXXXX") - sizeof(""), "L",
          sizeof("L") - sizeof(""));
  replace(buf, buflen, "XXXX", sizeof("XXXX") - sizeof(""), "XL",
          sizeof("XL") - sizeof(""));
  replace(buf, buflen, "LL", sizeof("LL") - sizeof(""), "C",
          sizeof("C") - sizeof(""));
  replace(buf, buflen, "LXL", sizeof("LXL") - sizeof(""), "XC",
          sizeof("XC") - sizeof(""));
  replace(buf, buflen, "CCCCC", sizeof("CCCCC") - sizeof(""), "D",
          sizeof("D") - sizeof(""));
  replace(buf, buflen, "CCCC", sizeof("CCCC") - sizeof(""), "CD",
          sizeof("CD") - sizeof(""));
  replace(buf, buflen, "DD", sizeof("DD") - sizeof(""), "M",
          sizeof("M") - sizeof(""));
  replace(buf, buflen, "DCD", sizeof("DCD") - sizeof(""), "CM",
          sizeof("CM") - sizeof(""));
  if (NULL != strstr(buf, "MMMM")) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rnc_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xec1(%rip),%rdx
mov    $0x5,%ecx
lea    0xec0(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe9c(%rip),%rdx
mov    $0x4,%ecx
lea    0xe99(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe7b(%rip),%rdx
mov    $0x2,%ecx
lea    0xe77(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe58(%rip),%rdx
mov    $0x3,%ecx
lea    0xe50(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe39(%rip),%rdx
mov    $0x5,%ecx
lea    0xe34(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe14(%rip),%rdx
mov    $0x4,%ecx
lea    0xe11(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdf3(%rip),%rdx
mov    $0x2,%ecx
lea    0xdf5(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdd0(%rip),%rdx
mov    $0x3,%ecx
lea    0xdc8(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdb1(%rip),%rdx
mov    $0x5,%ecx
lea    0xdb0(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xd8c(%rip),%rdx
mov    $0x4,%ecx
lea    0xd89(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xd6b(%rip),%rdx
mov    $0x2,%ecx
lea    0xd67(%rip),%r8
mov    $0x1,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xd48(%rip),%rdx
mov    $0x3,%ecx
lea    0xd40(%rip),%r8
mov    $0x2,%r9d
call   1030 <replace@plt>
mov    -0x10(%rbp),%rdi
lea    0xd2d(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1322 <rnc_normalize+0x202>
movl   $0x1,-0x4(%rbp)
jmp    1329 <rnc_normalize+0x209>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnc_normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecf(%rip),%rdx
lea    0xed3(%rip),%r8
mov    $0x5,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xeb2(%rip),%rdx
lea    0xeb4(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xe93(%rip),%rdx
lea    0xe94(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xe72(%rip),%rdx
lea    0xe6f(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xe55(%rip),%rdx
lea    0xe55(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xe32(%rip),%rdx
lea    0xe34(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xe13(%rip),%rdx
lea    0xe1a(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xdf2(%rip),%rdx
lea    0xdef(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xdd5(%rip),%rdx
lea    0xdd9(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xdb2(%rip),%rdx
lea    0xdb4(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xd93(%rip),%rdx
lea    0xd94(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%ecx
mov    $0x1,%r9d
call   1030 <replace@plt>
lea    0xd72(%rip),%rdx
lea    0xd6f(%rip),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%ecx
mov    $0x2,%r9d
call   1030 <replace@plt>
lea    0xd55(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"IIIII\00"
@.str.1 = [2 x i8] c"V\00"
@.str.2 = [5 x i8] c"IIII\00"
@.str.3 = [3 x i8] c"IV\00"
@.str.4 = [3 x i8] c"VV\00"
@.str.5 = [2 x i8] c"X\00"
@.str.6 = [4 x i8] c"VIV\00"
@.str.7 = [3 x i8] c"IX\00"
@.str.8 = [6 x i8] c"XXXXX\00"
@.str.9 = [2 x i8] c"L\00"
@.str.10 = [5 x i8] c"XXXX\00"
@.str.11 = [3 x i8] c"XL\00"
@.str.12 = [3 x i8] c"LL\00"
@.str.13 = [2 x i8] c"C\00"
@.str.14 = [4 x i8] c"LXL\00"
@.str.15 = [3 x i8] c"XC\00"
@.str.16 = [6 x i8] c"CCCCC\00"
@.str.17 = [2 x i8] c"D\00"
@.str.18 = [5 x i8] c"CCCC\00"
@.str.19 = [3 x i8] c"CD\00"
@.str.20 = [3 x i8] c"DD\00"
@.str.21 = [2 x i8] c"M\00"
@.str.22 = [4 x i8] c"DCD\00"
@.str.23 = [3 x i8] c"CM\00"
@.str.24 = [5 x i8] c"MMMM\00"
define i32 @rnc_normalize(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%6 = load i8*, i8** %4
%7 = load i64, i64* %5
%8 = call i32 @replace(i8* %6, i64 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = call i32 @replace(i8* %9, i64 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i32 @replace(i8* %12, i64 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = call i32 @replace(i8* %15, i64 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i32 @replace(i8* %18, i64 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = call i32 @replace(i8* %21, i64 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32 2)
%24 = load i8*, i8** %4
%25 = load i64, i64* %5
%26 = call i32 @replace(i8* %24, i64 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i32 1)
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = call i32 @replace(i8* %27, i64 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32 2)
%30 = load i8*, i8** %4
%31 = load i64, i64* %5
%32 = call i32 @replace(i8* %30, i64 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i32 1)
%33 = load i8*, i8** %4
%34 = load i64, i64* %5
%35 = call i32 @replace(i8* %33, i64 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i32 2)
%36 = load i8*, i8** %4
%37 = load i64, i64* %5
%38 = call i32 @replace(i8* %36, i64 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32 1)
%39 = load i8*, i8** %4
%40 = load i64, i64* %5
%41 = call i32 @replace(i8* %39, i64 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i32 2)
%42 = load i8*, i8** %4
%43 = call i32* @strstr(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.24, i64 0, i64 0))
%44 = icmp ne i32* null, %43
br i1 %44, label %45, label %46
45: ; preds = %2
store i32 1, i32* %3
br label %47
46: ; preds = %2
store i32 0, i32* %3
br label %47
47: ; preds = %46, %45
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"IIIII\00"
@.str.1 = [2 x i8] c"V\00"
@.str.2 = [5 x i8] c"IIII\00"
@.str.3 = [3 x i8] c"IV\00"
@.str.4 = [3 x i8] c"VV\00"
@.str.5 = [2 x i8] c"X\00"
@.str.6 = [4 x i8] c"VIV\00"
@.str.7 = [3 x i8] c"IX\00"
@.str.8 = [6 x i8] c"XXXXX\00"
@.str.9 = [2 x i8] c"L\00"
@.str.10 = [5 x i8] c"XXXX\00"
@.str.11 = [3 x i8] c"XL\00"
@.str.12 = [3 x i8] c"LL\00"
@.str.13 = [2 x i8] c"C\00"
@.str.14 = [4 x i8] c"LXL\00"
@.str.15 = [3 x i8] c"XC\00"
@.str.16 = [6 x i8] c"CCCCC\00"
@.str.17 = [2 x i8] c"D\00"
@.str.18 = [5 x i8] c"CCCC\00"
@.str.19 = [3 x i8] c"CD\00"
@.str.20 = [3 x i8] c"DD\00"
@.str.21 = [2 x i8] c"M\00"
@.str.22 = [4 x i8] c"DCD\00"
@.str.23 = [3 x i8] c"CM\00"
@.str.24 = [5 x i8] c"MMMM\00"
define i32 @rnc_normalize(i8* %0, i64 %1) {
%3 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%5 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%6 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%7 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%8 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32 2)
%9 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i32 1)
%10 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i32 2)
%11 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i32 1)
%12 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.19, i64 0, i64 0), i32 2)
%13 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32 1)
%14 = tail call i32 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.22, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i32 2)
%15 = tail call i32* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.24, i64 0, i64 0))
%16 = icmp ne i32* %15, null
%17 = zext i1 %16 to i32
ret i32 %17
}