#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 */
int /*<<< orphan*/ free(char *);
size_t get_closest_word(char *, char **);
void *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n, n_temp, e_len, i, j;
  char *error_word = NULL;
  scanf("%d", &n);
  char **dict = malloc((n + 1) * sizeof(int *));
  for (i = 0; i < n; i++) {
    scanf("%d", &n_temp);
    dict[i] = malloc((n_temp + 1) * sizeof(int));
    scanf("%s", dict[i]);
  }
  dict[n] = NULL;
  while (1) {
    scanf("%d", &n_temp);
    if (n_temp == -1)
      break;
    free(error_word);
    error_word = malloc((n_temp + 1) * sizeof(char));
    scanf("%s", error_word);
    printf("%s\n", dict[get_closest_word(error_word, dict)]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ff <main+0xaf>
lea    0xe56(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x47>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0xdea(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1230 <main+0xe0>
jmp    1293 <main+0x143>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <get_closest_word@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    (%rax,%rcx,8),%rsi
lea    0xd7d(%rip),%rdi
call   1050 <printf@plt>
jmp    120f <main+0xbf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x4(%rsp),%ebx
lea    0x8(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    11dc <main+0x8c>
lea    0xe74(%rip),%r14
mov    %rsp,%r15
lea    0xe6d(%rip),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%eax
lea    0x4(,%rax,4),%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rbx
cmp    %rbx,%rbp
jl     11a0 <main+0x50>
movslq %ebx,%rax
movq   $0x0,0x0(%r13,%rax,8)
lea    0xe11(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%r14d
cmp    $0xffffffff,%r14d
je     1277 <main+0x127>
lea    0xdfc(%rip),%r15
lea    0xdef(%rip),%r12
mov    %rsp,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xdc5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <get_closest_word@plt>
mov    0x0(%r13,%rax,8),%rsi
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%r14d
cmp    $0xffffffff,%r14d
jne    1220 <main+0xd0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
store i32 0, i32* %1
store i8* null, i8** %7
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
%16 = bitcast i8* %15 to i8**
store i8** %16, i8*** %8
store i32 0, i32* %5
br label %17
17: ; preds = %39, %0
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %42
21: ; preds = %17
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
%29 = load i8**, i8*** %8
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
store i8* %28, i8** %32
%33 = load i8**, i8*** %8
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %21
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %17
42: ; preds = %17
%43 = load i8**, i8*** %8
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
store i8* null, i8** %46
br label %47
47: ; preds = %42, %52
%48 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %47
br label %70
52: ; preds = %47
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 1
%59 = trunc i64 %58 to i32
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %7
%61 = load i8*, i8** %7
%62 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%63 = load i8**, i8*** %8
%64 = load i8*, i8** %7
%65 = load i8**, i8*** %8
%66 = call i64 @get_closest_word(i8* %64, i8** %65)
%67 = getelementptr inbounds i8*, i8** %63, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %68)
br label %47
70: ; preds = %51
ret i32 0
}

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