#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*/ *strchr(char *, char const);
size_t strlen(char const *);
int /*<<< orphan*/ *strstr(char const *, char *);
bool is_valid_roman_numeral(const char *s) {
  if (NULL == s)
    return false;
  size_t length = strlen(s);
  if (0 == length || length > 14)
    return false;
  char *valid_digits = "IVXLCDM";
  for (int i = 0; i < length; i++) {
    if (NULL == strchr(valid_digits, s[i]))
      return false;
  }
  if (NULL != strstr(s, "IIII"))
    return false;
  if (NULL != strstr(s, "XXXX"))
    return false;
  if (NULL != strstr(s, "CCCC"))
    return false;
  if (NULL != strstr(s, "VV"))
    return false;
  if (NULL != strstr(s, "LL"))
    return false;
  if (NULL != strstr(s, "DD"))
    return false;
  return true;
}


x86 assembly (clang, -O0):
<is_valid_roman_numeral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1154 <is_valid_roman_numeral+0x24>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1178 <is_valid_roman_numeral+0x48>
cmpq   $0xe,-0x18(%rbp)
jbe    1184 <is_valid_roman_numeral+0x54>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
lea    0xe75(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11e6 <is_valid_roman_numeral+0xb6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d3 <is_valid_roman_numeral+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
jmp    11d8 <is_valid_roman_numeral+0xa8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <is_valid_roman_numeral+0x66>
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1210 <is_valid_roman_numeral+0xe0>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     123a <is_valid_roman_numeral+0x10a>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1264 <is_valid_roman_numeral+0x134>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     128e <is_valid_roman_numeral+0x15e>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12b8 <is_valid_roman_numeral+0x188>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12e2 <is_valid_roman_numeral+0x1b2>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <is_valid_roman_numeral+0x1b9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_roman_numeral>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %r14d,%r14d
test   %rdi,%rdi
je     120c <is_valid_roman_numeral+0xdc>
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r13
add    $0xfffffffffffffff1,%rax
cmp    $0xfffffffffffffff2,%rax
jb     120c <is_valid_roman_numeral+0xdc>
xor    %r14d,%r14d
lea    0xe98(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     120c <is_valid_roman_numeral+0xdc>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <is_valid_roman_numeral+0x40>
lea    0xe72(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    120c <is_valid_roman_numeral+0xdc>
lea    0xe63(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    120c <is_valid_roman_numeral+0xdc>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    120c <is_valid_roman_numeral+0xdc>
lea    0xe45(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    120c <is_valid_roman_numeral+0xdc>
lea    0xe34(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    120c <is_valid_roman_numeral+0xdc>
lea    0xe23(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"IVXLCDM\00"
@.str.1 = [5 x i8] c"IIII\00"
@.str.2 = [5 x i8] c"XXXX\00"
@.str.3 = [5 x i8] c"CCCC\00"
@.str.4 = [3 x i8] c"VV\00"
@.str.5 = [3 x i8] c"LL\00"
@.str.6 = [3 x i8] c"DD\00"
define i32 @is_valid_roman_numeral(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %70
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp eq i64 0, %13
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i64, i64* %4
%17 = icmp ugt i64 %16, 14
br i1 %17, label %18, label %19
18: ; preds = %15, %10
store i32 0, i32* %2
br label %70
19: ; preds = %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %6
br label %20
20: ; preds = %36, %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = load i64, i64* %4
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32* @strchr(i8* %26, i8 signext %31)
%33 = icmp eq i32* null, %32
br i1 %33, label %34, label %35
34: ; preds = %25
store i32 0, i32* %2
br label %70
35: ; preds = %25
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %20
39: ; preds = %20
%40 = load i8*, i8** %3
%41 = call i32* @strstr(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp ne i32* null, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 0, i32* %2
br label %70
44: ; preds = %39
%45 = load i8*, i8** %3
%46 = call i32* @strstr(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%47 = icmp ne i32* null, %46
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 0, i32* %2
br label %70
49: ; preds = %44
%50 = load i8*, i8** %3
%51 = call i32* @strstr(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i32* null, %51
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 0, i32* %2
br label %70
54: ; preds = %49
%55 = load i8*, i8** %3
%56 = call i32* @strstr(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp ne i32* null, %56
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 0, i32* %2
br label %70
59: ; preds = %54
%60 = load i8*, i8** %3
%61 = call i32* @strstr(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%62 = icmp ne i32* null, %61
br i1 %62, label %63, label %64
63: ; preds = %59
store i32 0, i32* %2
br label %70
64: ; preds = %59
%65 = load i8*, i8** %3
%66 = call i32* @strstr(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%67 = icmp ne i32* null, %66
br i1 %67, label %68, label %69
68: ; preds = %64
store i32 0, i32* %2
br label %70
69: ; preds = %64
store i32 1, i32* %2
br label %70
70: ; preds = %69, %68, %63, %58, %53, %48, %43, %34, %18, %9
%71 = load i32, i32* %2
ret i32 %71
}

LLVM IR (-O2):
@.str = [8 x i8] c"IVXLCDM\00"
@.str.1 = [5 x i8] c"IIII\00"
@.str.2 = [5 x i8] c"XXXX\00"
@.str.3 = [5 x i8] c"CCCC\00"
@.str.4 = [3 x i8] c"VV\00"
@.str.5 = [3 x i8] c"LL\00"
@.str.6 = [3 x i8] c"DD\00"
define i32 @is_valid_roman_numeral(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %35, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add i64 %4, -15
%6 = icmp ult i64 %5, -14
br i1 %6, label %35, label %9
7: ; preds = %9
%8 = icmp eq i64 %15, %4
br i1 %8, label %16, label %9
9: ; preds = %3, %7
%10 = phi i64 [ %15, %7 ], [ 0, %3 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32* @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp eq i32* %13, null
%15 = add nuw i64 %10, 1
br i1 %14, label %35, label %7
16: ; preds = %7
%17 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i32* %32, null
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %9, %3, %31, %28, %25, %22, %19, %16, %1
%36 = phi i32 [ 0, %1 ], [ 0, %3 ], [ 0, %16 ], [ 0, %19 ], [ 0, %22 ], [ 0, %25 ], [ 0, %28 ], [ %34, %31 ], [ 0, %9 ]
ret i32 %36
}