#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*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate_board(int board[4][4], int unused_pieces[]) {
  srand(time(NULL));
  int row, col, piece;
  for (row = 0; row < 4; row++) {
    for (col = 0; col < 4; col++) {
      if (row == 4 - 1 && col == 4 - 1) {
        break;
      }
      piece = rand() % (4 * 4 - 1);
      while (unused_pieces[piece] == 0) {
        piece = (piece + 1) % (4 * 4 - 1);
      }
      board[row][col] = unused_pieces[piece];
      unused_pieces[piece] = 0;
    }
  }
  board[4 - 1][4 - 1] = 0;
}


x86 assembly (clang, -O0):
<generate_board>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1216 <generate_board+0xe6>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1203 <generate_board+0xd3>
cmpl   $0x3,-0x14(%rbp)
jne    118b <generate_board+0x5b>
cmpl   $0x3,-0x18(%rbp)
jne    118b <generate_board+0x5b>
jmp    1203 <generate_board+0xd3>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11c5 <generate_board+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
jmp    119d <generate_board+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <generate_board+0x38>
jmp    1208 <generate_board+0xd8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <generate_board+0x27>
mov    -0x8(%rbp),%rax
movl   $0x0,0x3c(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_board>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %r15d,%r15d
nop
xor    %eax,%eax
call   1050 <rand@plt>
nopw   0x0(%rax,%rax,1)
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%esi
mov    %eax,%ecx
sub    %esi,%ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,4),%edx
neg    %esi
add    %esi,%eax
add    $0x1,%eax
test   %edx,%edx
je     1160 <generate_board+0x30>
mov    %r15,%r12
shl    $0x4,%r12
mov    %edx,(%r14,%r12,1)
movl   $0x0,(%rbx,%rcx,4)
xor    %eax,%eax
call   1050 <rand@plt>
nopl   (%rax)
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%esi
mov    %eax,%ecx
sub    %esi,%ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,4),%edx
neg    %esi
add    %esi,%eax
add    $0x1,%eax
test   %edx,%edx
je     11b0 <generate_board+0x80>
mov    %edx,0x4(%r14,%r12,1)
movl   $0x0,(%rbx,%rcx,4)
xor    %eax,%eax
call   1050 <rand@plt>
nopw   0x0(%rax,%rax,1)
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%esi
mov    %eax,%ecx
sub    %esi,%ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,4),%edx
neg    %esi
add    %esi,%eax
add    $0x1,%eax
test   %edx,%edx
je     1200 <generate_board+0xd0>
mov    %edx,0x8(%r14,%r12,1)
movl   $0x0,(%rbx,%rcx,4)
cmp    $0x3,%r15
je     129e <generate_board+0x16e>
xor    %eax,%eax
call   1050 <rand@plt>
nopl   (%rax)
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x3,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%esi
mov    %eax,%ecx
sub    %esi,%ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,4),%edx
neg    %esi
add    %esi,%eax
add    $0x1,%eax
test   %edx,%edx
je     1250 <generate_board+0x120>
mov    %edx,0xc(%r14,%r12,1)
movl   $0x0,(%rbx,%rcx,4)
add    $0x1,%r15
cmp    $0x4,%r15
jne    1150 <generate_board+0x20>
movl   $0x0,0x3c(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @generate_board([4 x i32]* %0, i32* %1) {
%3 = alloca [4 x i32]*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store [4 x i32]* %0, [4 x i32]** %3
store i32* %1, i32** %4
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %59, %2
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %62
13: ; preds = %10
store i32 0, i32* %6
br label %14
14: ; preds = %55, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %58
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %20
br label %58
24: ; preds = %20, %17
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 15
store i32 %26, i32* %7
br label %27
27: ; preds = %34, %24
%28 = load i32*, i32** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = srem i32 %36, 15
store i32 %37, i32* %7
br label %27
38: ; preds = %27
%39 = load i32*, i32** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = load [4 x i32]*, [4 x i32]** %3
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %44, i64 %46
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %47, i64 0, i64 %49
store i32 %43, i32* %50
%51 = load i32*, i32** %4
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 0, i32* %54
br label %55
55: ; preds = %38
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %14
58: ; preds = %23, %14
br label %59
59: ; preds = %58
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %10
62: ; preds = %10
%63 = load [4 x i32]*, [4 x i32]** %3
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %63, i64 3
%65 = getelementptr inbounds [4 x i32], [4 x i32]* %64, i64 0, i64 3
store i32 0, i32* %65
ret void
}

LLVM IR (-O2):
define void @generate_board([4 x i32]* nocapture writeonly %0, i32* nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %54, %2
%6 = phi i64 [ 0, %2 ], [ %57, %54 ]
%7 = icmp eq i64 %6, 3
%8 = tail call i32 (...) @rand()
br label %9
9: ; preds = %9, %5
%10 = phi i32 [ %8, %5 ], [ %16, %9 ]
%11 = srem i32 %10, 15
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
%16 = add nsw i32 %11, 1
br i1 %15, label %9, label %17
17: ; preds = %9
%18 = getelementptr inbounds i32, i32* %1, i64 %12
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %6, i64 0
store i32 %14, i32* %19
store i32 0, i32* %18
%20 = tail call i32 (...) @rand()
br label %21
21: ; preds = %21, %17
%22 = phi i32 [ %20, %17 ], [ %28, %21 ]
%23 = srem i32 %22, 15
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %1, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
%28 = add nsw i32 %23, 1
br i1 %27, label %21, label %29
29: ; preds = %21
%30 = getelementptr inbounds i32, i32* %1, i64 %24
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %6, i64 1
store i32 %26, i32* %31
store i32 0, i32* %30
%32 = tail call i32 (...) @rand()
br label %33
33: ; preds = %33, %29
%34 = phi i32 [ %32, %29 ], [ %40, %33 ]
%35 = srem i32 %34, 15
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %1, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 0
%40 = add nsw i32 %35, 1
br i1 %39, label %33, label %41
41: ; preds = %33
%42 = getelementptr inbounds i32, i32* %1, i64 %36
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %6, i64 2
store i32 %38, i32* %43
store i32 0, i32* %42
br i1 %7, label %59, label %44
44: ; preds = %41
%45 = tail call i32 (...) @rand()
br label %46
46: ; preds = %46, %44
%47 = phi i32 [ %45, %44 ], [ %53, %46 ]
%48 = srem i32 %47, 15
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %1, i64 %49
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 0
%53 = add nsw i32 %48, 1
br i1 %52, label %46, label %54
54: ; preds = %46
%55 = getelementptr inbounds i32, i32* %1, i64 %49
%56 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %6, i64 3
store i32 %51, i32* %56
store i32 0, i32* %55
%57 = add nuw nsw i64 %6, 1
%58 = icmp eq i64 %57, 4
br i1 %58, label %59, label %5
59: ; preds = %41, %54
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 3, i64 3
store i32 0, i32* %60
ret void
}