#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 */
scalar_t__ malloc(int const);
float rand0to1();
int *randboolarray(const int size) {
  int i, *array;
  float v;
  array = (int *)malloc(size * sizeof(int));
  for (i = 0; i < size; i++) {
    v = rand0to1();
    if (v < 0.5)
      array[i] = 0;
    else
      array[i] = 1;
  }
  return array;
}


x86 assembly (clang, -O0):
<randboolarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ae <randboolarray+0x8e>
mov    $0x0,%al
call   1030 <rand0to1@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe92(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    118c <randboolarray+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    119b <randboolarray+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    11a0 <randboolarray+0x80>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <randboolarray+0x25>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randboolarray>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1174 <randboolarray+0x54>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand0to1@plt>
xor    %eax,%eax
movss  0xe9f(%rip),%xmm1
ucomiss %xmm0,%xmm1
setbe  %al
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <randboolarray+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @randboolarray(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca float
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 4
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %4
store i32 0, i32* %3
br label %12
12: ; preds = %32, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = call float (...) @rand0to1()
store float %17, float* %5
%18 = load float, float* %5
%19 = fpext float %18 to double
%20 = fcmp olt double %19, 5.000000e-01
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32*, i32** %4
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 0, i32* %25
br label %31
26: ; preds = %16
%27 = load i32*, i32** %4
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 1, i32* %30
br label %31
31: ; preds = %26, %21
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %12
35: ; preds = %12
%36 = load i32*, i32** %4
ret i32* %36
}

LLVM IR (-O2):
define i32* @randboolarray(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32*
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = tail call float (...) @rand0to1()
%11 = fcmp uge float %10, 5.000000e-01
%12 = zext i1 %11 to i32
%13 = getelementptr inbounds i32, i32* %4, i64 %9
store i32 %12, i32* %13
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %1
ret i32* %4
}