#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*/ *);
int ai_move(int game[3][3], int *gmx, int *gmy) {
  srand(time(NULL));
  do {
    *gmx = rand() % 3;
    *gmy = rand() % 3;
  } while (game[*gmx][*gmy] != 0);
  return 0;
}


x86 assembly (clang, -O0):
<ai_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1154 <ai_move+0x24>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_move>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,(%r14)
movslq (%rbx),%rcx
cltq
lea    (%rcx,%rcx,2),%rcx
lea    (%r15,%rcx,4),%rcx
cmpl   $0x0,(%rcx,%rax,4)
jne    1150 <ai_move+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @ai_move([3 x i32]* nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
br label %6
6: ; preds = %6, %3
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 3
store i32 %8, i32* %1
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 3
store i32 %10, i32* %2
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %0, i64 %12, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %6
ret i32 0
}