#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 */
char **allocateTwoD(int);
int /*<<< orphan*/ oneD2twoD(int, char *, char **);
int oneMove(int, char **, char);
int /*<<< orphan*/ releaseTwoD(int, char **);
int /*<<< orphan*/ twoD2oneD(int, char *, char **);
int moveTiles(int size, char *state, int nummove, char *moves) {
  char **twoD = allocateTwoD(size);
  oneD2twoD(size, state, twoD);
  int ind = 0;
  int valid = 1;
  while ((ind < nummove) && (valid == 1)) {
    valid = oneMove(size, twoD, moves[ind]);
    ind++;
  }
  twoD2oneD(size, state, twoD);
  releaseTwoD(size, twoD);
  return valid;
}


x86 assembly (clang, -O0):
<moveTiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <allocateTwoD@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <oneD2twoD@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x31(%rbp)
jge    11ab <moveTiles+0x5b>
cmpl   $0x1,-0x30(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11bb <moveTiles+0x6b>
jmp    11e4 <moveTiles+0x94>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
call   1040 <oneMove@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1190 <moveTiles+0x40>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <twoD2oneD@plt>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <releaseTwoD@plt>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moveTiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r15d
call   1070 <allocateTwoD@plt>
mov    %rax,%r13
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1060 <oneD2twoD@plt>
test   %ebp,%ebp
mov    %rbx,(%rsp)
jle    11b3 <moveTiles+0x63>
mov    %ebp,%ebx
mov    $0x1,%r14d
nopl   0x0(%rax)
movsbl -0x1(%r12,%r14,1),%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1040 <oneMove@plt>
mov    %eax,%ebp
cmp    %rbx,%r14
jae    11b8 <moveTiles+0x68>
add    $0x1,%r14
cmp    $0x1,%ebp
je     1190 <moveTiles+0x40>
jmp    11b8 <moveTiles+0x68>
mov    $0x1,%ebp
mov    %r15d,%edi
mov    (%rsp),%rsi
mov    %r13,%rdx
call   1030 <twoD2oneD@plt>
mov    %r15d,%edi
mov    %r13,%rsi
call   1050 <releaseTwoD@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @moveTiles(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i32, i32* %5
%13 = call i8** @allocateTwoD(i32 %12)
store i8** %13, i8*** %9
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i8**, i8*** %9
%17 = call i32 @oneD2twoD(i32 %14, i8* %15, i8** %16)
store i32 0, i32* %10
store i32 1, i32* %11
br label %18
18: ; preds = %27, %4
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, 1
br label %25
25: ; preds = %22, %18
%26 = phi i1 [ false, %18 ], [ %24, %22 ]
br i1 %26, label %27, label %38
27: ; preds = %25
%28 = load i32, i32* %5
%29 = load i8**, i8*** %9
%30 = load i8*, i8** %8
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @oneMove(i32 %28, i8** %29, i8 signext %34)
store i32 %35, i32* %11
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %18
38: ; preds = %25
%39 = load i32, i32* %5
%40 = load i8*, i8** %6
%41 = load i8**, i8*** %9
%42 = call i32 @twoD2oneD(i32 %39, i8* %40, i8** %41)
%43 = load i32, i32* %5
%44 = load i8**, i8*** %9
%45 = call i32 @releaseTwoD(i32 %43, i8** %44)
%46 = load i32, i32* %11
ret i32 %46
}

LLVM IR (-O2):
define i32 @moveTiles(i32 %0, i8* %1, i32 %2, i8* nocapture %3) {
%5 = tail call i8** @allocateTwoD(i32 %0)
%6 = tail call i32 @oneD2twoD(i32 %0, i8* %1, i8** %5)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @oneMove(i32 %0, i8** %5, i8 signext %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp ult i64 %15, %9
%17 = icmp eq i32 %14, 1
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %10, label %19
19: ; preds = %10, %4
%20 = phi i32 [ 1, %4 ], [ %14, %10 ]
%21 = tail call i32 @twoD2oneD(i32 %0, i8* %1, i8** %5)
%22 = tail call i32 @releaseTwoD(i32 %0, i8** %5)
ret i32 %20
}