#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *, int, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
size_t strlen(char const *);
int toupper(char const);
char *moral_regla8(char *result, const char *palabra, const int verbose) {
  const size_t len = strlen(palabra);
  memset(result, 0, 4);
  if (len == 1) {
    snprintf(result, 4, "%cXX", toupper(*palabra));
    if (verbose)
      printf("Aplicando regla 8:\n\t%-20s %cXX\n", palabra, toupper(*palabra));
  } else {
    snprintf(result, 4, "%c%cX", toupper(*palabra), toupper(*(palabra + 1)));
    if (verbose)
      printf("Aplicando regla 8:\n\t%-20s %c%cX\n", palabra, toupper(*palabra),
             toupper(*(palabra + 1)));
  }
  return result;
}


x86 assembly (clang, -O0):
<moral_regla8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
cmpq   $0x1,-0x20(%rbp)
jne    11ef <moral_regla8+0x9f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%ecx
mov    $0x4,%esi
lea    0xe4f(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11ea <moral_regla8+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127a <moral_regla8+0x12a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
mov    $0x4,%esi
lea    0xdfc(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1275 <moral_regla8+0x125>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    %eax,%ecx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127a <moral_regla8+0x12a>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moral_regla8>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%r12d
cmp    $0x1,%rbp
jne    11c7 <moral_regla8+0x77>
lea    0xe6d(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %r15d,%r15d
je     1219 <moral_regla8+0xc9>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1219 <moral_regla8+0xc9>
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe4e(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %r15d,%r15d
je     1219 <moral_regla8+0xc9>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe20(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%cXX\00"
@.str.1 = [32 x i8] c"Aplicando regla 8:\0A\09%-20s %cXX\0A\00"
@.str.2 = [6 x i8] c"%c%cX\00"
@.str.3 = [33 x i8] c"Aplicando regla 8:\0A\09%-20s %c%cX\0A\00"
define i8* @moral_regla8(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %7
%10 = load i8*, i8** %4
%11 = call i32 @memset(i8* %10, i32 0, i32 4)
%12 = load i64, i64* %7
%13 = icmp eq i64 %12, 1
br i1 %13, label %14, label %29
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = call i32 @toupper(i8 signext %17)
%19 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %15, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = call i32 @toupper(i8 signext %25)
%27 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %26)
br label %28
28: ; preds = %22, %14
br label %52
29: ; preds = %3
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = call i32 @toupper(i8 signext %32)
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = call i32 @toupper(i8 signext %36)
%38 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %30, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %37)
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %29
%42 = load i8*, i8** %5
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = call i32 @toupper(i8 signext %44)
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = call i32 @toupper(i8 signext %48)
%50 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 %45, i32 %49)
br label %51
51: ; preds = %41, %29
br label %52
52: ; preds = %51, %28
%53 = load i8*, i8** %4
ret i8* %53
}

LLVM IR (-O2):
@.str = [5 x i8] c"%cXX\00"
@.str.1 = [32 x i8] c"Aplicando regla 8:\0A\09%-20s %cXX\0A\00"
@.str.2 = [6 x i8] c"%c%cX\00"
@.str.3 = [33 x i8] c"Aplicando regla 8:\0A\09%-20s %c%cX\0A\00"
define i8* @moral_regla8(i8* returned %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i32 @memset(i8* %0, i32 0, i32 4)
%6 = icmp eq i64 %4, 1
%7 = load i8, i8* %1
%8 = tail call i32 @toupper(i8 signext %7)
br i1 %6, label %9, label %16
9: ; preds = %3
%10 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = icmp eq i32 %2, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = load i8, i8* %1
%14 = tail call i32 @toupper(i8 signext %13)
%15 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %14)
br label %28
16: ; preds = %3
%17 = getelementptr inbounds i8, i8* %1, i64 1
%18 = load i8, i8* %17
%19 = tail call i32 @toupper(i8 signext %18)
%20 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %19)
%21 = icmp eq i32 %2, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load i8, i8* %1
%24 = tail call i32 @toupper(i8 signext %23)
%25 = load i8, i8* %17
%26 = tail call i32 @toupper(i8 signext %25)
%27 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %24, i32 %26)
br label %28
28: ; preds = %16, %22, %9, %12
ret i8* %0
}