int knight_tour(int x, int y, int start_x, int start_y) {
  int i = 0;
  int sol[y * x][2];
  char **map = malloc(sizeof(char *) * y);
  if (!map)
    return (1);
  while (i < y) {
    map[i] = malloc(sizeof(char) * (x + 1));
    memset(map[i], '0', x);
    map[i++][x] = '\0';
  }
  sol[0][0] = start_x, sol[0][1] = start_y;
  map[sol[0][1]][sol[0][0]] = 'K';
  if (kt_solve(map, sol, x, y, 0))
    print_solution(map, sol, x, y);
  else
    printf("%s\n", "The knight tour is not possible.\n");
  i = 0;
  while (i < y)
    free(map[i++]);
  free(map);
  return (1);
}


x86 assembly (clang, -O0):
<knight_tour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   %ecx,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d7 <knight_tour+0x77>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12fe <knight_tour+0x19e>
jmp    11dc <knight_tour+0x7c>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1246 <knight_tour+0xe6>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
movslq -0x8(%rbp),%rdx
mov    $0x30,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11dc <knight_tour+0x7c>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%eax
mov    %eax,(%rsi)
mov    -0x14(%rbp),%eax
mov    %eax,0x4(%rsi)
mov    -0x30(%rbp),%rax
movslq 0x4(%rsi),%rcx
mov    (%rax,%rcx,8),%rax
movslq (%rsi),%rcx
movb   $0x4b,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %r8d,%r8d
mov    $0x0,%al
call   1060 <kt_solve@plt>
cmp    $0x0,%eax
je     129f <knight_tour+0x13f>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1080 <print_solution@plt>
jmp    12b4 <knight_tour+0x154>
lea    0xd5a(%rip),%rdi
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e7 <knight_tour+0x187>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
jmp    12bb <knight_tour+0x15b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<knight_tour>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%eax
imul   %edi,%eax
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
movslq %esi,%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     129a <knight_tour+0x13a>
mov    %rax,%rcx
mov    %r13d,-0x2c(%rbp)
mov    %r12d,-0x30(%rbp)
mov    %rbx,-0x40(%rbp)
lea    0x1(%r15),%eax
cltq
mov    %rax,-0x50(%rbp)
mov    %r15,-0x48(%rbp)
movslq %r15d,%r15
mov    %r14d,-0x34(%rbp)
mov    %r14d,%ebx
xor    %r12d,%r12d
mov    %rcx,%r13
nopl   0x0(%rax)
mov    -0x50(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x0(%r13,%r12,8)
mov    %rax,%rdi
mov    $0x30,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
add    $0x1,%r12
movb   $0x0,(%r14,%r15,1)
cmp    %r12,%rbx
jne    11e0 <knight_tour+0x80>
mov    %rbx,%r12
movslq -0x2c(%rbp),%rax
mov    %r13,%r14
mov    0x0(%r13,%rax,8),%rcx
mov    -0x40(%rbp),%rbx
mov    -0x30(%rbp),%edx
mov    %edx,(%rbx)
mov    %eax,0x4(%rbx)
movslq %edx,%rax
movb   $0x4b,(%rcx,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    -0x48(%rbp),%r13
mov    %r13d,%edx
mov    -0x34(%rbp),%r15d
mov    %r15d,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <kt_solve@plt>
test   %eax,%eax
je     126d <knight_tour+0x10d>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1080 <print_solution@plt>
test   %r15d,%r15d
jg     127e <knight_tour+0x11e>
jmp    1292 <knight_tour+0x132>
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
jle    1292 <knight_tour+0x132>
xor    %ebx,%ebx
mov    (%r14,%rbx,8),%rdi
add    $0x1,%rbx
call   1030 <free@plt>
cmp    %rbx,%r12
jne    1280 <knight_tour+0x120>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [34 x i8] c"The knight tour is not possible.\0A\00"
define i32 @knight_tour(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %1, %0
%6 = zext i32 %5 to i64
%7 = alloca [2 x i32], i64 %6
%8 = sext i32 %1 to i64
%9 = shl nsw i64 %8, 3
%10 = tail call i8* @malloc(i64 %9)
%11 = bitcast i8* %10 to i8**
%12 = icmp eq i8* %10, null
br i1 %12, label %50, label %13
13: ; preds = %4
%14 = icmp sgt i32 %1, 0
%15 = add nsw i32 %0, 1
%16 = sext i32 %15 to i64
%17 = sext i32 %0 to i64
%18 = zext i32 %1 to i64
br label %19
19: ; preds = %13, %19
%20 = phi i64 [ 0, %13 ], [ %23, %19 ]
%21 = tail call i8* @malloc(i64 %16)
%22 = getelementptr inbounds i8*, i8** %11, i64 %20
store i8* %21, i8** %22
tail call void @llvm.memset.p0i8.i64(i8* align 1 %21, i8 48, i64 %17, i1 false)
%23 = add nuw nsw i64 %20, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %17
store i8 0, i8* %24
%25 = icmp eq i64 %23, %18
br i1 %25, label %26, label %19
26: ; preds = %19
%27 = sext i32 %3 to i64
%28 = getelementptr inbounds i8*, i8** %11, i64 %27
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %2, i32* %30
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %3, i32* %31
%32 = sext i32 %2 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 75, i8* %33
%34 = call i32 (i8**, [2 x i32]*, i32, i32, i32, ...) bitcast (i32 (...)* @kt_solve to i32 (i8**, [2 x i32]*, i32, i32, i32, ...)*)(i8** %11, [2 x i32]* %7, i32 %0, i32 %1, i32 0)
%35 = icmp eq i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %26
%37 = call i32 (i8**, [2 x i32]*, i32, i32, ...) bitcast (i32 (...)* @print_solution to i32 (i8**, [2 x i32]*, i32, i32, ...)*)(i8** %11, [2 x i32]* %7, i32 %0, i32 %1)
br label %40
38: ; preds = %26
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
br i1 %14, label %41, label %49
41: ; preds = %40
%42 = zext i32 %1 to i64
br label %43
43: ; preds = %41, %43
%44 = phi i64 [ 0, %41 ], [ %45, %43 ]
%45 = add nuw nsw i64 %44, 1
%46 = getelementptr inbounds i8*, i8** %11, i64 %44
%47 = load i8*, i8** %46
%48 = icmp eq i64 %45, %42
br i1 %48, label %49, label %43
49: ; preds = %43, %40
br label %50
50: ; preds = %4, %49
ret i32 1
}