#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 placement(int ***, int, int, int, char);
int rand();
int AIPlacement(int (*boardaddr)[10][10], int ship) {
  int row = rand() % 10;
  int col = rand() % 10;
  int cardinal[4] = {78, 83, 69, 87};
  int random = rand() % 4;
  char direction = cardinal[random];
  return placement(boardaddr, row, col, ship, direction);
}


x86 assembly (clang, -O0):
<AIPlacement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %al,-0x35(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
movsbl -0x35(%rbp),%r8d
call   1030 <placement@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AIPlacement>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rbp
imul   $0x66666667,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cltq
lea    0xe6c(%rip),%rcx
movsbl (%rcx,%rax,4),%r8d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <placement@plt>

LLVM IR (-O0):
@__const.AIPlacement.cardinal = [4 x i32] [i32 78, i32 83, i32 69, i32 87]
define i32 @AIPlacement([10 x [10 x i32]]* %0, i32 %1) {
%3 = alloca [10 x [10 x i32]]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4 x i32]
%8 = alloca i32
%9 = alloca i8
store [10 x [10 x i32]]* %0, [10 x [10 x i32]]** %3
store i32 %1, i32* %4
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 10
store i32 %11, i32* %5
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 10
store i32 %13, i32* %6
%14 = bitcast [4 x i32]* %7 to i8*
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 4
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = trunc i32 %20 to i8
store i8 %21, i8* %9
%22 = load [10 x [10 x i32]]*, [10 x [10 x i32]]** %3
%23 = bitcast [10 x [10 x i32]]* %22 to i32***
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = load i8, i8* %9
%28 = call i32 @placement(i32*** %23, i32 %24, i32 %25, i32 %26, i8 signext %27)
ret i32 %28
}

LLVM IR (-O2):
@__const.AIPlacement.cardinal = [4 x i32] [i32 78, i32 83, i32 69, i32 87]
define i32 @AIPlacement([10 x [10 x i32]]* %0, i32 %1) {
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 10
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 10
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [4 x i32], [4 x i32]* @__const.AIPlacement.cardinal, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = trunc i32 %11 to i8
%13 = bitcast [10 x [10 x i32]]* %0 to i32***
%14 = tail call i32 @placement(i32*** %13, i32 %4, i32 %6, i32 %1, i8 signext %12)
ret i32 %14
}