#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(int **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int rand();
int main() {
  int vetor[1000000];
  int i;
  int colidiu = 0;
  int hash;
  memset(&vetor, 0, 5431);
  for (i = 0; i < 2000; i++) {
    hash = ((rand() % (1000000 - 0) + 0) % 5431);
    if (hash == vetor[hash])
      colidiu++;
    vetor[hash] = hash;
  }
  printf("Total de colisões: %d\n", colidiu);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0920,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3d0918(%rbp)
lea    -0x3d0910(%rbp),%rdi
xor    %esi,%esi
mov    $0x1537,%edx
call   1040 <memset@plt>
movl   $0x0,-0x3d0914(%rbp)
cmpl   $0x7d0,-0x3d0914(%rbp)
jge    11ec <main+0xbc>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x0,%eax
mov    $0x1537,%ecx
cltd
idiv   %ecx
mov    %edx,-0x3d091c(%rbp)
mov    -0x3d091c(%rbp),%eax
movslq -0x3d091c(%rbp),%rcx
cmp    -0x3d0910(%rbp,%rcx,4),%eax
jne    11c4 <main+0x94>
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
mov    -0x3d091c(%rbp),%ecx
movslq -0x3d091c(%rbp),%rax
mov    %ecx,-0x3d0910(%rbp,%rax,4)
mov    -0x3d0914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0914(%rbp)
jmp    1169 <main+0x39>
mov    -0x3d0918(%rbp),%esi
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3d0920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x3d0908,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x1537,%edx
call   1040 <memset@plt>
mov    $0x7d0,%ebp
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
cltq
imul   $0x182250cb,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x1537,%ecx,%ecx
sub    %ecx,%eax
cltq
xor    %ecx,%ecx
cmp    (%rsp,%rax,4),%eax
sete   %cl
add    %ecx,%ebx
mov    %eax,(%rsp,%rax,4)
add    $0xffffffff,%ebp
jne    1150 <main+0x20>
lea    0xe52(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3d0908,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Total de colis\C3\B5es: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = bitcast [1000000 x i32]* %2 to i32**
%7 = call i32 @memset(i32** %6, i32 0, i32 5431)
store i32 0, i32* %3
br label %8
8: ; preds = %30, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 2000
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 1000000
%14 = add nsw i32 %13, 0
%15 = srem i32 %14, 5431
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = icmp eq i32 %16, %20
br i1 %21, label %22, label %25
22: ; preds = %11
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %11
%26 = load i32, i32* %5
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %28
store i32 %26, i32* %29
br label %30
30: ; preds = %25
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %8
33: ; preds = %8
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Total de colis\C3\B5es: %d\0A\00"
define i32 @main() {
%1 = alloca [1000000 x i32]
%2 = bitcast [1000000 x i32]* %1 to i8*
%3 = bitcast [1000000 x i32]* %1 to i32**
%4 = call i32 @memset(i32** %3, i32 0, i32 5431)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %17, %5 ]
%7 = phi i32 [ 0, %0 ], [ %16, %5 ]
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 1000000
%10 = srem i32 %9, 5431
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %10, %13
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %7, %15
store i32 %10, i32* %12
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, 2000
br i1 %18, label %19, label %5
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %16)
ret i32 0
}