#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_regla7(char *result, const char *palabra, const int verbose) {
  const size_t len = strlen(palabra);
  memset(result, 0, 4);
  if (len >= 3) {
    if (verbose)
      printf("Aplicando regla 7:\n\t%-20s %c%c%c\n", palabra, toupper(*palabra),
             toupper(*(palabra + 1)), toupper(*(palabra + 2)));
    snprintf(result, 4, "%c%c%c", toupper(*palabra), toupper(*(palabra + 1)),
             toupper(*(palabra + 2)));
  } else if (len == 2) {
    if (verbose)
      printf("Aplicando regla 7, y regla 8 (agregando una X al final de la "
             "clave):\n\t%-20s %c%c\n",
             palabra, toupper(*palabra), toupper(*(palabra + 1)));
    snprintf(result, 4, "%c%cX", toupper(*palabra), toupper(*(palabra + 1)));
  } else {
    if (verbose)
      printf("Aplicando regla 7, y regla 8 (agregando dos letras X al final de "
             "la clave):\n\t%-20s %c\n",
             palabra, toupper(*palabra));
    snprintf(result, 4, "%cXX", toupper(*palabra));
  }
  return result;
}


x86 assembly (clang, -O0):
<moral_regla7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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   $0x3,-0x20(%rbp)
jb     123e <moral_regla7+0xee>
cmpl   $0x0,-0x14(%rbp)
je     11e4 <moral_regla7+0x94>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <toupper@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <toupper@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    %eax,%r9d
mov    $0x4,%esi
lea    0xdf0(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1338 <moral_regla7+0x1e8>
cmpq   $0x2,-0x20(%rbp)
jne    12d4 <moral_regla7+0x184>
cmpl   $0x0,-0x14(%rbp)
je     128e <moral_regla7+0x13e>
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    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    %eax,%r8d
mov    $0x4,%esi
lea    0xdb3(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1333 <moral_regla7+0x1e3>
cmpl   $0x0,-0x14(%rbp)
je     1306 <moral_regla7+0x1b6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%ecx
mov    $0x4,%esi
lea    0xdac(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1338 <moral_regla7+0x1e8>
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moral_regla7>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
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>
cmp    $0x3,%rbp
jb     1204 <moral_regla7+0xb4>
test   %r15d,%r15d
je     11c1 <moral_regla7+0x71>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%r15d
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x2(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%r15d
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x2(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe3b(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    12a7 <moral_regla7+0x157>
cmp    $0x2,%rbp
jne    1267 <moral_regla7+0x117>
test   %r15d,%r15d
je     1237 <moral_regla7+0xe7>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe00(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
lea    0xe2a(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    12a7 <moral_regla7+0x157>
test   %r15d,%r15d
je     1287 <moral_regla7+0x137>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
lea    0xe06(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
lea    0xe42(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Aplicando regla 7:\0A\09%-20s %c%c%c\0A\00"
@.str.1 = [7 x i8] c"%c%c%c\00"
@.str.2 = [82 x i8] c"Aplicando regla 7, y regla 8 (agregando una X al final de la clave):\0A\09%-20s %c%c\0A\00"
@.str.3 = [6 x i8] c"%c%cX\00"
@.str.4 = [87 x i8] c"Aplicando regla 7, y regla 8 (agregando dos letras X al final de la clave):\0A\09%-20s %c\0A\00"
@.str.5 = [5 x i8] c"%cXX\00"
define i8* @moral_regla7(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 uge i64 %12, 3
br i1 %13, label %14, label %45
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = call i32 @toupper(i8 signext %20)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = call i32 @toupper(i8 signext %24)
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = load i8, i8* %27
%29 = call i32 @toupper(i8 signext %28)
%30 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %21, i32 %25, i32 %29)
br label %31
31: ; preds = %17, %14
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = call i32 @toupper(i8 signext %34)
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
%39 = call i32 @toupper(i8 signext %38)
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = load i8, i8* %41
%43 = call i32 @toupper(i8 signext %42)
%44 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %32, i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %39, i32 %43)
br label %87
45: ; preds = %3
%46 = load i64, i64* %7
%47 = icmp eq i64 %46, 2
br i1 %47, label %48, label %71
48: ; preds = %45
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %48
%52 = load i8*, i8** %5
%53 = load i8*, i8** %5
%54 = load i8, i8* %53
%55 = call i32 @toupper(i8 signext %54)
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8, i8* %57
%59 = call i32 @toupper(i8 signext %58)
%60 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i8* %52, i32 %55, i32 %59)
br label %61
61: ; preds = %51, %48
%62 = load i8*, i8** %4
%63 = load i8*, i8** %5
%64 = load i8, i8* %63
%65 = call i32 @toupper(i8 signext %64)
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = call i32 @toupper(i8 signext %68)
%70 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %62, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %65, i32 %69)
br label %86
71: ; preds = %45
%72 = load i32, i32* %6
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %71
%75 = load i8*, i8** %5
%76 = load i8*, i8** %5
%77 = load i8, i8* %76
%78 = call i32 @toupper(i8 signext %77)
%79 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.4, i64 0, i64 0), i8* %75, i32 %78)
br label %80
80: ; preds = %74, %71
%81 = load i8*, i8** %4
%82 = load i8*, i8** %5
%83 = load i8, i8* %82
%84 = call i32 @toupper(i8 signext %83)
%85 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %81, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %80, %61
br label %87
87: ; preds = %86, %31
%88 = load i8*, i8** %4
ret i8* %88
}

LLVM IR (-O2):
@.str = [34 x i8] c"Aplicando regla 7:\0A\09%-20s %c%c%c\0A\00"
@.str.1 = [7 x i8] c"%c%c%c\00"
@.str.2 = [82 x i8] c"Aplicando regla 7, y regla 8 (agregando una X al final de la clave):\0A\09%-20s %c%c\0A\00"
@.str.3 = [6 x i8] c"%c%cX\00"
@.str.4 = [87 x i8] c"Aplicando regla 7, y regla 8 (agregando dos letras X al final de la clave):\0A\09%-20s %c\0A\00"
@.str.5 = [5 x i8] c"%cXX\00"
define i8* @moral_regla7(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 ugt i64 %4, 2
br i1 %6, label %7, label %29
7: ; preds = %3
%8 = icmp eq i32 %2, 0
br i1 %8, label %19, label %9
9: ; preds = %7
%10 = load i8, i8* %1
%11 = tail call i32 @toupper(i8 signext %10)
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = load i8, i8* %12
%14 = tail call i32 @toupper(i8 signext %13)
%15 = getelementptr inbounds i8, i8* %1, i64 2
%16 = load i8, i8* %15
%17 = tail call i32 @toupper(i8 signext %16)
%18 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %11, i32 %14, i32 %17)
br label %19
19: ; preds = %9, %7
%20 = load i8, i8* %1
%21 = tail call i32 @toupper(i8 signext %20)
%22 = getelementptr inbounds i8, i8* %1, i64 1
%23 = load i8, i8* %22
%24 = tail call i32 @toupper(i8 signext %23)
%25 = getelementptr inbounds i8, i8* %1, i64 2
%26 = load i8, i8* %25
%27 = tail call i32 @toupper(i8 signext %26)
%28 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24, i32 %27)
br label %56
29: ; preds = %3
%30 = icmp eq i64 %4, 2
%31 = icmp eq i32 %2, 0
br i1 %30, label %32, label %47
32: ; preds = %29
br i1 %31, label %40, label %33
33: ; preds = %32
%34 = load i8, i8* %1
%35 = tail call i32 @toupper(i8 signext %34)
%36 = getelementptr inbounds i8, i8* %1, i64 1
%37 = load i8, i8* %36
%38 = tail call i32 @toupper(i8 signext %37)
%39 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %35, i32 %38)
br label %40
40: ; preds = %33, %32
%41 = load i8, i8* %1
%42 = tail call i32 @toupper(i8 signext %41)
%43 = getelementptr inbounds i8, i8* %1, i64 1
%44 = load i8, i8* %43
%45 = tail call i32 @toupper(i8 signext %44)
%46 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %45)
br label %56
47: ; preds = %29
br i1 %31, label %52, label %48
48: ; preds = %47
%49 = load i8, i8* %1
%50 = tail call i32 @toupper(i8 signext %49)
%51 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %50)
br label %52
52: ; preds = %48, %47
%53 = load i8, i8* %1
%54 = tail call i32 @toupper(i8 signext %53)
%55 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %40, %52, %19
ret i8* %0
}