#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);
double rand_real();
double *hyperplane_init(int num_coef) {
  double *hyperplane = malloc(num_coef * sizeof(double));
  int i = 0;
  double coef = 0.0;
  for (i = 0; i < num_coef; ++i) {
    coef = rand_real();
    if (rand_real() > 0.5) {
      coef = -coef;
    }
    hyperplane[i] = coef;
  }
  return hyperplane;
}


x86 assembly (clang, -O0):
<hyperplane_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c6 <hyperplane_init+0xa6>
mov    $0x0,%al
call   1040 <rand_real@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rand_real@plt>
movsd  0xe85(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a6 <hyperplane_init+0x86>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <hyperplane_init+0x34>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hyperplane_init>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    119c <hyperplane_init+0x7c>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_real@plt>
movapd %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand_real@plt>
movapd (%rsp),%xmm3
movapd %xmm3,%xmm1
xorpd  0xe8c(%rip),%xmm1
movsd  0xe94(%rip),%xmm2
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm3,%xmm2
orpd   %xmm1,%xmm2
movlpd %xmm2,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <hyperplane_init+0x30>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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