#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 *malloc(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *createrandom(int length) {
  int i;
  int *arr = malloc(length * sizeof(int));
  srand(time(NULL));
  for (i = 0; i < length; i++) {
    arr[i] = rand() % 2;
  }
  return arr;
}


x86 assembly (clang, -O0):
<createrandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a9 <createrandom+0x69>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1175 <createrandom+0x35>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createrandom>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    1190 <createrandom+0x50>
mov    %r14d,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <createrandom+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i32* @createrandom(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i32* @malloc(i32 %2)
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 2
%13 = getelementptr inbounds i32, i32* %3, i64 %10
store i32 %12, i32* %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %1
ret i32* %3
}