#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__ isalpha(char);
size_t strnlen(char *, size_t const);
char toupper(char);
void cleanRomanNumeral(char *romanNumeral, size_t *romanNumeralLength,
                       const size_t romanNumeralSizeInBytes) {
  int romanNumeralSourceIndex = 0;
  int romanNumeralDestinationIndex = 0;
  char currentCharacter = '\0';
  (*romanNumeralLength) = strnlen(romanNumeral, romanNumeralSizeInBytes);
  for (romanNumeralSourceIndex = 0;
       romanNumeralSourceIndex < (*romanNumeralLength);
       romanNumeralSourceIndex++) {
    currentCharacter = romanNumeral[romanNumeralSourceIndex];
    if (isalpha(currentCharacter)) {
      romanNumeral[romanNumeralDestinationIndex++] = toupper(currentCharacter);
    }
  }
  romanNumeral[romanNumeralDestinationIndex] = '\0';
  (*romanNumeralLength) = romanNumeralDestinationIndex;
}


x86 assembly (clang, -O0):
<cleanRomanNumeral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strnlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jae    11d9 <cleanRomanNumeral+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11c6 <cleanRomanNumeral+0x96>
movsbl -0x21(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11cb <cleanRomanNumeral+0x9b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1174 <cleanRomanNumeral+0x44>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanRomanNumeral>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rsi
call   1040 <strnlen@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     118e <cleanRomanNumeral+0x5e>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1169 <cleanRomanNumeral+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,(%r14)
jbe    1191 <cleanRomanNumeral+0x61>
movsbl (%r15,%rbx,1),%ebp
mov    %ebp,%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1160 <cleanRomanNumeral+0x30>
mov    %ebp,%edi
call   1030 <toupper@plt>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %al,(%r15,%rcx,1)
jmp    1160 <cleanRomanNumeral+0x30>
xor    %r12d,%r12d
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cleanRomanNumeral(i8* %0, i64* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i8 0, i8* %9
%10 = load i8*, i8** %4
%11 = load i64, i64* %6
%12 = call i64 @strnlen(i8* %10, i64 %11)
%13 = load i64*, i64** %5
store i64 %12, i64* %13
store i32 0, i32* %7
br label %14
14: ; preds = %38, %3
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = load i64*, i64** %5
%18 = load i64, i64* %17
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %41
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %9
%26 = load i8, i8* %9
%27 = call i64 @isalpha(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %20
%30 = load i8, i8* %9
%31 = call signext i8 @toupper(i8 signext %30)
%32 = load i8*, i8** %4
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
br label %37
37: ; preds = %29, %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %14
41: ; preds = %14
%42 = load i8*, i8** %4
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = load i64*, i64** %5
store i64 %47, i64* %48
ret void
}

LLVM IR (-O2):
define void @cleanRomanNumeral(i8* nocapture %0, i64* nocapture %1, i64 %2) {
%4 = tail call i64 @strnlen(i8* %0, i64 %2)
store i64 %4, i64* %1
%5 = icmp eq i64 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %3, %18
%7 = phi i64 [ %20, %18 ], [ 0, %3 ]
%8 = phi i32 [ %19, %18 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @isalpha(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = tail call signext i8 @toupper(i8 signext %10)
%15 = add nsw i32 %8, 1
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %14, i8* %17
br label %18
18: ; preds = %6, %13
%19 = phi i32 [ %15, %13 ], [ %8, %6 ]
%20 = add nuw i64 %7, 1
%21 = load i64, i64* %1
%22 = icmp ugt i64 %21, %20
br i1 %22, label %6, label %23
23: ; preds = %18, %3
%24 = phi i32 [ 0, %3 ], [ %19, %18 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 0, i8* %26
store i64 %25, i64* %1
ret void
}