#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ longest_substring(char *, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  int T;
  int rc;
  int bufsize = 5;
  int BUFFSIZE = 2000;
  char *buffer = malloc(bufsize * sizeof(char));
  if (fgets(buffer, bufsize, stdin) == NULL) {
    printf("Failure to read T\n");
    return (1);
  }
  sscanf(buffer, "%d", &T);
  char *DNA = malloc(BUFFSIZE * sizeof(char));
  char *substring = malloc(BUFFSIZE * sizeof(char));
  int sub_len;
  int dna_len;
  int i;
  for (i = 0; i < T; i++) {
    if (fgets(DNA, 2000, stdin) == NULL) {
      printf("Failure to read DNA sequence!\n");
      return (1);
    }
    DNA[strcspn(DNA, "\n\r")] = '\0';
    dna_len = strlen(DNA);
    if (dna_len == 1) {
      printf("No repetitions found!\n");
    } else {
      longest_substring(DNA, dna_len);
    }
  }
  free(buffer);
  free(DNA);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x1c(%rbp)
movl   $0x7d0,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    11ee <main+0x6e>
lea    0xe23(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f6 <main+0x176>
mov    -0x28(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   10a0 <sscanf@plt>
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12dd <main+0x15d>
mov    -0x30(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    $0x7d0,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1274 <main+0xf4>
lea    0xdb3(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f6 <main+0x176>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x1,-0x40(%rbp)
jne    12be <main+0x13e>
lea    0xd84(%rip),%rdi
call   1050 <printf@plt>
jmp    12ca <main+0x14a>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1080 <longest_substring@plt>
jmp    12cf <main+0x14f>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    122f <main+0xaf>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x5,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    0x2e49(%rip),%r13
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    $0x5,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1263 <main+0xe3>
lea    0xe40(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   10a0 <sscanf@plt>
mov    $0x7d0,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
jle    124f <main+0xcf>
xor    %ebp,%ebp
lea    0xe19(%rip),%r15
lea    0xe15(%rip),%r12
jmp    1213 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <longest_substring@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jge    124f <main+0xcf>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x7d0,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     126c <main+0xec>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    1200 <main+0x80>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    120a <main+0x8a>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    127d <main+0xfd>
lea    0xdd0(%rip),%rdi
jmp    1273 <main+0xf3>
lea    0xda9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [19 x i8] c"Failure to read T\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"Failure to read DNA sequence!\0A\00"
@.str.3 = [3 x i8] c"\0A\0D\00"
@.str.4 = [23 x i8] c"No repetitions found!\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 i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5, i32* %8
store i32 2000, i32* %9
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %10
%21 = load i8*, i8** %10
%22 = load i32, i32* %8
%23 = load i32, i32* @stdin
%24 = call i32* @fgets(i8* %21, i32 %22, i32 %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %76
28: ; preds = %2
%29 = load i8*, i8** %10
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %11
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %12
store i32 0, i32* %15
br label %41
41: ; preds = %68, %28
%42 = load i32, i32* %15
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %71
45: ; preds = %41
%46 = load i8*, i8** %11
%47 = load i32, i32* @stdin
%48 = call i32* @fgets(i8* %46, i32 2000, i32 %47)
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %76
52: ; preds = %45
%53 = load i8*, i8** %11
%54 = load i8*, i8** %11
%55 = call i64 @strcspn(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %11
%58 = call i32 @strlen(i8* %57)
store i32 %58, i32* %14
%59 = load i32, i32* %14
%60 = icmp eq i32 %59, 1
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %67
63: ; preds = %52
%64 = load i8*, i8** %11
%65 = load i32, i32* %14
%66 = call i32 @longest_substring(i8* %64, i32 %65)
br label %67
67: ; preds = %63, %61
br label %68
68: ; preds = %67
%69 = load i32, i32* %15
%70 = add nsw i32 %69, 1
store i32 %70, i32* %15
br label %41
71: ; preds = %41
%72 = load i8*, i8** %10
%73 = call i32 @free(i8* %72)
%74 = load i8*, i8** %11
%75 = call i32 @free(i8* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %71, %50, %26
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"\0A\0D\00"
@str = [22 x i8] c"No repetitions found!\00"
@str.5 = [30 x i8] c"Failure to read DNA sequence!\00"
@str.6 = [18 x i8] c"Failure to read T\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%6 = load i32, i32* @stdin
%7 = tail call i32* @fgets(i8* %5, i32 5, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
br label %39
11: ; preds = %2
%12 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = call dereferenceable_or_null(2000) i8* @malloc(i32 2000)
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %11, %32
%17 = phi i32 [ %33, %32 ], [ 0, %11 ]
%18 = load i32, i32* @stdin
%19 = call i32* @fgets(i8* %13, i32 2000, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
br label %39
23: ; preds = %16
%24 = call i64 @strcspn(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds i8, i8* %13, i64 %24
store i8 0, i8* %25
%26 = call i32 @strlen(i8* %13)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %32
30: ; preds = %23
%31 = call i32 @longest_substring(i8* %13, i32 %26)
br label %32
32: ; preds = %28, %30
%33 = add nuw nsw i32 %17, 1
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %16, label %36
36: ; preds = %32, %11
%37 = call i32 @free(i8* %5)
%38 = call i32 @free(i8* %13)
br label %39
39: ; preds = %21, %36, %9
%40 = phi i32 [ 1, %9 ], [ 1, %21 ], [ 0, %36 ]
ret i32 %40
}