#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned long,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memcmp(char *, char *, int);
int /*<<< orphan*/ printError(char *);
int /*<<< orphan*/ printf(char *, ...);
void findFiles(char *workfile, int *matrix, int *filecounter) {
  FILE *workfp;
  char *filebuffer = malloc(65536);
  char signature[] = "CRYO_APC";
  int sigsize = 8, counter = 0;
  unsigned long seekposition = 0, filesize = 0;
  int i = 0;
  printf("BigExtract: searching for collisions in %s\n", workfile);
  printf("BigExtract: signature size is %d bytes\n", sigsize);
  if ((workfp = fopen(workfile, "rb")) == NULL) {
    printError("error while opening file");
  }
  fseek(workfp, 0, SEEK_END);
  if ((filesize = ftell(workfp)) == 0) {
    printError("file size was zero");
  }
  fseek(workfp, 0, SEEK_SET);
  while (seekposition < filesize - 65536) {
    fseek(workfp, seekposition, SEEK_SET);
    fread(filebuffer, 1, 65536, workfp);
    for (i = 0; i < 65536; i++) {
      if (!memcmp(filebuffer + i, signature, sigsize)) {
        matrix[counter] = seekposition + i;
        counter++;
      }
    }
    seekposition += 65536;
  }
  free(filebuffer);
  fclose(workfp);
  printf("BigExtract: %d collisions detected\n", counter);
  *filecounter = counter;
}


x86 assembly (clang, -O0):
<findFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x10000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0xe37(%rip),%rax
mov    %rax,-0x31(%rbp)
mov    0xe35(%rip),%al
mov    %al,-0x29(%rbp)
movl   $0x8,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1248 <findFiles+0xa8>
lea    0xe1d(%rip),%rdi
call   10c0 <printError@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1281 <findFiles+0xe1>
lea    0xdfd(%rip),%rdi
call   10c0 <printError@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    $0x10000,%rcx
cmp    %rcx,%rax
jae    1357 <findFiles+0x1b7>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    0x2d1a(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x10000,-0x54(%rbp)
jge    1344 <findFiles+0x1a4>
mov    -0x28(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
lea    -0x31(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%eax
jne    1331 <findFiles+0x191>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
add    %rcx,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1336 <findFiles+0x196>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12e3 <findFiles+0x143>
mov    -0x48(%rbp),%rax
add    $0x10000,%rax
mov    %rax,-0x48(%rbp)
jmp    1297 <findFiles+0xf7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x3c(%rbp),%esi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x10000,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
movabs $0x4350415f4f595243,%rax
41 50 43
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe44(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1220 <findFiles+0x80>
lea    0xe45(%rip),%rdi
call   10c0 <printError@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r12,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1251 <findFiles+0xb1>
lea    0xe2d(%rip),%rdi
call   10c0 <printError@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
add    $0xffffffffffff0000,%rbp
mov    %rbp,0x20(%rsp)
je     1312 <findFiles+0x172>
xor    %r14d,%r14d
mov    %rsp,%rbp
xor    %ebx,%ebx
mov    %r12,0x18(%rsp)
jmp    12a3 <findFiles+0x103>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x10000,%r14
cmp    0x20(%rsp),%r14
mov    0x18(%rsp),%r12
jae    1312 <findFiles+0x172>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   10a0 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
xor    %r12d,%r12d
jmp    12ed <findFiles+0x14d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    $0x10000,%r12
je     1290 <findFiles+0xf0>
lea    (%r12,%r13,1),%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1070 <memcmp@plt>
test   %eax,%eax
jne    12e0 <findFiles+0x140>
movslq %ebx,%rbx
lea    (%r14,%r12,1),%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%ebx
jmp    12e0 <findFiles+0x140>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xd63(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.findFiles.signature = [9 x i8] c"CRYO_APC\00"
@.str = [44 x i8] c"BigExtract: searching for collisions in %s\0A\00"
@.str.1 = [40 x i8] c"BigExtract: signature size is %d bytes\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [25 x i8] c"error while opening file\00"
@SEEK_END = global i32 0
@.str.4 = [19 x i8] c"file size was zero\00"
@SEEK_SET = global i32 0
@.str.5 = [36 x i8] c"BigExtract: %d collisions detected\0A\00"
define void @findFiles(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [9 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%15 = call i8* @malloc(i32 65536)
store i8* %15, i8** %8
%16 = bitcast [9 x i8]* %9 to i8*
store i32 8, i32* %10
store i32 0, i32* %11
store i64 0, i64* %12
store i64 0, i64* %13
store i32 0, i32* %14
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %10
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %3
%25 = call i32 @printError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %3
%27 = load i32*, i32** %7
%28 = load i32, i32* @SEEK_END
%29 = call i32 @fseek(i32* %27, i64 0, i32 %28)
%30 = load i32*, i32** %7
%31 = call i64 @ftell(i32* %30)
store i64 %31, i64* %13
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @printError(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = load i32*, i32** %7
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i64 0, i32 %37)
br label %39
39: ; preds = %80, %35
%40 = load i64, i64* %12
%41 = load i64, i64* %13
%42 = sub i64 %41, 65536
%43 = icmp ult i64 %40, %42
br i1 %43, label %44, label %83
44: ; preds = %39
%45 = load i32*, i32** %7
%46 = load i64, i64* %12
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @fseek(i32* %45, i64 %46, i32 %47)
%49 = load i8*, i8** %8
%50 = load i32*, i32** %7
%51 = call i32 @fread(i8* %49, i32 1, i32 65536, i32* %50)
store i32 0, i32* %14
br label %52
52: ; preds = %77, %44
%53 = load i32, i32* %14
%54 = icmp slt i32 %53, 65536
br i1 %54, label %55, label %80
55: ; preds = %52
%56 = load i8*, i8** %8
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%61 = load i32, i32* %10
%62 = call i32 @memcmp(i8* %59, i8* %60, i32 %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %76, label %64
64: ; preds = %55
%65 = load i64, i64* %12
%66 = load i32, i32* %14
%67 = sext i32 %66 to i64
%68 = add i64 %65, %67
%69 = trunc i64 %68 to i32
%70 = load i32*, i32** %5
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 %69, i32* %73
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %76
76: ; preds = %64, %55
br label %77
77: ; preds = %76
%78 = load i32, i32* %14
%79 = add nsw i32 %78, 1
store i32 %79, i32* %14
br label %52
80: ; preds = %52
%81 = load i64, i64* %12
%82 = add i64 %81, 65536
store i64 %82, i64* %12
br label %39
83: ; preds = %39
%84 = load i8*, i8** %8
%85 = call i32 @free(i8* %84)
%86 = load i32*, i32** %7
%87 = call i32 @fclose(i32* %86)
%88 = load i32, i32* %11
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %11
%91 = load i32*, i32** %6
store i32 %90, i32* %91
ret void
}

LLVM IR (-O2):
@__const.findFiles.signature = [9 x i8] c"CRYO_APC\00"
@.str = [44 x i8] c"BigExtract: searching for collisions in %s\0A\00"
@.str.1 = [40 x i8] c"BigExtract: signature size is %d bytes\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [25 x i8] c"error while opening file\00"
@SEEK_END = global i32 0
@.str.4 = [19 x i8] c"file size was zero\00"
@SEEK_SET = global i32 0
@.str.5 = [36 x i8] c"BigExtract: %d collisions detected\0A\00"
define void @findFiles(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [9 x i8]
%5 = tail call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 8)
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @printError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %9, i64 0, i32 %14)
%16 = tail call i64 @ftell(i32* %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @printError(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %9, i64 0, i32 %21)
%23 = add i64 %16, -65536
%24 = icmp eq i64 %23, 0
br i1 %24, label %50, label %25
25: ; preds = %20, %47
%26 = phi i64 [ %48, %47 ], [ 0, %20 ]
%27 = phi i32 [ %44, %47 ], [ 0, %20 ]
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %9, i64 %26, i32 %28)
%30 = call i32 @fread(i8* %5, i32 1, i32 65536, i32* %9)
br label %31
31: ; preds = %25, %43
%32 = phi i64 [ 0, %25 ], [ %45, %43 ]
%33 = phi i32 [ %27, %25 ], [ %44, %43 ]
%34 = getelementptr inbounds i8, i8* %5, i64 %32
%35 = call i32 @memcmp(i8* %34, i8* %6, i32 8)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = add i64 %32, %26
%39 = sext i32 %33 to i64
%40 = getelementptr inbounds i32, i32* %1, i64 %39
%41 = trunc i64 %38 to i32
store i32 %41, i32* %40
%42 = add nsw i32 %33, 1
br label %43
43: ; preds = %31, %37
%44 = phi i32 [ %33, %31 ], [ %42, %37 ]
%45 = add nuw nsw i64 %32, 1
%46 = icmp eq i64 %45, 65536
br i1 %46, label %47, label %31
47: ; preds = %43
%48 = add i64 %26, 65536
%49 = icmp ult i64 %48, %23
br i1 %49, label %25, label %50
50: ; preds = %47, %20
%51 = phi i32 [ 0, %20 ], [ %44, %47 ]
%52 = call i32 @free(i8* %5)
%53 = call i32 @fclose(i32* %9)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %51)
store i32 %51, i32* %2
ret void
}