#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 /*<<< orphan*/ ordinaryd(double);
double rand_double();
double *get_random_doubles(int nums) {
  int i;
  double *arr = malloc(sizeof(double) * nums * 1);
  for (i = 0; i < nums * 1; i++) {
    double rand;
    do {
      rand = rand_double();
    } while (!ordinaryd(rand));
    arr[i] = rand;
  }
  return arr;
}


x86 assembly (clang, -O0):
<get_random_doubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x0,%ecx
cmp    %ecx,%eax
jge    11b5 <get_random_doubles+0x85>
jmp    116f <get_random_doubles+0x3f>
mov    $0x0,%al
call   1040 <rand_double@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <ordinaryd@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116f <get_random_doubles+0x3f>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1159 <get_random_doubles+0x29>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_random_doubles>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    118b <get_random_doubles+0x5b>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_double@plt>
movsd  %xmm0,0x8(%rsp)
call   1030 <ordinaryd@plt>
test   %eax,%eax
je     1160 <get_random_doubles+0x30>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %r14,%rbx
jne    1160 <get_random_doubles+0x30>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias double* @get_random_doubles(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, %13
%8 = phi i64 [ 0, %5 ], [ %15, %13 ]
br label %9
9: ; preds = %7, %9
%10 = tail call double (...) @rand_double()
%11 = tail call i32 @ordinaryd(double %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9
%14 = getelementptr inbounds double, double* %3, i64 %8
store double %10, double* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %13, %1
ret double* %3
}