#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 int32_t;

/* Variables and functions */
scalar_t__ ToUpper(char);
int NaiveSubsequence(char *read, int32_t readLength, char *reference,
                     int32_t referenceLength) {
  int i, j, found;
  for (i = 0; i < referenceLength - readLength + 1; i++) {
    for (j = 0, found = 1; 1 == found && j < readLength; j++) {
      if (ToUpper(read[j]) == ToUpper(reference[i + j])) {
        found = 0;
      }
    }
    if (1 == found) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<NaiveSubsequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11ff <NaiveSubsequence+0xef>
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
xor    %eax,%eax
mov    $0x1,%ecx
cmp    -0x30(%rbp),%ecx
mov    %al,-0x31(%rbp)
jne    116e <NaiveSubsequence+0x5e>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117e <NaiveSubsequence+0x6e>
jmp    11d3 <NaiveSubsequence+0xc3>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ToUpper@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ToUpper@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    11c0 <NaiveSubsequence+0xb0>
movl   $0x0,-0x30(%rbp)
jmp    11c5 <NaiveSubsequence+0xb5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <NaiveSubsequence+0x3f>
mov    $0x1,%eax
cmp    -0x30(%rbp),%eax
jne    11ec <NaiveSubsequence+0xdc>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <NaiveSubsequence+0xf6>
jmp    11f1 <NaiveSubsequence+0xe1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112d <NaiveSubsequence+0x1d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NaiveSubsequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
sub    %esi,%ecx
jl     11a0 <NaiveSubsequence+0x90>
mov    %rdx,%rbp
mov    %rdi,%r13
movslq %esi,%r15
add    $0x1,%ecx
xor    %r14d,%r14d
mov    %rcx,0x10(%rsp)
mov    %esi,0xc(%rsp)
nop
test   %esi,%esi
jle    119d <NaiveSubsequence+0x8d>
mov    $0x1,%r12d
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%r13,%r12,1),%edi
call   1030 <ToUpper@plt>
mov    %rax,%rbx
movsbl -0x1(%rbp,%r12,1),%edi
call   1030 <ToUpper@plt>
cmp    %rax,%rbx
je     117b <NaiveSubsequence+0x6b>
lea    0x1(%r12),%rcx
cmp    %r15,%r12
mov    %rcx,%r12
jl     1150 <NaiveSubsequence+0x40>
cmp    %rax,%rbx
jne    119d <NaiveSubsequence+0x8d>
add    $0x1,%r14
add    $0x1,%rbp
mov    0x10(%rsp),%rcx
cmp    %rcx,%r14
mov    0xc(%rsp),%esi
jne    1140 <NaiveSubsequence+0x30>
mov    $0xffffffff,%eax
jmp    11a0 <NaiveSubsequence+0x90>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NaiveSubsequence(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %13
13: ; preds = %57, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %60
20: ; preds = %13
store i32 0, i32* %11
store i32 1, i32* %12
br label %21
21: ; preds = %48, %20
%22 = load i32, i32* %12
%23 = icmp eq i32 1, %22
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %11
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br label %28
28: ; preds = %24, %21
%29 = phi i1 [ false, %21 ], [ %27, %24 ]
br i1 %29, label %30, label %51
30: ; preds = %28
%31 = load i8*, i8** %6
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i64 @ToUpper(i8 signext %35)
%37 = load i8*, i8** %8
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = add nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
%43 = load i8, i8* %42
%44 = call i64 @ToUpper(i8 signext %43)
%45 = icmp eq i64 %36, %44
br i1 %45, label %46, label %47
46: ; preds = %30
store i32 0, i32* %12
br label %47
47: ; preds = %46, %30
br label %48
48: ; preds = %47
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %21
51: ; preds = %28
%52 = load i32, i32* %12
%53 = icmp eq i32 1, %52
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = load i32, i32* %10
store i32 %55, i32* %5
br label %61
56: ; preds = %51
br label %57
57: ; preds = %56
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %13
60: ; preds = %13
store i32 -1, i32* %5
br label %61
61: ; preds = %60, %54
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
define i32 @NaiveSubsequence(i8* nocapture %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = icmp slt i32 %3, %1
br i1 %5, label %35, label %6
6: ; preds = %4
%7 = icmp sgt i32 %1, 0
%8 = sext i32 %1 to i64
%9 = add i32 %3, 1
%10 = sub i32 %9, %1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %6, %28
%13 = phi i64 [ 0, %6 ], [ %29, %28 ]
br i1 %7, label %14, label %31
14: ; preds = %12, %14
%15 = phi i64 [ %24, %14 ], [ 0, %12 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i64 @ToUpper(i8 signext %17)
%19 = add nuw nsw i64 %15, %13
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = load i8, i8* %20
%22 = tail call i64 @ToUpper(i8 signext %21)
%23 = icmp ne i64 %18, %22
%24 = add nuw nsw i64 %15, 1
%25 = icmp slt i64 %24, %8
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %14, label %27
27: ; preds = %14
br i1 %23, label %33, label %28
28: ; preds = %27
%29 = add nuw nsw i64 %13, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %35, label %12
31: ; preds = %12
%32 = trunc i64 %13 to i32
br label %35
33: ; preds = %27
%34 = trunc i64 %13 to i32
br label %35
35: ; preds = %28, %31, %33, %4
%36 = phi i32 [ -1, %4 ], [ %32, %31 ], [ %34, %33 ], [ -1, %28 ]
ret i32 %36
}