#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 */
char getchar();
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ intervalize(char *, int, char *, int);
int kmp_search(char *, int, char *, int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int rc, i;
  int N;
  int M;
  char *song;
  char *snippet;
  size_t bufsize = 400000;
  song = (char *)malloc(bufsize * sizeof(char));
  snippet = (char *)malloc(bufsize * sizeof(char));
  size_t bsize = 20;
  char *buffer = (char *)malloc(bsize * sizeof(char));
  if ((rc = scanf("%d %d", &N, &M)) != 2) {
    return (1);
  }
  while (getchar() != '\n')
    ;
  while ((N != 0) && (M != 0)) {
    int song_len = getline(&song, &bufsize, stdin);
    int snippet_len = getline(&snippet, &bufsize, stdin);
    char text[N - 1];
    char pattern[M - 1];
    intervalize(song, song_len, text, N - 1);
    intervalize(snippet, snippet_len, pattern, M - 1);
    int match = kmp_search(text, N - 1, pattern, M - 1);
    if (match == N - 1) {
      printf("N\n");
    } else {
      printf("S\n");
    }
    if ((rc = scanf("%d %d", &N, &M)) != 2) {
      printf("Scanf failed to read N, M\n");
      printf("rc = %d\n", rc);
      return (1);
    }
    while (getchar() != '\n')
      ;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x61a80,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x14,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
lea    0xe2d(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <scanf@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x2,%eax
je     11f8 <main+0x88>
movl   $0x1,-0x4(%rbp)
jmp    13ed <main+0x27d>
jmp    11fd <main+0x8d>
mov    $0x0,%al
call   1060 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1215 <main+0xa5>
jmp    11fd <main+0x8d>
jmp    121a <main+0xaa>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x71(%rbp)
je     1233 <main+0xc3>
cmpl   $0x0,-0x20(%rbp)
setne  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    1243 <main+0xd3>
jmp    13e6 <main+0x276>
mov    0x2d9e(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    %rsi,-0x98(%rbp)
call   1090 <getline@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
mov    %ecx,-0x4c(%rbp)
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
call   1090 <getline@plt>
mov    %eax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x88(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <intervalize@plt>
mov    -0x80(%rbp),%rdx
mov    -0x30(%rbp),%rdi
mov    -0x50(%rbp),%esi
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <intervalize@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
call   1050 <kmp_search@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1341 <main+0x1d1>
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134f <main+0x1df>
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcaa(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <scanf@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x2,%eax
je     13a1 <main+0x231>
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    13c5 <main+0x255>
jmp    13a6 <main+0x236>
mov    $0x0,%al
call   1060 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     13be <main+0x24e>
jmp    13a6 <main+0x236>
movl   $0x0,-0x70(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x70(%rbp),%eax
test   %eax,%eax
je     13e1 <main+0x271>
jmp    13dc <main+0x26c>
jmp    13ed <main+0x27d>
jmp    121a <main+0xaa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x61a80,-0x48(%rbp)
mov    $0x61a80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x61a80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x14,%edi
call   1080 <malloc@plt>
lea    0xe3a(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1090 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jne    1322 <main+0x1a2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    11f0 <main+0x70>
jmp    12ee <main+0x16e>
cmpl   $0x0,-0x30(%rbp)
je     1322 <main+0x1a2>
mov    0x2dd7(%rip),%rbx
mov    (%rbx),%edx
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%r14
mov    %r14,%rsi
call   10a0 <getline@plt>
mov    %eax,%r13d
mov    (%rbx),%edx
lea    -0x38(%rbp),%rdi
mov    %r14,%rsi
call   10a0 <getline@plt>
mov    %eax,%ebx
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %r13d,%esi
mov    %r12,%rdx
call   1030 <intervalize@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <intervalize@plt>
mov    -0x2c(%rbp),%esi
add    $0xffffffff,%esi
mov    -0x30(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %r12,%rdi
mov    %r14,%rdx
call   1060 <kmp_search@plt>
mov    -0x2c(%rbp),%ecx
add    $0xffffffff,%ecx
cmp    %ecx,%eax
lea    0xd59(%rip),%rdi
lea    0xd6e(%rip),%rax
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xd33(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    12fc <main+0x17c>
nop
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    12e0 <main+0x160>
mov    %r15,%rsp
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
jne    1200 <main+0x80>
jmp    1322 <main+0x1a2>
mov    %eax,%ebx
lea    0xd0c(%rip),%rdi
call   1040 <puts@plt>
lea    0xcf5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rsp
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"N\0A\00"
@.str.2 = [3 x i8] c"S\0A\00"
@.str.3 = [27 x i8] c"Scanf failed to read N, M\0A\00"
@.str.4 = [9 x i8] c"rc = %d\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 i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 400000, i64* %12
%22 = load i64, i64* %12
%23 = mul i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %10
%26 = load i64, i64* %12
%27 = mul i64 %26, 1
%28 = call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %11
store i64 20, i64* %13
%30 = load i64, i64* %13
%31 = mul i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %14
%34 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9)
store i32 %34, i32* %6
%35 = icmp ne i32 %34, 2
br i1 %35, label %36, label %37
36: ; preds = %2
store i32 1, i32* %3
br label %108
37: ; preds = %2
br label %38
38: ; preds = %42, %37
%39 = call signext i8 (...) @getchar()
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %38
br label %38
43: ; preds = %38
br label %44
44: ; preds = %106, %43
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %9
%49 = icmp ne i32 %48, 0
br label %50
50: ; preds = %47, %44
%51 = phi i1 [ false, %44 ], [ %49, %47 ]
br i1 %51, label %52, label %107
52: ; preds = %50
%53 = load i32, i32* @stdin
%54 = call i32 @getline(i8** %10, i64* %12, i32 %53)
store i32 %54, i32* %15
%55 = load i32, i32* @stdin
%56 = call i32 @getline(i8** %11, i64* %12, i32 %55)
store i32 %56, i32* %16
%57 = load i32, i32* %8
%58 = sub nsw i32 %57, 1
%59 = zext i32 %58 to i64
%60 = call i8* @llvm.stacksave()
store i8* %60, i8** %17
%61 = alloca i8, i64 %59
store i64 %59, i64* %18
%62 = load i32, i32* %9
%63 = sub nsw i32 %62, 1
%64 = zext i32 %63 to i64
%65 = alloca i8, i64 %64
store i64 %64, i64* %19
%66 = load i8*, i8** %10
%67 = load i32, i32* %15
%68 = load i32, i32* %8
%69 = sub nsw i32 %68, 1
%70 = call i32 @intervalize(i8* %66, i32 %67, i8* %61, i32 %69)
%71 = load i8*, i8** %11
%72 = load i32, i32* %16
%73 = load i32, i32* %9
%74 = sub nsw i32 %73, 1
%75 = call i32 @intervalize(i8* %71, i32 %72, i8* %65, i32 %74)
%76 = load i32, i32* %8
%77 = sub nsw i32 %76, 1
%78 = load i32, i32* %9
%79 = sub nsw i32 %78, 1
%80 = call i32 @kmp_search(i8* %61, i32 %77, i8* %65, i32 %79)
store i32 %80, i32* %20
%81 = load i32, i32* %20
%82 = load i32, i32* %8
%83 = sub nsw i32 %82, 1
%84 = icmp eq i32 %81, %83
br i1 %84, label %85, label %87
85: ; preds = %52
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %89
87: ; preds = %52
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %89
89: ; preds = %87, %85
%90 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9)
store i32 %90, i32* %6
%91 = icmp ne i32 %90, 2
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%94 = load i32, i32* %6
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %94)
store i32 1, i32* %3
store i32 1, i32* %21
br label %103
96: ; preds = %89
br label %97
97: ; preds = %101, %96
%98 = call signext i8 (...) @getchar()
%99 = sext i8 %98 to i32
%100 = icmp ne i32 %99, 10
br i1 %100, label %101, label %102
101: ; preds = %97
br label %97
102: ; preds = %97
store i32 0, i32* %21
br label %103
103: ; preds = %102, %92
%104 = load i8*, i8** %17
%105 = load i32, i32* %21
switch i32 %105, label %110 [
i32 0, label %106
i32 1, label %108
]
106: ; preds = %103
br label %44
107: ; preds = %50
store i32 0, i32* %3
br label %108
108: ; preds = %107, %103, %36
%109 = load i32, i32* %3
ret i32 %109
110: ; preds = %103
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@stdin = global i32 0
@.str.4 = [9 x i8] c"rc = %d\0A\00"
@str = [2 x i8] c"S\00"
@str.5 = [26 x i8] c"Scanf failed to read N, M\00"
@str.6 = [2 x i8] c"N\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i8** %5 to i8*
%11 = bitcast i8** %6 to i8*
%12 = bitcast i64* %7 to i8*
store i64 400000, i64* %7
%13 = tail call i64 @malloc(i64 400000)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
%15 = tail call i64 @malloc(i64 400000)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = tail call i64 @malloc(i64 20)
%18 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %75
20: ; preds = %2, %20
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %20
23: ; preds = %20
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %75
29: ; preds = %23, %69
%30 = load i32, i32* @stdin
%31 = call i32 @getline(i8** %5, i64* %7, i32 %30)
%32 = load i32, i32* @stdin
%33 = call i32 @getline(i8** %6, i64* %7, i32 %32)
%34 = load i32, i32* %3
%35 = add nsw i32 %34, -1
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
%38 = alloca i8, i64 %36
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
%41 = zext i32 %40 to i64
%42 = alloca i8, i64 %41
%43 = load i8*, i8** %5
%44 = load i32, i32* %3
%45 = add nsw i32 %44, -1
%46 = call i32 @intervalize(i8* %43, i32 %31, i8* %38, i32 %45)
%47 = load i8*, i8** %6
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
%50 = call i32 @intervalize(i8* %47, i32 %33, i8* %42, i32 %49)
%51 = load i32, i32* %3
%52 = add nsw i32 %51, -1
%53 = load i32, i32* %4
%54 = add nsw i32 %53, -1
%55 = call i32 @kmp_search(i8* %38, i32 %52, i8* %42, i32 %54)
%56 = load i32, i32* %3
%57 = add nsw i32 %56, -1
%58 = icmp eq i32 %55, %57
%59 = select i1 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0)
%60 = call i32 @puts(i8* dereferenceable(1) %59)
%61 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%62 = icmp eq i32 %61, 2
br i1 %62, label %66, label %63
63: ; preds = %29
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %61)
br label %75
66: ; preds = %29, %66
%67 = call signext i8 (...) @getchar()
%68 = icmp eq i8 %67, 10
br i1 %68, label %69, label %66
69: ; preds = %66
%70 = load i32, i32* %3
%71 = icmp ne i32 %70, 0
%72 = load i32, i32* %4
%73 = icmp ne i32 %72, 0
%74 = select i1 %71, i1 %73, i1 false
br i1 %74, label %29, label %75
75: ; preds = %69, %23, %63, %2
%76 = phi i32 [ 1, %2 ], [ 1, %63 ], [ 0, %23 ], [ 0, %69 ]
ret i32 %76
}