#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 on_puzzle(int, int);
int /*<<< orphan*/ swap_on_puzzle(int *, int, int, int, int);
int make_movement_on_puzzle(int *matrix, int arrow, int x, int y) {
  if (on_puzzle(x, y)) {
    int is_valid = 0;
    int new_x = 0;
    int new_y = 0;
    switch (arrow) {
    case 1:
      new_x = x - 1;
      new_y = y;
      is_valid = on_puzzle(new_x, new_y);
      break;
    case 2:
      new_x = x + 1;
      new_y = y;
      is_valid = on_puzzle(new_x, new_y);
      break;
    case 3:
      new_x = x;
      new_y = y + 1;
      is_valid = on_puzzle(new_x, new_y);
      break;
    case 4:
      new_x = x;
      new_y = y - 1;
      is_valid = on_puzzle(new_x, new_y);
      break;
    }
    if (!is_valid) {
      return -1;
    }
    swap_on_puzzle(matrix, x, y, new_x, new_y);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_movement_on_puzzle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <on_puzzle@plt>
cmp    $0x0,%eax
je     1242 <make_movement_on_puzzle+0x122>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     120a <make_movement_on_puzzle+0xea>
mov    -0x30(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <on_puzzle@plt>
mov    %eax,-0x20(%rbp)
jmp    120a <make_movement_on_puzzle+0xea>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <on_puzzle@plt>
mov    %eax,-0x20(%rbp)
jmp    120a <make_movement_on_puzzle+0xea>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <on_puzzle@plt>
mov    %eax,-0x20(%rbp)
jmp    120a <make_movement_on_puzzle+0xea>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <on_puzzle@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1220 <make_movement_on_puzzle+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <make_movement_on_puzzle+0x129>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1030 <swap_on_puzzle@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <make_movement_on_puzzle+0x129>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_movement_on_puzzle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %edx,%edi
mov    %ecx,%esi
call   1040 <on_puzzle@plt>
test   %eax,%eax
je     116c <make_movement_on_puzzle+0x4c>
mov    $0xffffffff,%r15d
add    $0xffffffff,%ebp
cmp    $0x3,%ebp
ja     11bf <make_movement_on_puzzle+0x9f>
mov    %rbx,(%rsp)
lea    0xea4(%rip),%rax
movslq (%rax,%rbp,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    -0x1(%r12),%ebx
jmp    1176 <make_movement_on_puzzle+0x56>
xor    %r15d,%r15d
jmp    11bf <make_movement_on_puzzle+0x9f>
lea    0x1(%r12),%ebx
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <on_puzzle@plt>
mov    %r14d,%r13d
test   %eax,%eax
jne    11a5 <make_movement_on_puzzle+0x85>
jmp    11bf <make_movement_on_puzzle+0x9f>
lea    0x1(%r14),%r13d
jmp    1193 <make_movement_on_puzzle+0x73>
lea    -0x1(%r14),%r13d
mov    %r12d,%edi
mov    %r13d,%esi
call   1040 <on_puzzle@plt>
mov    %r12d,%ebx
test   %eax,%eax
je     11bf <make_movement_on_puzzle+0x9f>
mov    (%rsp),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %r13d,%r8d
call   1030 <swap_on_puzzle@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @make_movement_on_puzzle(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 i32
%12 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = call i32 @on_puzzle(i32 %13, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %58
17: ; preds = %4
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%18 = load i32, i32* %7
switch i32 %18, label %47 [
i32 1, label %19
i32 2, label %26
i32 3, label %33
i32 4, label %40
]
19: ; preds = %17
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %11
%22 = load i32, i32* %9
store i32 %22, i32* %12
%23 = load i32, i32* %11
%24 = load i32, i32* %12
%25 = call i32 @on_puzzle(i32 %23, i32 %24)
store i32 %25, i32* %10
br label %47
26: ; preds = %17
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %11
%29 = load i32, i32* %9
store i32 %29, i32* %12
%30 = load i32, i32* %11
%31 = load i32, i32* %12
%32 = call i32 @on_puzzle(i32 %30, i32 %31)
store i32 %32, i32* %10
br label %47
33: ; preds = %17
%34 = load i32, i32* %8
store i32 %34, i32* %11
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %12
%37 = load i32, i32* %11
%38 = load i32, i32* %12
%39 = call i32 @on_puzzle(i32 %37, i32 %38)
store i32 %39, i32* %10
br label %47
40: ; preds = %17
%41 = load i32, i32* %8
store i32 %41, i32* %11
%42 = load i32, i32* %9
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %12
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = call i32 @on_puzzle(i32 %44, i32 %45)
store i32 %46, i32* %10
br label %47
47: ; preds = %17, %40, %33, %26, %19
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %47
store i32 -1, i32* %5
br label %59
51: ; preds = %47
%52 = load i32*, i32** %6
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = load i32, i32* %11
%56 = load i32, i32* %12
%57 = call i32 @swap_on_puzzle(i32* %52, i32 %53, i32 %54, i32 %55, i32 %56)
store i32 1, i32* %5
br label %59
58: ; preds = %4
store i32 0, i32* %5
br label %59
59: ; preds = %58, %51, %50
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
define i32 @make_movement_on_puzzle(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @on_puzzle(i32 %2, i32 %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %4
switch i32 %1, label %27 [
i32 1, label %8
i32 2, label %11
i32 3, label %14
i32 4, label %17
]
8: ; preds = %7
%9 = add nsw i32 %2, -1
%10 = tail call i32 @on_puzzle(i32 %9, i32 %3)
br label %20
11: ; preds = %7
%12 = add nsw i32 %2, 1
%13 = tail call i32 @on_puzzle(i32 %12, i32 %3)
br label %20
14: ; preds = %7
%15 = add nsw i32 %3, 1
%16 = tail call i32 @on_puzzle(i32 %2, i32 %15)
br label %20
17: ; preds = %7
%18 = add nsw i32 %3, -1
%19 = tail call i32 @on_puzzle(i32 %2, i32 %18)
br label %20
20: ; preds = %17, %14, %11, %8
%21 = phi i32 [ %19, %17 ], [ %16, %14 ], [ %13, %11 ], [ %10, %8 ]
%22 = phi i32 [ %2, %17 ], [ %2, %14 ], [ %12, %11 ], [ %9, %8 ]
%23 = phi i32 [ %18, %17 ], [ %15, %14 ], [ %3, %11 ], [ %3, %8 ]
%24 = icmp eq i32 %21, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @swap_on_puzzle(i32* %0, i32 %2, i32 %3, i32 %22, i32 %23)
br label %27
27: ; preds = %7, %4, %25, %20
%28 = phi i32 [ 1, %25 ], [ -1, %20 ], [ 0, %4 ], [ -1, %7 ]
ret i32 %28
}