#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  uint8_t *data = malloc(3008290);
  FILE *file = fopen("random.data", "r");
  fread(data, 300829, 10, file);
  fclose(file);
  int a, b, c = 0, dups = 0;
  for (a = 1; a < 300829; a++) {
    if (++c == 1000) {
      printf("%i\n", a);
      c = 0;
    }
    for (b = 0; b < a; b++) {
      if (!memcmp(&data[b * 10], &data[a * 10], 10)) {
        dups++;
        printf("dup\n");
      }
    }
  }
  free(data);
  printf("dups: %i\n", dups);
  printf("OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2de722,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4971d,%esi
mov    $0xa,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x4971d,-0x1c(%rbp)
jge    1297 <main+0x127>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x3e8,%eax
jne    1212 <main+0xa2>
mov    -0x1c(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1284 <main+0x114>
mov    -0x10(%rbp),%rdi
imul   $0xa,-0x20(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
imul   $0xa,-0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0xa,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%eax
jne    1271 <main+0x101>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1276 <main+0x106>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1219 <main+0xa9>
jmp    1289 <main+0x119>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <main+0x69>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%esi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x2de722,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe61(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x4971d,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %r14d,%r14d
mov    $0x1,%r15d
mov    $0x28,%r12d
xor    %ebp,%ebp
jmp    11f5 <main+0x75>
xchg   %ax,%ax
add    $0x1,%r15
add    $0x28,%r12
cmp    $0x4971d,%r15
mov    0x4(%rsp),%ebp
je     1260 <main+0xe0>
add    $0x1,%ebp
cmp    $0x3e8,%ebp
jne    1213 <main+0x93>
xor    %ebp,%ebp
lea    0xe0b(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,0x4(%rsp)
lea    (%r15,%r15,4),%rax
lea    (%rbx,%rax,8),%rbp
xor    %r13d,%r13d
jmp    1239 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x28,%r13
cmp    %r13,%r12
je     11e0 <main+0x60>
lea    (%rbx,%r13,1),%rdi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1080 <memcmp@plt>
test   %eax,%eax
jne    1230 <main+0xb0>
add    $0x1,%r14d
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
jmp    1230 <main+0xb0>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd9f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd98(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"random.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%i\0A\00"
@.str.3 = [5 x i8] c"dup\0A\00"
@.str.4 = [10 x i8] c"dups: %i\0A\00"
@.str.5 = [4 x i8] c"OK\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @malloc(i32 3008290)
store i32* %8, i32** %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %2
%11 = load i32*, i32** %3
%12 = call i32 @fread(i32* %10, i32 300829, i32 10, i32* %11)
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %4
br label %15
15: ; preds = %52, %0
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 300829
br i1 %17, label %18, label %55
18: ; preds = %15
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = icmp eq i32 %20, 1000
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 0, i32* %6
br label %25
25: ; preds = %22, %18
store i32 0, i32* %5
br label %26
26: ; preds = %48, %25
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %51
30: ; preds = %26
%31 = load i32*, i32** %2
%32 = load i32, i32* %5
%33 = mul nsw i32 %32, 10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %31, i64 %34
%36 = load i32*, i32** %2
%37 = load i32, i32* %4
%38 = mul nsw i32 %37, 10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
%41 = call i32 @memcmp(i32* %35, i32* %40, i32 10)
%42 = icmp ne i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %30
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %43, %30
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %26
51: ; preds = %26
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %15
55: ; preds = %15
%56 = load i32*, i32** %2
%57 = call i32 @free(i32* %56)
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"random.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%i\0A\00"
@.str.4 = [10 x i8] c"dups: %i\0A\00"
@str = [3 x i8] c"OK\00"
@str.6 = [4 x i8] c"dup\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 3008290)
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @fread(i32* %1, i32 300829, i32 10, i32* %2)
%4 = tail call i32 @fclose(i32* %2)
br label %5
5: ; preds = %0, %32
%6 = phi i64 [ 1, %0 ], [ %33, %32 ]
%7 = phi i32 [ 0, %0 ], [ %29, %32 ]
%8 = phi i32 [ 0, %0 ], [ %15, %32 ]
%9 = add nsw i32 %8, 1
%10 = icmp eq i32 %9, 1000
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = trunc i64 %6 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ 0, %11 ], [ %9, %5 ]
%16 = mul nuw nsw i64 %6, 10
%17 = getelementptr inbounds i32, i32* %1, i64 %16
br label %18
18: ; preds = %14, %28
%19 = phi i64 [ 0, %14 ], [ %30, %28 ]
%20 = phi i32 [ %7, %14 ], [ %29, %28 ]
%21 = mul nuw nsw i64 %19, 10
%22 = getelementptr inbounds i32, i32* %1, i64 %21
%23 = tail call i32 @memcmp(i32* %22, i32* %17, i32 10)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = add nsw i32 %20, 1
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.6, i64 0, i64 0))
br label %28
28: ; preds = %18, %25
%29 = phi i32 [ %20, %18 ], [ %26, %25 ]
%30 = add nuw nsw i64 %19, 1
%31 = icmp eq i64 %30, %6
br i1 %31, label %32, label %18
32: ; preds = %28
%33 = add nuw nsw i64 %6, 1
%34 = icmp eq i64 %33, 300829
br i1 %34, label %35, label %5
35: ; preds = %32
%36 = tail call i32 @free(i32* %1)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret i32 0
}