#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 getCharInPosition(int, int, char *);
int strlen(char *);
bool wordSearch(int row, int col, int d_row, int d_col, char *word,
                char *array) {
  for (int i = 0; i < strlen(word); i++) {
    if (word[i] != getCharInPosition(row, col, array)) {
      return false;
    }
    row += d_row;
    col += d_col;
  }
  return true;
}


x86 assembly (clang, -O0):
<wordSearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    11b9 <wordSearch+0x99>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <getCharInPosition@plt>
mov    %al,%cl
mov    -0x34(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
je     1199 <wordSearch+0x79>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <wordSearch+0xa0>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1143 <wordSearch+0x23>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wordSearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbx
mov    %ecx,0xc(%rsp)
mov    %edx,%r13d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %r8,%rdi
call   1030 <strlen@plt>
mov    $0x1,%ecx
test   %eax,%eax
jle    119c <wordSearch+0x7c>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%r12,1),%r14d
mov    %r15d,%edi
mov    %ebp,%esi
mov    0x10(%rsp),%rdx
call   1040 <getCharInPosition@plt>
cmp    %al,%r14b
jne    119a <wordSearch+0x7a>
add    %r13d,%r15d
add    0xc(%rsp),%ebp
add    $0x1,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r12
jl     1160 <wordSearch+0x40>
mov    $0x1,%ecx
jmp    119c <wordSearch+0x7c>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wordSearch(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i32 0, i32* %14
br label %15
15: ; preds = %41, %6
%16 = load i32, i32* %14
%17 = load i8*, i8** %12
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %44
20: ; preds = %15
%21 = load i8*, i8** %12
%22 = load i32, i32* %14
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = load i8*, i8** %13
%30 = call signext i8 @getCharInPosition(i32 %27, i32 %28, i8* %29)
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %26, %31
br i1 %32, label %33, label %34
33: ; preds = %20
store i32 0, i32* %7
br label %45
34: ; preds = %20
%35 = load i32, i32* %10
%36 = load i32, i32* %8
%37 = add nsw i32 %36, %35
store i32 %37, i32* %8
%38 = load i32, i32* %11
%39 = load i32, i32* %9
%40 = add nsw i32 %39, %38
store i32 %40, i32* %9
br label %41
41: ; preds = %34
%42 = load i32, i32* %14
%43 = add nsw i32 %42, 1
store i32 %43, i32* %14
br label %15
44: ; preds = %15
store i32 1, i32* %7
br label %45
45: ; preds = %44, %33
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
define i32 @wordSearch(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = tail call i32 @strlen(i8* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6, %17
%10 = phi i64 [ %20, %17 ], [ 0, %6 ]
%11 = phi i32 [ %18, %17 ], [ %0, %6 ]
%12 = phi i32 [ %19, %17 ], [ %1, %6 ]
%13 = getelementptr inbounds i8, i8* %4, i64 %10
%14 = load i8, i8* %13
%15 = tail call signext i8 @getCharInPosition(i32 %11, i32 %12, i8* %5)
%16 = icmp eq i8 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %9
%18 = add nsw i32 %11, %2
%19 = add nsw i32 %12, %3
%20 = add nuw nsw i64 %10, 1
%21 = tail call i32 @strlen(i8* %4)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %9, label %24
24: ; preds = %17, %9, %6
%25 = phi i32 [ 1, %6 ], [ 0, %9 ], [ 1, %17 ]
ret i32 %25
}