#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 */
scalar_t__ replace(char *, size_t, char *, int, char *, int);
char *stpncpy(char *, char const *, size_t);
int rnc_denormalize(char *out, size_t outlen, const char *normal) {
  if (stpncpy(out, normal, outlen) >= out + outlen) {
    return 1;
  }
  return replace(out, outlen, "IV", sizeof("IV") - sizeof(""), "IIII",
                 sizeof("IIII") - sizeof("")) ||
         replace(out, outlen, "IX", sizeof("IX") - sizeof(""), "VIIII",
                 sizeof("VIIII") - sizeof("")) ||
         replace(out, outlen, "XL", sizeof("XL") - sizeof(""), "XXXX",
                 sizeof("XXXX") - sizeof("")) ||
         replace(out, outlen, "XC", sizeof("XC") - sizeof(""), "LXXXX",
                 sizeof("LXXXX") - sizeof("")) ||
         replace(out, outlen, "CD", sizeof("CD") - sizeof(""), "CCCC",
                 sizeof("CCCC") - sizeof("")) ||
         replace(out, outlen, "CM", sizeof("CM") - sizeof(""), "DCCCC",
                 sizeof("DCCCC") - sizeof(""));
}


x86 assembly (clang, -O0):
<rnc_denormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <stpncpy@plt>
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jb     1162 <rnc_denormalize+0x42>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <rnc_denormalize+0x195>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe8f(%rip),%rdx
mov    $0x2,%ecx
lea    0xe8a(%rip),%r8
mov    $0x4,%r9d
call   1040 <replace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12aa <rnc_denormalize+0x18a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe5a(%rip),%rdx
mov    $0x2,%ecx
lea    0xe51(%rip),%r8
mov    $0x5,%r9d
call   1040 <replace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12aa <rnc_denormalize+0x18a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe2b(%rip),%rdx
mov    $0x2,%ecx
lea    0xe26(%rip),%r8
mov    $0x4,%r9d
call   1040 <replace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12aa <rnc_denormalize+0x18a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdf6(%rip),%rdx
mov    $0x2,%ecx
lea    0xded(%rip),%r8
mov    $0x5,%r9d
call   1040 <replace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12aa <rnc_denormalize+0x18a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdc7(%rip),%rdx
mov    $0x2,%ecx
lea    0xdc2(%rip),%r8
mov    $0x4,%r9d
call   1040 <replace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    12aa <rnc_denormalize+0x18a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xd92(%rip),%rdx
mov    $0x2,%ecx
lea    0xd89(%rip),%r8
mov    $0x5,%r9d
call   1040 <replace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnc_denormalize>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rdx,%rsi
mov    %rbx,%rdx
call   1030 <stpncpy@plt>
lea    (%rbx,%rbp,1),%rcx
mov    $0x1,%r14d
cmp    %rcx,%rax
jae    124f <rnc_denormalize+0x12f>
lea    0xeb1(%rip),%rdx
lea    0xeb1(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x4,%r9d
call   1040 <replace@plt>
test   %rax,%rax
jne    124f <rnc_denormalize+0x12f>
lea    0xe87(%rip),%rdx
lea    0xe83(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x5,%r9d
call   1040 <replace@plt>
test   %rax,%rax
jne    124f <rnc_denormalize+0x12f>
lea    0xe63(%rip),%rdx
lea    0xe63(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x4,%r9d
call   1040 <replace@plt>
test   %rax,%rax
jne    124f <rnc_denormalize+0x12f>
lea    0xe39(%rip),%rdx
lea    0xe35(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x5,%r9d
call   1040 <replace@plt>
test   %rax,%rax
jne    124f <rnc_denormalize+0x12f>
lea    0xe19(%rip),%rdx
lea    0xe19(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x4,%r9d
call   1040 <replace@plt>
test   %rax,%rax
jne    124f <rnc_denormalize+0x12f>
lea    0xdf3(%rip),%rdx
lea    0xdef(%rip),%r8
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
mov    $0x5,%r9d
call   1040 <replace@plt>
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"IV\00"
@.str.1 = [5 x i8] c"IIII\00"
@.str.2 = [3 x i8] c"IX\00"
@.str.3 = [6 x i8] c"VIIII\00"
@.str.4 = [3 x i8] c"XL\00"
@.str.5 = [5 x i8] c"XXXX\00"
@.str.6 = [3 x i8] c"XC\00"
@.str.7 = [6 x i8] c"LXXXX\00"
@.str.8 = [3 x i8] c"CD\00"
@.str.9 = [5 x i8] c"CCCC\00"
@.str.10 = [3 x i8] c"CM\00"
@.str.11 = [6 x i8] c"DCCCC\00"
define i32 @rnc_denormalize(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%8 = load i8*, i8** %5
%9 = load i8*, i8** %7
%10 = load i64, i64* %6
%11 = call i8* @stpncpy(i8* %8, i8* %9, i64 %10)
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = icmp uge i8* %11, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 1, i32* %4
br label %50
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = call i64 @replace(i8* %18, i64 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = icmp ne i64 %20, 0
br i1 %21, label %47, label %22
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = call i64 @replace(i8* %23, i64 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%26 = icmp ne i64 %25, 0
br i1 %26, label %47, label %27
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = call i64 @replace(i8* %28, i64 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%31 = icmp ne i64 %30, 0
br i1 %31, label %47, label %32
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = call i64 @replace(i8* %33, i64 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%36 = icmp ne i64 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = call i64 @replace(i8* %38, i64 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%41 = icmp ne i64 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = load i8*, i8** %5
%44 = load i64, i64* %6
%45 = call i64 @replace(i8* %43, i64 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 5)
%46 = icmp ne i64 %45, 0
br label %47
47: ; preds = %42, %37, %32, %27, %22, %17
%48 = phi i1 [ true, %37 ], [ true, %32 ], [ true, %27 ], [ true, %22 ], [ true, %17 ], [ %46, %42 ]
%49 = zext i1 %48 to i32
store i32 %49, i32* %4
br label %50
50: ; preds = %47, %16
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"IV\00"
@.str.1 = [5 x i8] c"IIII\00"
@.str.2 = [3 x i8] c"IX\00"
@.str.3 = [6 x i8] c"VIIII\00"
@.str.4 = [3 x i8] c"XL\00"
@.str.5 = [5 x i8] c"XXXX\00"
@.str.6 = [3 x i8] c"XC\00"
@.str.7 = [6 x i8] c"LXXXX\00"
@.str.8 = [3 x i8] c"CD\00"
@.str.9 = [5 x i8] c"CCCC\00"
@.str.10 = [3 x i8] c"CM\00"
@.str.11 = [6 x i8] c"DCCCC\00"
define i32 @rnc_denormalize(i8* %0, i64 %1, i8* nocapture %2) {
%4 = tail call i8* @stpncpy(i8* %0, i8* %2, i64 %1)
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = icmp ult i8* %4, %5
br i1 %6, label %7, label %26
7: ; preds = %3
%8 = tail call i64 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = tail call i64 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = tail call i64 @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 ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = tail call i64 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = tail call i64 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = tail call i64 @replace(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 5)
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %7, %10, %13, %16, %19, %22, %3
%27 = phi i32 [ 1, %3 ], [ 1, %19 ], [ 1, %16 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ], [ %25, %22 ]
ret i32 %27
}