#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 */
scalar_t__ canFormLoop(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int T;
  char line[10000 + 1];
  scanf("%d", &T);
  gets(line);
  while (T) {
    gets(line);
    if (canFormLoop(line))
      printf("LOOP\n");
    else
      printf("NO LOOP\n");
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2720,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x2720(%rbp),%rdi
call   1050 <gets@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c5 <main+0x85>
lea    -0x2720(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x2720(%rbp),%rdi
call   1030 <canFormLoop@plt>
cmp    $0x0,%rax
je     11ab <main+0x6b>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <main+0x77>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <main+0x2e>
xor    %eax,%eax
add    $0x2720,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x2730,%rsp
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
lea    0x10(%rsp),%rdi
call   1050 <gets@plt>
cmpl   $0x0,0xc(%rsp)
je     11b6 <main+0x76>
lea    0x10(%rsp),%rbx
lea    0xe89(%rip),%r14
lea    0xe85(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %rbx,%rdi
call   1040 <canFormLoop@plt>
test   %rax,%rax
mov    %r15,%rdi
cmove  %r14,%rdi
call   1030 <puts@plt>
addl   $0xffffffff,0xc(%rsp)
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"LOOP\0A\00"
@.str.2 = [9 x i8] c"NO LOOP\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10001 x i8]
store i32 0, i32* %1
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = getelementptr inbounds [10001 x i8], [10001 x i8]* %3, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = getelementptr inbounds [10001 x i8], [10001 x i8]* %3, i64 0, i64 0
%12 = call i32 @gets(i8* %11)
%13 = getelementptr inbounds [10001 x i8], [10001 x i8]* %3, i64 0, i64 0
%14 = call i64 @canFormLoop(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %2
%22 = add nsw i32 %21, -1
store i32 %22, i32* %2
br label %7
23: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [8 x i8] c"NO LOOP\00"
@str.3 = [5 x i8] c"LOOP\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10001 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [10001 x i8], [10001 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = call i32 @gets(i8* %4)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %0, %9
%10 = call i32 @gets(i8* %4)
%11 = call i64 @canFormLoop(i8* %4)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @str.3, i64 0, i64 0)
%14 = call i32 @puts(i8* dereferenceable(1) %13)
%15 = load i32, i32* %1
%16 = add nsw i32 %15, -1
store i32 %16, i32* %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %9, %0
ret i32 0
}