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

/* Variables and functions */
scalar_t__ _sub_digits(char *, int, char *);
int /*<<< orphan*/ 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_sub(char *diff, size_t diff_len, const char *num_l, const char *num_r) {
  char buf_l[sizeof("MMMDCCCCLXXXXVIIII")];
  char buf_r[sizeof("MMMDCCCCLXXXXVIIII")];
  if (!rnc_valid(num_l))
    return 1;
  rnc_denormalize(buf_l, sizeof(buf_l), num_l);
  if (!rnc_valid(num_r))
    return 1;
  rnc_denormalize(buf_r, sizeof(buf_r), num_r);
  if (0 != _sub_digits(buf_l, sizeof(buf_l), buf_r)) {
    return 1;
  }
  rnc_normalize(buf_l, sizeof(buf_l));
  if (stpncpy(diff, buf_l, diff_len) >= diff + diff_len) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rnc_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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
jne    1186 <rnc_sub+0x36>
movl   $0x1,-0x4(%rbp)
jmp    1237 <rnc_sub+0xe7>
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x13,%esi
call   1040 <rnc_denormalize@plt>
mov    -0x28(%rbp),%rdi
call   1050 <rnc_valid@plt>
cmp    $0x0,%eax
jne    11b6 <rnc_sub+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1237 <rnc_sub+0xe7>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x13,%esi
call   1040 <rnc_denormalize@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    $0x13,%esi
call   1070 <_sub_digits@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11f4 <rnc_sub+0xa4>
movl   $0x1,-0x4(%rbp)
jmp    1237 <rnc_sub+0xe7>
lea    -0x40(%rbp),%rdi
mov    $0x13,%esi
call   1030 <rnc_normalize@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <stpncpy@plt>
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jb     1230 <rnc_sub+0xe0>
movl   $0x1,-0x4(%rbp)
jmp    1237 <rnc_sub+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnc_sub>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%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     11eb <rnc_sub+0x9b>
mov    %rsp,%rdi
mov    $0x13,%esi
mov    %rbp,%rdx
call   1040 <rnc_denormalize@plt>
mov    %rbx,%rdi
call   1050 <rnc_valid@plt>
test   %eax,%eax
je     11eb <rnc_sub+0x9b>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x13,%esi
mov    %rbx,%rdx
call   1040 <rnc_denormalize@plt>
mov    %rsp,%rdi
mov    $0x13,%esi
mov    %rbp,%rdx
call   1070 <_sub_digits@plt>
test   %rax,%rax
jne    11eb <rnc_sub+0x9b>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x13,%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
mov    %r12d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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