#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 */
struct chromosome {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ crossover(struct chromosome *, struct chromosome *, int);
int rand();
void reproducegenes(struct chromosome **generation, int POPSIZE,
                    int crossoverprob, int timeslots) {
  int randomtable[POPSIZE], i, counter = 0, erased = 0;
  for (i = 0; i < POPSIZE; i++) {
    randomtable[i] = (rand() % 100);
    if (randomtable[i] <= crossoverprob) {
      counter++;
    }
  }
  if (counter % 2 != 0) {
    int j = 0;
    do {
      if (randomtable[j] <= crossoverprob) {
        randomtable[j] = 2 * crossoverprob;
        erased = 10;
      }
      j++;
    } while (erased < 1);
  }
  struct chromosome *parent1 = NULL;
  struct chromosome *parent2 = NULL;
  int p = 0, parent2found = 0;
  while (p < POPSIZE) {
    if (randomtable[p] <= crossoverprob) {
      int j = p + 1;
      parent2found = 0;
      parent1 = generation[p];
      while (parent2found == 0) {
        if (randomtable[j] <= crossoverprob) {
          parent2found = 1;
          parent2 = generation[j];
        }
        j++;
      }
      crossover(parent1, parent2, timeslots);
      p = j - 1;
    }
    p++;
  }
}


x86 assembly (clang, -O0):
<reproducegenes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c3 <reproducegenes+0xa3>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x60(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jg     11b0 <reproducegenes+0x90>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b5 <reproducegenes+0x95>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1171 <reproducegenes+0x51>
mov    -0x30(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1222 <reproducegenes+0x102>
movl   $0x0,-0x38(%rbp)
mov    -0x60(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jg     120a <reproducegenes+0xea>
mov    -0x60(%rbp),%rax
mov    -0x10(%rbp),%edx
shl    $0x1,%edx
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0xa,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x34(%rbp)
jl     11de <reproducegenes+0xbe>
jmp    1222 <reproducegenes+0x102>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ea <reproducegenes+0x1ca>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jg     12dc <reproducegenes+0x1bc>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    12c3 <reproducegenes+0x1a3>
mov    -0x60(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jg     12b5 <reproducegenes+0x195>
movl   $0x1,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1280 <reproducegenes+0x160>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <crossover@plt>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1240 <reproducegenes+0x120>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reproducegenes>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,-0x38(%rbp)
mov    %esi,%r14d
mov    %rsp,%r13
lea    0xf(,%r14,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %esi,%esi
jle    123b <reproducegenes+0x11b>
mov    %edx,%ebx
mov    %esi,-0x2c(%rbp)
mov    %ecx,-0x30(%rbp)
xor    %r15d,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x0(%r13,%r15,4)
xor    %ecx,%ecx
cmp    %ebx,%eax
setle  %cl
add    %ecx,%r12d
add    $0x1,%r15
cmp    %r15,%r14
jne    1170 <reproducegenes+0x50>
test   $0x1,%r12b
mov    -0x30(%rbp),%r12d
mov    -0x2c(%rbp),%edx
je     11d8 <reproducegenes+0xb8>
mov    $0xffffffffffffffff,%rax
xchg   %ax,%ax
mov    %rax,%rcx
add    $0x1,%rax
cmp    %ebx,0x4(%r13,%rcx,4)
jg     11c0 <reproducegenes+0xa0>
mov    %eax,%eax
lea    (%rbx,%rbx,1),%ecx
mov    %ecx,0x0(%r13,%rax,4)
test   %edx,%edx
jle    123b <reproducegenes+0x11b>
lea    0x4(%r13),%r14
xor    %eax,%eax
jmp    11f7 <reproducegenes+0xd7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%eax
cmp    %edx,%eax
jge    123b <reproducegenes+0x11b>
movslq %eax,%r15
cmp    %ebx,0x0(%r13,%r15,4)
jg     11f0 <reproducegenes+0xd0>
mov    -0x38(%rbp),%rax
mov    (%rax,%r15,8),%rdi
lea    (%r14,%r15,4),%rcx
xor    %eax,%eax
nop
mov    %rax,%rdx
add    $0x1,%rax
cmp    %ebx,(%rcx,%rdx,4)
jg     1210 <reproducegenes+0xf0>
mov    -0x38(%rbp),%rcx
lea    (%rcx,%r15,8),%rcx
mov    (%rcx,%rax,8),%rsi
add    %eax,%r15d
mov    %r12d,%edx
call   1030 <crossover@plt>
mov    %r15d,%eax
mov    -0x2c(%rbp),%edx
jmp    11f0 <reproducegenes+0xd0>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.chromosome = type { i32 }
define void @reproducegenes(%struct.chromosome** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.chromosome**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.chromosome*
%16 = alloca %struct.chromosome*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store %struct.chromosome** %0, %struct.chromosome*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %9
%23 = alloca i32, i64 %21
store i64 %21, i64* %10
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %11
br label %24
24: ; preds = %44, %4
%25 = load i32, i32* %11
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %47
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 100
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %23, i64 %32
store i32 %30, i32* %33
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %23, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %7
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %28
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %43
43: ; preds = %40, %28
br label %44
44: ; preds = %43
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %24
47: ; preds = %24
%48 = load i32, i32* %12
%49 = srem i32 %48, 2
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %72
51: ; preds = %47
store i32 0, i32* %14
br label %52
52: ; preds = %68, %51
%53 = load i32, i32* %14
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %23, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %7
%58 = icmp sle i32 %56, %57
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = load i32, i32* %7
%61 = mul nsw i32 2, %60
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %23, i64 %63
store i32 %61, i32* %64
store i32 10, i32* %13
br label %65
65: ; preds = %59, %52
%66 = load i32, i32* %14
%67 = add nsw i32 %66, 1
store i32 %67, i32* %14
br label %68
68: ; preds = %65
%69 = load i32, i32* %13
%70 = icmp slt i32 %69, 1
br i1 %70, label %52, label %71
71: ; preds = %68
br label %72
72: ; preds = %71, %47
store %struct.chromosome* null, %struct.chromosome** %15
store %struct.chromosome* null, %struct.chromosome** %16
store i32 0, i32* %17
store i32 0, i32* %18
br label %73
73: ; preds = %118, %72
%74 = load i32, i32* %17
%75 = load i32, i32* %6
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %121
77: ; preds = %73
%78 = load i32, i32* %17
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %23, i64 %79
%81 = load i32, i32* %80
%82 = load i32, i32* %7
%83 = icmp sle i32 %81, %82
br i1 %83, label %84, label %118
84: ; preds = %77
%85 = load i32, i32* %17
%86 = add nsw i32 %85, 1
store i32 %86, i32* %19
store i32 0, i32* %18
%87 = load %struct.chromosome**, %struct.chromosome*** %5
%88 = load i32, i32* %17
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds %struct.chromosome*, %struct.chromosome** %87, i64 %89
%91 = load %struct.chromosome*, %struct.chromosome** %90
store %struct.chromosome* %91, %struct.chromosome** %15
br label %92
92: ; preds = %108, %84
%93 = load i32, i32* %18
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %111
95: ; preds = %92
%96 = load i32, i32* %19
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %23, i64 %97
%99 = load i32, i32* %98
%100 = load i32, i32* %7
%101 = icmp sle i32 %99, %100
br i1 %101, label %102, label %108
102: ; preds = %95
store i32 1, i32* %18
%103 = load %struct.chromosome**, %struct.chromosome*** %5
%104 = load i32, i32* %19
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds %struct.chromosome*, %struct.chromosome** %103, i64 %105
%107 = load %struct.chromosome*, %struct.chromosome** %106
store %struct.chromosome* %107, %struct.chromosome** %16
br label %108
108: ; preds = %102, %95
%109 = load i32, i32* %19
%110 = add nsw i32 %109, 1
store i32 %110, i32* %19
br label %92
111: ; preds = %92
%112 = load %struct.chromosome*, %struct.chromosome** %15
%113 = load %struct.chromosome*, %struct.chromosome** %16
%114 = load i32, i32* %8
%115 = call i32 @crossover(%struct.chromosome* %112, %struct.chromosome* %113, i32 %114)
%116 = load i32, i32* %19
%117 = sub nsw i32 %116, 1
store i32 %117, i32* %17
br label %118
118: ; preds = %111, %77
%119 = load i32, i32* %17
%120 = add nsw i32 %119, 1
store i32 %120, i32* %17
br label %73
121: ; preds = %73
%122 = load i8*, i8** %9
ret void
}

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