#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 unsigned int uint64_t;
typedef unsigned int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ *calloc(unsigned int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *generateRandomData(unsigned int);
int /*<<< orphan*/ hasSubstringOfLength(unsigned int, int *, unsigned int,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int);
int *readDataFromFile(char *, unsigned int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  bool test = false;
  if (argc != 2) {
    fprintf(stderr, "Usage: findlongest file\n"
                    "       findlongest --test\n");
    return 1;
  }
  if (!strcmp(argv[1], "--test")) {
    test = true;
  }
  uint64_t dataLen;
  bool *data;
  if (test) {
    dataLen = 1u << 24u;
    data = generateRandomData(dataLen);
  } else {
    data = readDataFromFile(argv[1], &dataLen);
  }
  uint8_t *stringsSeen = calloc((uint64_t)1 << (34u - 3u), sizeof(uint8_t));
  uint32_t len;
  for (len = 4u; len <= 34u; len++) {
    if (!hasSubstringOfLength(len, data, dataLen, stringsSeen)) {
      printf("Maximum substring is %u long\n", len - 1u);
      return 0;
    }
  }
  printf("Maximum substring is at least %u long\n", 34u);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11dc <main+0x6c>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11fe <main+0x8e>
movl   $0x1000000,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <generateRandomData@plt>
mov    %rax,-0x20(%rbp)
jmp    1213 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <readDataFromFile@plt>
mov    %rax,-0x20(%rbp)
mov    $0x80000000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x4,-0x2c(%rbp)
cmpl   $0x22,-0x2c(%rbp)
ja     1284 <main+0x114>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1090 <hasSubstringOfLength@plt>
cmp    $0x0,%eax
jne    1271 <main+0x101>
mov    -0x2c(%rbp),%esi
sub    $0x1,%esi
lea    0xdda(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129c <main+0x12c>
jmp    1276 <main+0x106>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    122d <main+0xbd>
lea    0xdcd(%rip),%rdi
mov    $0x22,%esi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11a3 <main+0x33>
mov    0x8(%rsi),%rbx
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11bf <main+0x4f>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <readDataFromFile@plt>
jmp    11d1 <main+0x61>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    122e <main+0xbe>
movl   $0x1000000,0xc(%rsp)
01
mov    $0x1000000,%edi
call   1050 <generateRandomData@plt>
mov    %rax,%r14
mov    $0x4,%ebp
mov    $0x80000000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1090 <hasSubstringOfLength@plt>
test   %eax,%eax
je     121b <main+0xab>
add    $0x1,%ebp
cmp    $0x23,%ebp
jne    11f0 <main+0x80>
lea    0xe44(%rip),%rdi
mov    $0x22,%esi
jmp    1227 <main+0xb7>
add    $0xffffffff,%ebp
lea    0xe15(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: findlongest file\0A findlongest --test\0A\00"
@.str.1 = [7 x i8] c"--test\00"
@.str.2 = [30 x i8] c"Maximum substring is %u long\0A\00"
@.str.3 = [39 x i8] c"Maximum substring is at least %u long\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %56
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 1, i32* %6
br label %23
23: ; preds = %22, %16
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
store i32 16777216, i32* %7
%27 = load i32, i32* %7
%28 = call i32* @generateRandomData(i32 %27)
store i32* %28, i32** %8
br label %34
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @readDataFromFile(i8* %32, i32* %7)
store i32* %33, i32** %8
br label %34
34: ; preds = %29, %26
%35 = call i32* @calloc(i32 -2147483648, i32 4)
store i32* %35, i32** %9
store i32 4, i32* %10
br label %36
36: ; preds = %51, %34
%37 = load i32, i32* %10
%38 = icmp ule i32 %37, 34
br i1 %38, label %39, label %54
39: ; preds = %36
%40 = load i32, i32* %10
%41 = load i32*, i32** %8
%42 = load i32, i32* %7
%43 = load i32*, i32** %9
%44 = call i32 @hasSubstringOfLength(i32 %40, i32* %41, i32 %42, i32* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %39
%47 = load i32, i32* %10
%48 = sub i32 %47, 1
%49 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 0, i32* %3
br label %56
50: ; preds = %39
br label %51
51: ; preds = %50
%52 = load i32, i32* %10
%53 = add i32 %52, 1
store i32 %53, i32* %10
br label %36
54: ; preds = %36
%55 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 34)
store i32 0, i32* %3
br label %56
56: ; preds = %54, %46, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: findlongest file\0A findlongest --test\0A\00"
@.str.1 = [7 x i8] c"--test\00"
@.str.2 = [30 x i8] c"Maximum substring is %u long\0A\00"
@.str.3 = [39 x i8] c"Maximum substring is at least %u long\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %35
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
%13 = bitcast i32* %3 to i8*
br i1 %12, label %14, label %16
14: ; preds = %8
store i32 16777216, i32* %3
%15 = tail call i32* @generateRandomData(i32 16777216)
br label %18
16: ; preds = %8
%17 = call i32* @readDataFromFile(i8* %10, i32* %3)
br label %18
18: ; preds = %16, %14
%19 = phi i32* [ %15, %14 ], [ %17, %16 ]
%20 = call i32* @calloc(i32 -2147483648, i32 4)
br label %21
21: ; preds = %18, %29
%22 = phi i32 [ 4, %18 ], [ %30, %29 ]
%23 = load i32, i32* %3
%24 = call i32 @hasSubstringOfLength(i32 %22, i32* %19, i32 %23, i32* %20)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = add nsw i32 %22, -1
%28 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %34
29: ; preds = %21
%30 = add nuw nsw i32 %22, 1
%31 = icmp eq i32 %30, 35
br i1 %31, label %32, label %21
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 34)
br label %34
34: ; preds = %32, %26
br label %35
35: ; preds = %34, %5
%36 = phi i32 [ 1, %5 ], [ 0, %34 ]
ret i32 %36
}