#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 /*<<< orphan*/ fantasia_crea_bot(int, char);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void fantasia_assegna_ia_random(int numIA, int numG) {
  int i;
  int r;
  char occupato[numG];
  char rt;
  for (i = 1; i < numG; i++)
    occupato[i] = 'F';
  occupato[0] = 'T';
  srand((unsigned)time(NULL));
  for (i = 0; i < numIA; i++) {
    do {
      r = rand() % numG;
    } while (occupato[r] != 'F');
    occupato[r] = 'T';
    switch (rand() % 3) {
    case 0:
      rt = 'a';
      break;
    case 1:
      rt = 'd';
      break;
    case 3:
      rt = 'e';
      break;
    default:
      rt = 'n';
      break;
    }
    fantasia_crea_bot(r, rt);
  }
  return;
}


x86 assembly (clang, -O0):
<fantasia_assegna_ia_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a1 <fantasia_assegna_ia_random+0x61>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x46,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117b <fantasia_assegna_ia_random+0x3b>
mov    -0x30(%rbp),%rax
movb   $0x54,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128d <fantasia_assegna_ia_random+0x14d>
jmp    11d0 <fantasia_assegna_ia_random+0x90>
mov    $0x0,%al
call   1060 <rand@plt>
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x46,%eax
jne    11d0 <fantasia_assegna_ia_random+0x90>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x54,(%rax,%rcx,1)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
je     1254 <fantasia_assegna_ia_random+0x114>
jmp    1232 <fantasia_assegna_ia_random+0xf2>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     125d <fantasia_assegna_ia_random+0x11d>
jmp    1243 <fantasia_assegna_ia_random+0x103>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
je     1266 <fantasia_assegna_ia_random+0x126>
jmp    126f <fantasia_assegna_ia_random+0x12f>
movb   $0x61,-0x21(%rbp)
jmp    1273 <fantasia_assegna_ia_random+0x133>
movb   $0x64,-0x21(%rbp)
jmp    1273 <fantasia_assegna_ia_random+0x133>
movb   $0x65,-0x21(%rbp)
jmp    1273 <fantasia_assegna_ia_random+0x133>
movb   $0x6e,-0x21(%rbp)
mov    -0x10(%rbp),%edi
movsbl -0x21(%rbp),%esi
call   1050 <fantasia_crea_bot@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bf <fantasia_assegna_ia_random+0x7f>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fantasia_assegna_ia_random>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    %esi,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x2,%esi
jl     118f <fantasia_assegna_ia_random+0x3f>
lea    0x1(%r12),%rdi
lea    -0x1(%r15),%edx
mov    $0x46,%esi
call   1030 <memset@plt>
movb   $0x54,(%r12)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
test   %r14d,%r14d
jle    1218 <fantasia_assegna_ia_random+0xc8>
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %r15d
movslq %edx,%rbx
cmpb   $0x46,(%r12,%rbx,1)
jne    11b0 <fantasia_assegna_ia_random+0x60>
movb   $0x54,(%r12,%rbx,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %ecx,%edx
cmp    $0x1,%edx
mov    $0x6e,%esi
mov    $0x64,%edx
cmove  %edx,%esi
cmp    %ecx,%eax
mov    $0x61,%eax
cmove  %eax,%esi
mov    %ebx,%edi
call   1060 <fantasia_crea_bot@plt>
add    $0x1,%r13d
cmp    %r14d,%r13d
jne    11b0 <fantasia_assegna_ia_random+0x60>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @fantasia_assegna_ia_random(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i8, i64 %3
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = add nsw i32 %1, -1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %6, %2
store i8 84, i8* %4
%11 = tail call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @srand(i32 %12)
%14 = icmp sgt i32 %0, 0
br i1 %14, label %15, label %35
15: ; preds = %10, %24
%16 = phi i32 [ %33, %24 ], [ 0, %10 ]
br label %17
17: ; preds = %15, %17
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 70
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = getelementptr inbounds i8, i8* %4, i64 %20
store i8 84, i8* %25
%26 = tail call i32 (...) @rand()
%27 = srem i32 %26, 3
%28 = icmp eq i32 %27, 1
%29 = select i1 %28, i8 100, i8 110
%30 = icmp eq i32 %27, 0
%31 = select i1 %30, i8 97, i8 %29
%32 = tail call i32 @fantasia_crea_bot(i32 %19, i8 signext %31)
%33 = add nuw nsw i32 %16, 1
%34 = icmp eq i32 %33, %0
br i1 %34, label %35, label %15
35: ; preds = %24, %10
ret void
}