#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 rand();
int /*<<< orphan*/ swap(int *, int *);
void randomize_board(int arr[][4]) {
  int num_swaps = rand() % 20 + 5;
  while (num_swaps--) {
    swap(&arr[rand() % 4][rand() % 4], &arr[rand() % 4][rand() % 4]);
  }
}


x86 assembly (clang, -O0):
<randomize_board>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
add    $0x5,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11f3 <randomize_board+0xd3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    $0x4,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    1141 <randomize_board+0x21>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomize_board>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
add    $0x5,%r12d
je     11de <randomize_board+0xbe>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
movslq %eax,%rbx
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cltq
shl    $0x4,%rbx
add    %r14,%rbx
lea    (%rbx,%rax,4),%r15
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
movslq %eax,%rbx
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cltq
shl    $0x4,%rbx
add    %r14,%rbx
lea    (%rbx,%rax,4),%rsi
mov    %r15,%rdi
call   1030 <swap@plt>
add    $0xffffffff,%r12d
jne    1160 <randomize_board+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @randomize_board([4 x i32]* %0) {
%2 = alloca [4 x i32]*
%3 = alloca i32
store [4 x i32]* %0, [4 x i32]** %2
%4 = call i32 (...) @rand()
%5 = srem i32 %4, 20
%6 = add nsw i32 %5, 5
store i32 %6, i32* %3
br label %7
7: ; preds = %11, %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load [4 x i32]*, [4 x i32]** %2
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 %15
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 %19
%21 = load [4 x i32]*, [4 x i32]** %2
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %21, i64 %24
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %25, i64 0, i64 %28
%30 = call i32 @swap(i32* %20, i32* %29)
br label %7
31: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @randomize_board([4 x i32]* %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 20
%4 = add nsw i32 %3, 5
%5 = icmp eq i32 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %8, %6 ], [ %4, %1 ]
%8 = add nsw i32 %7, -1
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 4
%11 = sext i32 %10 to i64
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %11, i64 %14
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 4
%18 = sext i32 %17 to i64
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %18, i64 %21
%23 = tail call i32 @swap(i32* %15, i32* %22)
%24 = icmp eq i32 %8, 0
br i1 %24, label %25, label %6
25: ; preds = %6, %1
ret void
}