#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';
    printf("DNA: %s\n", DNA);
    dna_len = strlen(DNA);
    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    11f0 <main+0x70>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x28(%rbp),%rdi
lea    0xe18(%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    12d3 <main+0x153>
mov    -0x30(%rbp),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    $0x7d0,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1278 <main+0xf8>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1080 <longest_substring@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1231 <main+0xb1>
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   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x2e39(%rip),%r13
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    $0x5,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     1271 <main+0xe1>
lea    0xe30(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   10b0 <sscanf@plt>
mov    $0x7d0,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
jle    125d <main+0xcd>
lea    0xe0b(%rip),%r15
lea    0xe07(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x7d0,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     127a <main+0xea>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <longest_substring@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1210 <main+0x80>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    128b <main+0xfb>
lea    0xdb5(%rip),%rdi
jmp    1281 <main+0xf1>
lea    0xd8e(%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 = [9 x i8] c"DNA: %s\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 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %72
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 = %64, %28
%42 = load i32, i32* %15
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %67
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 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %72
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 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = load i8*, i8** %11
%60 = call i32 @strlen(i8* %59)
store i32 %60, i32* %14
%61 = load i8*, i8** %11
%62 = load i32, i32* %14
%63 = call i32 @longest_substring(i8* %61, i32 %62)
br label %64
64: ; preds = %52
%65 = load i32, i32* %15
%66 = add nsw i32 %65, 1
store i32 %66, i32* %15
br label %41
67: ; preds = %41
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %11
%71 = call i32 @free(i8* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %67, %50, %26
%73 = load i32, i32* %3
ret i32 %73
}

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.4 = [9 x i8] c"DNA: %s\0A\00"
@str = [30 x i8] c"Failure to read DNA sequence!\00"
@str.5 = [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.5, i64 0, i64 0))
br label %35
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 %32
16: ; preds = %11, %23
%17 = phi i32 [ %29, %23 ], [ 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, i64 0, i64 0))
br label %35
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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%27 = call i32 @strlen(i8* %13)
%28 = call i32 @longest_substring(i8* %13, i32 %27)
%29 = add nuw nsw i32 %17, 1
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %16, label %32
32: ; preds = %23, %11
%33 = call i32 @free(i8* %5)
%34 = call i32 @free(i8* %13)
br label %35
35: ; preds = %21, %32, %9
%36 = phi i32 [ 1, %9 ], [ 1, %21 ], [ 0, %32 ]
ret i32 %36
}