#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 /*<<< orphan*/ word_buffer;
typedef size_t ssize_t;

/* Variables and functions */
char *find_best_word_aux(char **, size_t, size_t, size_t, char *, int,
                         int /*<<< orphan*/, int *);
int /*<<< orphan*/ free(char *);
char *find_best_word(char **board, size_t board_dim) {
  static char word_buffer[1024];
  int best_score = -1;
  char *word = NULL;
  ssize_t i, j;
  for (i = 0; i < board_dim; i++) {
    for (j = 0; j < board_dim; j++) {
      int score;
      char *w = find_best_word_aux(board, board_dim, i, j, word_buffer,
                                   sizeof(word_buffer), 0, &score);
      if (score > best_score) {
        free(word);
        word = w;
        best_score = score;
      } else {
        free(w);
      }
    }
  }
  return word;
}


x86 assembly (clang, -O0):
<find_best_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1200 <find_best_word+0xe0>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ea <find_best_word+0xca>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0x2ebe(%rip),%r8
mov    $0x400,%r9d
xor    %eax,%eax
lea    -0x34(%rbp),%rax
movl   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <find_best_word_aux@plt>
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11cb <find_best_word+0xab>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <find_best_word+0xb4>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    11d9 <find_best_word+0xb9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    115d <find_best_word+0x3d>
jmp    11ef <find_best_word+0xcf>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1147 <find_best_word+0x27>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_best_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
test   %rsi,%rsi
je     11b9 <find_best_word+0x99>
mov    %rsi,%rbx
mov    $0xffffffff,%r14d
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    1159 <find_best_word+0x39>
nopl   (%rax)
add    $0x1,%r15
cmp    %rbx,%r15
je     11bc <find_best_word+0x9c>
xor    %ebp,%ebp
jmp    1171 <find_best_word+0x51>
nopl   (%rax)
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1150 <find_best_word+0x30>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
lea    0x2eba(%rip),%r8
mov    $0x400,%r9d
lea    0xc(%rsp),%rax
push   %rax
push   $0x0
call   1040 <find_best_word_aux@plt>
add    $0x10,%rsp
mov    %rax,%r13
cmp    %r14d,0xc(%rsp)
jle    1160 <find_best_word+0x40>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%r14d
mov    %r13,%r12
jmp    1168 <find_best_word+0x48>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@find_best_word.word_buffer = internal global [1024 x i8] zeroinitializer
define i8* @find_best_word(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i8** %0, i8*** %3
store i64 %1, i64* %4
store i32 -1, i32* %5
store i8* null, i8** %6
store i64 0, i64* %7
br label %11
11: ; preds = %42, %2
%12 = load i64, i64* %7
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %45
15: ; preds = %11
store i64 0, i64* %8
br label %16
16: ; preds = %38, %15
%17 = load i64, i64* %8
%18 = load i64, i64* %4
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load i8**, i8*** %3
%22 = load i64, i64* %4
%23 = load i64, i64* %7
%24 = load i64, i64* %8
%25 = call i8* @find_best_word_aux(i8** %21, i64 %22, i64 %23, i64 %24, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @find_best_word.word_buffer, i64 0, i64 0), i32 1024, i32 0, i32* %9)
store i8* %25, i8** %10
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %20
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %10
store i8* %32, i8** %6
%33 = load i32, i32* %9
store i32 %33, i32* %5
br label %37
34: ; preds = %20
%35 = load i8*, i8** %10
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %29
br label %38
38: ; preds = %37
%39 = load i64, i64* %8
%40 = add i64 %39, 1
store i64 %40, i64* %8
br label %16
41: ; preds = %16
br label %42
42: ; preds = %41
%43 = load i64, i64* %7
%44 = add i64 %43, 1
store i64 %44, i64* %7
br label %11
45: ; preds = %11
%46 = load i8*, i8** %6
ret i8* %46
}

LLVM IR (-O2):
@find_best_word.word_buffer = internal global [1024 x i8] zeroinitializer
define i8* @find_best_word(i8** %0, i64 %1) {
%3 = alloca i32
%4 = icmp eq i64 %1, 0
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %5, %28
%8 = phi i32 [ -1, %5 ], [ %25, %28 ]
%9 = phi i64 [ 0, %5 ], [ %29, %28 ]
%10 = phi i8* [ null, %5 ], [ %24, %28 ]
br label %11
11: ; preds = %7, %23
%12 = phi i32 [ %8, %7 ], [ %25, %23 ]
%13 = phi i64 [ 0, %7 ], [ %26, %23 ]
%14 = phi i8* [ %10, %7 ], [ %24, %23 ]
%15 = call i8* @find_best_word_aux(i8** %0, i64 %1, i64 %9, i64 %13, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @find_best_word.word_buffer, i64 0, i64 0), i32 1024, i32 0, i32* %3)
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, %12
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = call i32 @free(i8* %14)
%20 = load i32, i32* %3
br label %23
21: ; preds = %11
%22 = call i32 @free(i8* %15)
br label %23
23: ; preds = %21, %18
%24 = phi i8* [ %15, %18 ], [ %14, %21 ]
%25 = phi i32 [ %20, %18 ], [ %12, %21 ]
%26 = add nuw i64 %13, 1
%27 = icmp eq i64 %26, %1
br i1 %27, label %28, label %11
28: ; preds = %23
%29 = add nuw i64 %9, 1
%30 = icmp eq i64 %29, %1
br i1 %30, label %31, label %7
31: ; preds = %28, %2
%32 = phi i8* [ null, %2 ], [ %24, %28 ]
ret i8* %32
}