#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 **findWords(char **, int, int, char **, int, int *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  int i;
  int row = 2;
  int col = 2;
  char **board = malloc(row * sizeof(char *));
  board[0] = malloc(col);
  board[0][0] = 'a';
  board[0][1] = 'b';
  board[1] = malloc(col);
  board[1][0] = 'a';
  board[1][1] = 'a';
  int size = 7;
  char **words = malloc(size * sizeof(char *));
  words[0] = malloc(5);
  words[1] = malloc(5);
  words[2] = malloc(5);
  words[3] = malloc(5);
  words[4] = malloc(5);
  words[5] = malloc(5);
  words[6] = malloc(5);
  strcpy(words[0], "aba");
  strcpy(words[1], "baa");
  strcpy(words[2], "bab");
  strcpy(words[3], "aaab");
  strcpy(words[4], "aaa");
  strcpy(words[5], "aaaa");
  strcpy(words[6], "aaba");
  int count = 0;
  char **lists = findWords(board, row, col, words, size, &count);
  for (i = 0; i < count; i++) {
    printf("%s\n", lists[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x61,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x62,0x1(%rax)
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movb   $0x61,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movb   $0x61,0x1(%rax)
movl   $0x7,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd98(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd71(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd61(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd51(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd43(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xd2e(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    0x30(%rax),%rdi
lea    0xd1f(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    -0x2c(%rbp),%r9
call   1050 <findWords@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1357 <main+0x217>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcd3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1325 <main+0x1e5>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x20(%rsp)
mov    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
movw   $0x6261,(%rax)
mov    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rbx)
movw   $0x6161,(%rax)
mov    $0x38,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x8(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x10(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x18(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x20(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rax,0x28(%rbx)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %rax,0x30(%rbx)
lea    0xe00(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xdde(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
lea    0xdd3(%rip),%rsi
mov    %r13,%rdi
call   1030 <strcpy@plt>
lea    0xdc8(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xdbf(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xdaf(%rip),%rsi
mov    0x18(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xda3(%rip),%rsi
mov    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r9
mov    0x20(%rsp),%rdi
mov    $0x2,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
mov    $0x7,%r8d
call   1050 <findWords@plt>
cmpl   $0x0,0xc(%rsp)
jle    12da <main+0x19a>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xd61(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     12c0 <main+0x180>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"aba\00"
@.str.1 = [4 x i8] c"baa\00"
@.str.2 = [4 x i8] c"bab\00"
@.str.3 = [5 x i8] c"aaab\00"
@.str.4 = [4 x i8] c"aaa\00"
@.str.5 = [5 x i8] c"aaaa\00"
@.str.6 = [5 x i8] c"aaba\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8**
store i32 0, i32* %1
store i32 2, i32* %3
store i32 2, i32* %4
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
%15 = bitcast i8* %14 to i8**
store i8** %15, i8*** %5
%16 = load i32, i32* %4
%17 = call i8* @malloc(i32 %16)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
store i8* %17, i8** %19
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 97, i8* %23
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 98, i8* %27
%28 = load i32, i32* %4
%29 = call i8* @malloc(i32 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
store i8* %29, i8** %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 97, i8* %35
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8 97, i8* %39
store i32 7, i32* %6
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = mul i64 %41, 8
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
%45 = bitcast i8* %44 to i8**
store i8** %45, i8*** %7
%46 = call i8* @malloc(i32 5)
%47 = load i8**, i8*** %7
%48 = getelementptr inbounds i8*, i8** %47, i64 0
store i8* %46, i8** %48
%49 = call i8* @malloc(i32 5)
%50 = load i8**, i8*** %7
%51 = getelementptr inbounds i8*, i8** %50, i64 1
store i8* %49, i8** %51
%52 = call i8* @malloc(i32 5)
%53 = load i8**, i8*** %7
%54 = getelementptr inbounds i8*, i8** %53, i64 2
store i8* %52, i8** %54
%55 = call i8* @malloc(i32 5)
%56 = load i8**, i8*** %7
%57 = getelementptr inbounds i8*, i8** %56, i64 3
store i8* %55, i8** %57
%58 = call i8* @malloc(i32 5)
%59 = load i8**, i8*** %7
%60 = getelementptr inbounds i8*, i8** %59, i64 4
store i8* %58, i8** %60
%61 = call i8* @malloc(i32 5)
%62 = load i8**, i8*** %7
%63 = getelementptr inbounds i8*, i8** %62, i64 5
store i8* %61, i8** %63
%64 = call i8* @malloc(i32 5)
%65 = load i8**, i8*** %7
%66 = getelementptr inbounds i8*, i8** %65, i64 6
store i8* %64, i8** %66
%67 = load i8**, i8*** %7
%68 = getelementptr inbounds i8*, i8** %67, i64 0
%69 = load i8*, i8** %68
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%71 = load i8**, i8*** %7
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 @strcpy(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%75 = load i8**, i8*** %7
%76 = getelementptr inbounds i8*, i8** %75, i64 2
%77 = load i8*, i8** %76
%78 = call i32 @strcpy(i8* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%79 = load i8**, i8*** %7
%80 = getelementptr inbounds i8*, i8** %79, i64 3
%81 = load i8*, i8** %80
%82 = call i32 @strcpy(i8* %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%83 = load i8**, i8*** %7
%84 = getelementptr inbounds i8*, i8** %83, i64 4
%85 = load i8*, i8** %84
%86 = call i32 @strcpy(i8* %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%87 = load i8**, i8*** %7
%88 = getelementptr inbounds i8*, i8** %87, i64 5
%89 = load i8*, i8** %88
%90 = call i32 @strcpy(i8* %89, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%91 = load i8**, i8*** %7
%92 = getelementptr inbounds i8*, i8** %91, i64 6
%93 = load i8*, i8** %92
%94 = call i32 @strcpy(i8* %93, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %8
%95 = load i8**, i8*** %5
%96 = load i32, i32* %3
%97 = load i32, i32* %4
%98 = load i8**, i8*** %7
%99 = load i32, i32* %6
%100 = call i8** @findWords(i8** %95, i32 %96, i32 %97, i8** %98, i32 %99, i32* %8)
store i8** %100, i8*** %9
store i32 0, i32* %2
br label %101
101: ; preds = %112, %0
%102 = load i32, i32* %2
%103 = load i32, i32* %8
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %115
105: ; preds = %101
%106 = load i8**, i8*** %9
%107 = load i32, i32* %2
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8*, i8** %106, i64 %108
%110 = load i8*, i8** %109
%111 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %110)
br label %112
112: ; preds = %105
%113 = load i32, i32* %2
%114 = add nsw i32 %113, 1
store i32 %114, i32* %2
br label %101
115: ; preds = %101
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"aba\00"
@.str.1 = [4 x i8] c"baa\00"
@.str.2 = [4 x i8] c"bab\00"
@.str.3 = [5 x i8] c"aaab\00"
@.str.4 = [4 x i8] c"aaa\00"
@.str.5 = [5 x i8] c"aaaa\00"
@.str.6 = [5 x i8] c"aaba\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%3 = bitcast i8* %2 to i8**
%4 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
store i8* %4, i8** %3
store i8 97, i8* %4
%5 = getelementptr inbounds i8, i8* %4, i64 1
store i8 98, i8* %5
%6 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%7 = getelementptr inbounds i8*, i8** %3, i64 1
store i8* %6, i8** %7
store i8 97, i8* %6
%8 = getelementptr inbounds i8, i8* %6, i64 1
store i8 97, i8* %8
%9 = tail call dereferenceable_or_null(56) i8* @malloc(i32 56)
%10 = bitcast i8* %9 to i8**
%11 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
store i8* %11, i8** %10
%12 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%13 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* %12, i8** %13
%14 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%15 = getelementptr inbounds i8*, i8** %10, i64 2
store i8* %14, i8** %15
%16 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%17 = getelementptr inbounds i8*, i8** %10, i64 3
store i8* %16, i8** %17
%18 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%19 = getelementptr inbounds i8*, i8** %10, i64 4
store i8* %18, i8** %19
%20 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%21 = getelementptr inbounds i8*, i8** %10, i64 5
store i8* %20, i8** %21
%22 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%23 = getelementptr inbounds i8*, i8** %10, i64 6
store i8* %22, i8** %23
%24 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%31 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%32 = call i8** @findWords(i8** %3, i32 2, i32 2, i8** %10, i32 7, i32* %1)
%33 = load i32, i32* %1
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %0, %35
%36 = phi i64 [ %40, %35 ], [ 0, %0 ]
%37 = getelementptr inbounds i8*, i8** %32, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %38)
%40 = add nuw nsw i64 %36, 1
%41 = load i32, i32* %1
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %35, label %44
44: ; preds = %35, %0
ret i32 0
}