#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*/ free(int *);
int /*<<< orphan*/ genome_addition_iteration(int *, int, int, int *, int, int *,
                                             int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void workhorse(void) {
  int i;
  int j;
  int nall = 6;
  int zeroes = 3;
  int inds = 3;
  int curr_zero = 0;
  int curr_ind = 0;
  int *genotype;
  int *zero_ind;
  int *replacement;
  genotype = (int *)malloc(nall * sizeof(int));
  zero_ind = (int *)malloc(zeroes * sizeof(int));
  replacement = (int *)malloc(inds * sizeof(int));
  zero_ind[0] = 3;
  zero_ind[1] = 4;
  zero_ind[2] = 5;
  replacement[0] = 0;
  replacement[1] = 1;
  replacement[2] = 2;
  genotype[0] = 1;
  genotype[1] = 2;
  genotype[2] = 3;
  genotype[3] = 0;
  genotype[4] = 0;
  genotype[5] = 0;
  printf("genotype:");
  for (i = 0; i < nall; i++) {
    printf(" %d", genotype[i]);
  }
  printf("\n====================\n");
  for (i = 0; i < inds; i++) {
    genome_addition_iteration(genotype, zeroes, inds, zero_ind, curr_zero,
                              replacement, i, 1);
  }
  free(genotype);
  free(zero_ind);
  free(replacement);
  return;
}


x86 assembly (clang, -O0):
<workhorse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x6,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x5,0x8(%rax)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x38(%rbp),%rax
movl   $0x2,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x3,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x10(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x14(%rax)
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126d <workhorse+0x12d>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <workhorse+0xfa>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12c5 <workhorse+0x185>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x38(%rbp),%r9
mov    -0x4(%rbp),%eax
mov    %eax,(%rsp)
movl   $0x1,0x8(%rsp)
call   1060 <genome_addition_iteration@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <workhorse+0x142>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<workhorse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movabs $0x400000003,%rax
mov    %rax,(%r14)
movl   $0x5,0x8(%r14)
movabs $0x100000000,%rax
mov    %rax,(%r15)
movl   $0x2,0x8(%r15)
movaps 0xe50(%rip),%xmm0
movups %xmm0,(%rbx)
movq   $0x0,0x10(%rbx)
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
lea    0xe48(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
mov    %r15,%r9
push   $0x1
push   $0x0
call   1070 <genome_addition_iteration@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
mov    %r15,%r9
push   $0x1
push   $0x1
call   1070 <genome_addition_iteration@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
mov    %r15,%r9
push   $0x1
push   $0x2
call   1070 <genome_addition_iteration@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"genotype:\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [23 x i8] c"\0A====================\0A\00"
define void @workhorse() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 6, i32* %3
store i32 3, i32* %4
store i32 3, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %8
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %9
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %10
%29 = load i32*, i32** %9
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 3, i32* %30
%31 = load i32*, i32** %9
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32 4, i32* %32
%33 = load i32*, i32** %9
%34 = getelementptr inbounds i32, i32* %33, i64 2
store i32 5, i32* %34
%35 = load i32*, i32** %10
%36 = getelementptr inbounds i32, i32* %35, i64 0
store i32 0, i32* %36
%37 = load i32*, i32** %10
%38 = getelementptr inbounds i32, i32* %37, i64 1
store i32 1, i32* %38
%39 = load i32*, i32** %10
%40 = getelementptr inbounds i32, i32* %39, i64 2
store i32 2, i32* %40
%41 = load i32*, i32** %8
%42 = getelementptr inbounds i32, i32* %41, i64 0
store i32 1, i32* %42
%43 = load i32*, i32** %8
%44 = getelementptr inbounds i32, i32* %43, i64 1
store i32 2, i32* %44
%45 = load i32*, i32** %8
%46 = getelementptr inbounds i32, i32* %45, i64 2
store i32 3, i32* %46
%47 = load i32*, i32** %8
%48 = getelementptr inbounds i32, i32* %47, i64 3
store i32 0, i32* %48
%49 = load i32*, i32** %8
%50 = getelementptr inbounds i32, i32* %49, i64 4
store i32 0, i32* %50
%51 = load i32*, i32** %8
%52 = getelementptr inbounds i32, i32* %51, i64 5
store i32 0, i32* %52
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %54
54: ; preds = %65, %0
%55 = load i32, i32* %1
%56 = load i32, i32* %3
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load i32*, i32** %8
%60 = load i32, i32* %1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %58
%66 = load i32, i32* %1
%67 = add nsw i32 %66, 1
store i32 %67, i32* %1
br label %54
68: ; preds = %54
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %70
70: ; preds = %83, %68
%71 = load i32, i32* %1
%72 = load i32, i32* %5
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %86
74: ; preds = %70
%75 = load i32*, i32** %8
%76 = load i32, i32* %4
%77 = load i32, i32* %5
%78 = load i32*, i32** %9
%79 = load i32, i32* %6
%80 = load i32*, i32** %10
%81 = load i32, i32* %1
%82 = call i32 @genome_addition_iteration(i32* %75, i32 %76, i32 %77, i32* %78, i32 %79, i32* %80, i32 %81, i32 1)
br label %83
83: ; preds = %74
%84 = load i32, i32* %1
%85 = add nsw i32 %84, 1
store i32 %85, i32* %1
br label %70
86: ; preds = %70
%87 = load i32*, i32** %8
%88 = call i32 @free(i32* %87)
%89 = load i32*, i32** %9
%90 = call i32 @free(i32* %89)
%91 = load i32*, i32** %10
%92 = call i32 @free(i32* %91)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"genotype:\00"
@.str.1 = [4 x i8] c" %d\00"
@str = [22 x i8] c"\0A====================\00"
define void @workhorse() {
%1 = tail call i64 @malloc(i32 24)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @malloc(i32 12)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i64 @malloc(i32 12)
%6 = inttoptr i64 %5 to i32*
store i32 3, i32* %4
%7 = getelementptr inbounds i32, i32* %4, i64 1
store i32 4, i32* %7
%8 = getelementptr inbounds i32, i32* %4, i64 2
store i32 5, i32* %8
store i32 0, i32* %6
%9 = getelementptr inbounds i32, i32* %6, i64 1
store i32 1, i32* %9
%10 = getelementptr inbounds i32, i32* %6, i64 2
store i32 2, i32* %10
%11 = getelementptr inbounds i32, i32* %2, i64 1
%12 = getelementptr inbounds i32, i32* %2, i64 2
%13 = getelementptr inbounds i32, i32* %2, i64 3
%14 = inttoptr i64 %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 0>, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %2, i64 4
store i32 0, i32* %15
%16 = getelementptr inbounds i32, i32* %2, i64 5
store i32 0, i32* %16
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %11
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %12
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %13
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %15
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %16
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%31 = tail call i32 @genome_addition_iteration(i32* %2, i32 3, i32 3, i32* %4, i32 0, i32* %6, i32 0, i32 1)
%32 = tail call i32 @genome_addition_iteration(i32* %2, i32 3, i32 3, i32* %4, i32 0, i32* %6, i32 1, i32 1)
%33 = tail call i32 @genome_addition_iteration(i32* %2, i32 3, i32 3, i32* %4, i32 0, i32* %6, i32 2, i32 1)
%34 = tail call i32 @free(i32* %2)
%35 = tail call i32 @free(i32* %4)
%36 = tail call i32 @free(i32* %6)
ret void
}