#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 */
short find_pos(short *);
short num_inversions(short *);
short is_solvable(short *puzzle) {
  short pos = find_pos(puzzle);
  short count = num_inversions(puzzle);
  if ((4 - pos / 4) % 2 == 0)
    return count % 2 == 1;
  else
    return count % 2 == 0;
}


x86 assembly (clang, -O0):
<is_solvable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <find_pos@plt>
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <num_inversions@plt>
mov    %ax,-0x14(%rbp)
movswl -0x12(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x4,%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118c <is_solvable+0x6c>
movswl -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,-0x2(%rbp)
jmp    11a7 <is_solvable+0x87>
movswl -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_solvable>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <find_pos@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <num_inversions@plt>
lea    0x3(%rbx),%ecx
test   %bx,%bx
movzbl %cl,%ecx
cmovns %ebx,%ecx
bt     $0x2,%ecx
jb     1162 <is_solvable+0x42>
movzwl %ax,%ecx
mov    %ecx,%eax
shr    $0xf,%eax
add    %ecx,%eax
and    $0xfffffffe,%eax
sub    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%cx
sete   %al
jmp    1167 <is_solvable+0x47>
not    %eax
and    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i16 @is_solvable(i16* %0) {
%2 = alloca i16
%3 = alloca i16*
%4 = alloca i16
%5 = alloca i16
store i16* %0, i16** %3
%6 = load i16*, i16** %3
%7 = call signext i16 @find_pos(i16* %6)
store i16 %7, i16* %4
%8 = load i16*, i16** %3
%9 = call signext i16 @num_inversions(i16* %8)
store i16 %9, i16* %5
%10 = load i16, i16* %4
%11 = sext i16 %10 to i32
%12 = sdiv i32 %11, 4
%13 = sub nsw i32 4, %12
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %1
%17 = load i16, i16* %5
%18 = sext i16 %17 to i32
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = trunc i32 %21 to i16
store i16 %22, i16* %2
br label %30
23: ; preds = %1
%24 = load i16, i16* %5
%25 = sext i16 %24 to i32
%26 = srem i32 %25, 2
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = trunc i32 %28 to i16
store i16 %29, i16* %2
br label %30
30: ; preds = %23, %16
%31 = load i16, i16* %2
ret i16 %31
}

LLVM IR (-O2):
define signext i16 @is_solvable(i16* %0) {
%2 = tail call signext i16 @find_pos(i16* %0)
%3 = tail call signext i16 @num_inversions(i16* %0)
%4 = sdiv i16 %2, -4
%5 = and i16 %4, 1
%6 = icmp eq i16 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = srem i16 %3, 2
%9 = icmp eq i16 %8, 1
%10 = zext i1 %9 to i16
br label %14
11: ; preds = %1
%12 = and i16 %3, 1
%13 = xor i16 %12, 1
br label %14
14: ; preds = %11, %7
%15 = phi i16 [ %10, %7 ], [ %13, %11 ]
ret i16 %15
}