#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 */
typedef int /*<<< orphan*/ buf_sum;
typedef int /*<<< orphan*/ buf_r;
typedef int /*<<< orphan*/ buf_l;

/* Variables and functions */
scalar_t__ _merge_sorted(char *, int, char *, char *);
scalar_t__ rnc_denormalize(char *, int, char const *);
int /*<<< orphan*/ rnc_normalize(char *, int);
int /*<<< orphan*/ rnc_valid(char const *);
char *stpncpy(char *, char *, size_t);
int rnc_add(char *sum, size_t sumlen, const char *raw_l, const char *raw_r) {
  char buf_l[sizeof("MMMDCCCCLXXXXVIIII")];
  char buf_r[sizeof("MMMDCCCCLXXXXVIIII")];
  char buf_sum[sizeof("MDCCCCLXXXXVIIIIMDCCCCLXXXXVIIII")];
  if (!rnc_valid(raw_l) || 0 != rnc_denormalize(buf_l, sizeof(buf_l), raw_l))
    return 1;
  if (!rnc_valid(raw_r) || 0 != rnc_denormalize(buf_r, sizeof(buf_r), raw_r))
    return 1;
  if (0 != _merge_sorted(buf_sum, sizeof(buf_sum), buf_l, buf_r))
    return 1;
  rnc_normalize(buf_sum, sizeof(buf_sum));
  if (stpncpy(sum, buf_sum, sumlen) >= sum + sumlen) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rnc_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <rnc_valid@plt>
cmp    $0x0,%eax
je     119d <rnc_add+0x4d>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x13,%esi
call   1040 <rnc_denormalize@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11a9 <rnc_add+0x59>
movl   $0x1,-0x4(%rbp)
jmp    1263 <rnc_add+0x113>
mov    -0x28(%rbp),%rdi
call   1050 <rnc_valid@plt>
cmp    $0x0,%eax
je     11db <rnc_add+0x8b>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x13,%esi
call   1040 <rnc_denormalize@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11e7 <rnc_add+0x97>
movl   $0x1,-0x4(%rbp)
jmp    1263 <rnc_add+0x113>
lea    -0x90(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rcx
mov    $0x21,%esi
call   1070 <_merge_sorted@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     121a <rnc_add+0xca>
movl   $0x1,-0x4(%rbp)
jmp    1263 <rnc_add+0x113>
lea    -0x90(%rbp),%rdi
mov    $0x21,%esi
call   1030 <rnc_normalize@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <stpncpy@plt>
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jb     125c <rnc_add+0x10c>
movl   $0x1,-0x4(%rbp)
jmp    1263 <rnc_add+0x113>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnc_add>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1050 <rnc_valid@plt>
mov    $0x1,%r12d
test   %eax,%eax
je     1191 <rnc_add+0x41>
lea    0x20(%rsp),%rdi
mov    $0x13,%esi
mov    %rbp,%rdx
call   1040 <rnc_denormalize@plt>
test   %rax,%rax
je     11a1 <rnc_add+0x51>
mov    %r12d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <rnc_valid@plt>
test   %eax,%eax
je     1191 <rnc_add+0x41>
mov    %rsp,%rdi
mov    $0x13,%esi
mov    %rbx,%rdx
call   1040 <rnc_denormalize@plt>
test   %rax,%rax
jne    1191 <rnc_add+0x41>
lea    0x40(%rsp),%rdi
lea    0x20(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x21,%esi
call   1070 <_merge_sorted@plt>
test   %rax,%rax
jne    1191 <rnc_add+0x41>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x21,%esi
call   1030 <rnc_normalize@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <stpncpy@plt>
add    %r14,%r15
xor    %r12d,%r12d
cmp    %r15,%rax
setae  %r12b
jmp    1191 <rnc_add+0x41>

LLVM IR (-O0):
define i32 @rnc_add(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [19 x i8]
%11 = alloca [19 x i8]
%12 = alloca [33 x i8]
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %8
%14 = call i32 @rnc_valid(i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %10, i64 0, i64 0
%18 = load i8*, i8** %8
%19 = call i64 @rnc_denormalize(i8* %17, i32 19, i8* %18)
%20 = icmp ne i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %16, %4
store i32 1, i32* %5
br label %52
22: ; preds = %16
%23 = load i8*, i8** %9
%24 = call i32 @rnc_valid(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%28 = load i8*, i8** %9
%29 = call i64 @rnc_denormalize(i8* %27, i32 19, i8* %28)
%30 = icmp ne i64 0, %29
br i1 %30, label %31, label %32
31: ; preds = %26, %22
store i32 1, i32* %5
br label %52
32: ; preds = %26
%33 = getelementptr inbounds [33 x i8], [33 x i8]* %12, i64 0, i64 0
%34 = getelementptr inbounds [19 x i8], [19 x i8]* %10, i64 0, i64 0
%35 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%36 = call i64 @_merge_sorted(i8* %33, i32 33, i8* %34, i8* %35)
%37 = icmp ne i64 0, %36
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 1, i32* %5
br label %52
39: ; preds = %32
%40 = getelementptr inbounds [33 x i8], [33 x i8]* %12, i64 0, i64 0
%41 = call i32 @rnc_normalize(i8* %40, i32 33)
%42 = load i8*, i8** %6
%43 = getelementptr inbounds [33 x i8], [33 x i8]* %12, i64 0, i64 0
%44 = load i64, i64* %7
%45 = call i8* @stpncpy(i8* %42, i8* %43, i64 %44)
%46 = load i8*, i8** %6
%47 = load i64, i64* %7
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = icmp uge i8* %45, %48
br i1 %49, label %50, label %51
50: ; preds = %39
store i32 1, i32* %5
br label %52
51: ; preds = %39
store i32 0, i32* %5
br label %52
52: ; preds = %51, %50, %38, %31, %21
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
define i32 @rnc_add(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca [19 x i8]
%6 = alloca [19 x i8]
%7 = alloca [33 x i8]
%8 = getelementptr inbounds [19 x i8], [19 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [19 x i8], [19 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [33 x i8], [33 x i8]* %7, i64 0, i64 0
%11 = tail call i32 @rnc_valid(i8* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %4
%14 = call i64 @rnc_denormalize(i8* %8, i32 19, i8* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = call i32 @rnc_valid(i8* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %16
%20 = call i64 @rnc_denormalize(i8* %9, i32 19, i8* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = call i64 @_merge_sorted(i8* %10, i32 33, i8* %8, i8* %9)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i32 @rnc_normalize(i8* %10, i32 33)
%27 = call i8* @stpncpy(i8* %0, i8* %10, i64 %1)
%28 = getelementptr inbounds i8, i8* %0, i64 %1
%29 = icmp uge i8* %27, %28
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %25, %22, %16, %19, %4, %13
%32 = phi i32 [ 1, %13 ], [ 1, %4 ], [ 1, %19 ], [ 1, %16 ], [ 1, %22 ], [ %30, %25 ]
ret i32 %32
}