#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__ RAND_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *random_gen(int size) {
  srand(time(NULL));
  int *array = malloc(sizeof(int) * size);
  if (array == NULL) {
    fprintf(stderr, "Failed to allocate array, qutting.\n");
    exit(1);
  }
  for (int i = 0; i < size; i++) {
    array[i] = (int)(((double)rand() / (double)RAND_MAX) * 20);
  }
  return array;
}


x86 assembly (clang, -O0):
<random_gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <random_gen+0x58>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1210 <random_gen+0xb0>
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e0a(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe11(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bf <random_gen+0x5f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_gen>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e3 <random_gen+0x83>
mov    %rax,%r15
test   %r14d,%r14d
jle    11d4 <random_gen+0x74>
mov    %r14d,%r12d
mov    0x2e4b(%rip),%r14
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xe3d(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <random_gen+0x40>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Failed to allocate array, qutting.\0A\00"
@RAND_MAX = global i64 0
define i32* @random_gen(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i32* @malloc(i32 %10)
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
store i32 0, i32* %4
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = call i64 (...) @rand()
%25 = sitofp i64 %24 to double
%26 = load i64, i64* @RAND_MAX
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
%29 = fmul double %28, 2.000000e+01
%30 = fptosi double %29 to i32
%31 = load i32*, i32** %3
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
br label %35
35: ; preds = %23
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %19
38: ; preds = %19
%39 = load i32*, i32** %3
ret i32* %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Failed to allocate array, qutting.\0A\00"
@RAND_MAX = global i64 0
define noalias i32* @random_gen(i32 %0) {
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = shl i32 %0, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %15
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %16, %7
ret i32* %5
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %26, %16 ]
%18 = tail call i64 (...) @rand()
%19 = sitofp i64 %18 to double
%20 = load i64, i64* @RAND_MAX
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
%23 = fmul double %22, 2.000000e+01
%24 = fptosi double %23 to i32
%25 = getelementptr inbounds i32, i32* %5, i64 %17
store i32 %24, i32* %25
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %15, label %16
}