#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 */
double *malloc(int);
int rand();
double *CreateChild(double *parent1, double *parent2) {
  int i = 0;
  int passdown = rand() % 2;
  double *child = malloc(sizeof(double) * 8);
  for (i = 0; i < 8; i++) {
    if (passdown) {
      child[i] = parent1[i];
    } else {
      child[i] = parent2[i];
    }
  }
  return child;
}


x86 assembly (clang, -O0):
<CreateChild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11be <CreateChild+0x9e>
cmpl   $0x0,-0x18(%rbp)
je     1191 <CreateChild+0x71>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ab <CreateChild+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11b0 <CreateChild+0x90>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <CreateChild+0x3e>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateChild>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebp
mov    $0x40,%edi
call   1030 <malloc@plt>
test   $0x1,%bpl
cmove  %r14,%rbx
movups (%rbx),%xmm0
movups %xmm0,(%rax)
movups 0x10(%rbx),%xmm0
movups %xmm0,0x10(%rax)
movups 0x20(%rbx),%xmm0
movups %xmm0,0x20(%rax)
movups 0x30(%rbx),%xmm0
movups %xmm0,0x30(%rax)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double* @CreateChild(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
store i32 0, i32* %5
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 2
store i32 %9, i32* %6
%10 = call double* @malloc(i32 64)
store double* %10, double** %7
store i32 0, i32* %5
br label %11
11: ; preds = %38, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %41
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load double*, double** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %7
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
store double %22, double* %26
br label %37
27: ; preds = %14
%28 = load double*, double** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %7
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double %32, double* %36
br label %37
37: ; preds = %27, %17
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %11
41: ; preds = %11
%42 = load double*, double** %7
ret double* %42
}

LLVM IR (-O2):
define noalias double* @CreateChild(double* nocapture %0, double* nocapture %1) {
%3 = tail call i32 (...) @rand()
%4 = tail call double* @malloc(i32 64)
%5 = and i32 %3, 1
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, double* %1, double* %0
%8 = bitcast double* %7 to <2 x double>*
%9 = load <2 x double>, <2 x double>* %8
%10 = bitcast double* %4 to <2 x double>*
store <2 x double> %9, <2 x double>* %10
%11 = getelementptr inbounds double, double* %7, i64 2
%12 = getelementptr inbounds double, double* %4, i64 2
%13 = bitcast double* %11 to <2 x double>*
%14 = load <2 x double>, <2 x double>* %13
%15 = bitcast double* %12 to <2 x double>*
store <2 x double> %14, <2 x double>* %15
%16 = getelementptr inbounds double, double* %7, i64 4
%17 = getelementptr inbounds double, double* %4, i64 4
%18 = bitcast double* %16 to <2 x double>*
%19 = load <2 x double>, <2 x double>* %18
%20 = bitcast double* %17 to <2 x double>*
store <2 x double> %19, <2 x double>* %20
%21 = getelementptr inbounds double, double* %7, i64 6
%22 = getelementptr inbounds double, double* %4, i64 6
%23 = bitcast double* %21 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = bitcast double* %22 to <2 x double>*
store <2 x double> %24, <2 x double>* %25
ret double* %4
}