#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 */
scalar_t__ hash_table_is_present(char *);
int hash_table_search(char *);
char *malloc(int);
char *strcpy(char *, char *);
int strlen(char *);
char *better_candidate(char *word, char **possibles, int index) {
  if (hash_table_is_present(word)) {
    return word;
  }
  int max_occurence = 0;
  int occurence = 0;
  int index_corr_word = -1;
  for (int i = 0; i < index; i++) {
    occurence = hash_table_search(*(possibles + i));
    if (occurence > max_occurence) {
      index_corr_word = i;
      max_occurence = occurence;
    }
  }
  if (index_corr_word == -1)
    return word;
  char *corr = malloc(sizeof(char) * (strlen(word) + 2));
  return strcpy(corr, *(possibles + index_corr_word));
}


x86 assembly (clang, -O0):
<better_candidate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <hash_table_is_present@plt>
cmp    $0x0,%rax
je     1183 <better_candidate+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1237 <better_candidate+0xe7>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ea <better_candidate+0x9a>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <hash_table_search@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11d7 <better_candidate+0x87>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11dc <better_candidate+0x8c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <better_candidate+0x4f>
cmpl   $0xffffffff,-0x28(%rbp)
jne    1201 <better_candidate+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1237 <better_candidate+0xe7>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<better_candidate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
call   1070 <hash_table_is_present@plt>
test   %rax,%rax
jne    11c3 <better_candidate+0x73>
test   %ebp,%ebp
jle    11c3 <better_candidate+0x73>
mov    %ebp,%r12d
xor    %ebx,%ebx
mov    $0xffffffff,%r13d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15,%rbx,8),%rdi
call   1050 <hash_table_search@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
cmovg  %ebx,%r13d
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <better_candidate+0x30>
cmp    $0xffffffff,%r13d
je     11c3 <better_candidate+0x73>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movslq %r13d,%rax
mov    (%r15,%rax,8),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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