#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 checkExists(char, char *, int);
int countOcurrences(char *, char, int, int);
int /*<<< orphan*/ printf(char *, char, int);
void validateOcurrences(char *characters, int quantityN, int quantityM) {
  int i, ocurrenceIncrement = 0, maxCharacter = quantityM * quantityN;
  char ocurrencesCharacter[maxCharacter];
  int ocurrencesCount[maxCharacter];
  for (i = 0; i < maxCharacter; i++) {
    char actualCharacter = characters[i];
    int exists =
        checkExists(actualCharacter, ocurrencesCharacter, maxCharacter);
    if (exists == -1) {
      int totalOcurrences =
          countOcurrences(characters, actualCharacter, quantityN, quantityM);
      ocurrencesCharacter[ocurrenceIncrement] = actualCharacter;
      ocurrencesCount[ocurrenceIncrement] = totalOcurrences;
      ocurrenceIncrement++;
      printf("Ocurrence: %c (total %d) \n", actualCharacter, totalOcurrences);
    }
  }
}


x86 assembly (clang, -O0):
<validateOcurrences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1244 <validateOcurrences+0x114>
mov    -0x58(%rbp),%rsi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
mov    -0x1c(%rbp),%edx
movsbl %al,%edi
call   1030 <checkExists@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    1231 <validateOcurrences+0x101>
mov    -0x8(%rbp),%rdi
mov    -0x39(%rbp),%al
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
movsbl %al,%esi
call   1050 <countOcurrences@plt>
mov    -0x58(%rbp),%rcx
mov    %eax,%edx
mov    -0x50(%rbp),%rax
mov    %edx,-0x44(%rbp)
mov    -0x39(%rbp),%sil
movslq -0x18(%rbp),%rdx
mov    %sil,(%rcx,%rdx,1)
mov    -0x44(%rbp),%edx
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x39(%rbp),%al
mov    -0x44(%rbp),%edx
lea    0xdd7(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
jmp    1236 <validateOcurrences+0x106>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a2 <validateOcurrences+0x72>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateOcurrences>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x30(%rbp)
mov    %esi,-0x2c(%rbp)
imul   %esi,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
test   %edx,%edx
jle    11cf <validateOcurrences+0x9f>
mov    %rdi,%r13
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    117c <validateOcurrences+0x4c>
nopl   (%rax)
mov    %r12,%rdx
add    $0x1,%r15
cmp    %r15,%r12
je     11cf <validateOcurrences+0x9f>
movzbl 0x0(%r13,%r15,1),%eax
movsbl %al,%r14d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rdx,%r12
call   1030 <checkExists@plt>
cmp    $0xffffffff,%eax
jne    1170 <validateOcurrences+0x40>
mov    %r13,%rdi
mov    %r14d,%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1050 <countOcurrences@plt>
mov    -0x38(%rbp),%rcx
movslq %ecx,%rcx
mov    %r14b,(%rbx,%rcx,1)
add    $0x1,%ecx
mov    %rcx,-0x38(%rbp)
lea    0xe3d(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1040 <printf@plt>
jmp    1170 <validateOcurrences+0x40>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Ocurrence: %c (total %d) \0A\00"
define void @validateOcurrences(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = mul nsw i32 %16, %17
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %10
%22 = alloca i8, i64 %20
store i64 %20, i64* %11
%23 = load i32, i32* %9
%24 = zext i32 %23 to i64
%25 = alloca i32, i64 %24
store i64 %24, i64* %12
store i32 0, i32* %7
br label %26
26: ; preds = %61, %3
%27 = load i32, i32* %7
%28 = load i32, i32* %9
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %64
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %13
%36 = load i8, i8* %13
%37 = load i32, i32* %9
%38 = call i32 @checkExists(i8 signext %36, i8* %22, i32 %37)
store i32 %38, i32* %14
%39 = load i32, i32* %14
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %60
41: ; preds = %30
%42 = load i8*, i8** %4
%43 = load i8, i8* %13
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = call i32 @countOcurrences(i8* %42, i8 signext %43, i32 %44, i32 %45)
store i32 %46, i32* %15
%47 = load i8, i8* %13
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %22, i64 %49
store i8 %47, i8* %50
%51 = load i32, i32* %15
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %25, i64 %53
store i32 %51, i32* %54
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
%57 = load i8, i8* %13
%58 = load i32, i32* %15
%59 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8 signext %57, i32 %58)
br label %60
60: ; preds = %41, %30
br label %61
61: ; preds = %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %26
64: ; preds = %26
%65 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Ocurrence: %c (total %d) \0A\00"
define void @validateOcurrences(i8* %0, i32 %1, i32 %2) {
%4 = mul i32 %2, %1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %25
8: ; preds = %3, %21
%9 = phi i64 [ %23, %21 ], [ 0, %3 ]
%10 = phi i32 [ %22, %21 ], [ 0, %3 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = call i32 @checkExists(i8 signext %12, i8* %6, i32 %4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = call i32 @countOcurrences(i8* %0, i8 signext %12, i32 %1, i32 %2)
%17 = sext i32 %10 to i64
%18 = getelementptr inbounds i8, i8* %6, i64 %17
store i8 %12, i8* %18
%19 = add nsw i32 %10, 1
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8 signext %12, i32 %16)
br label %21
21: ; preds = %15, %8
%22 = phi i32 [ %19, %15 ], [ %10, %8 ]
%23 = add nuw nsw i64 %9, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %8
25: ; preds = %21, %3
ret void
}