#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int *calloc(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(unsigned long);
int *random_int_list(int count) {
  int *buf;
  int iter;
  struct timeval time;
  if (count < 1)
    return NULL;
  buf = calloc(count, sizeof(int));
  if (buf == NULL)
    return NULL;
  gettimeofday(&time, NULL);
  srand((unsigned long)time.tv_usec);
  for (iter = 0; iter < count; iter++) {
    buf[iter] = rand() % 20;
  }
  return buf;
}


x86 assembly (clang, -O0):
<random_int_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    1162 <random_int_list+0x22>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <random_int_list+0xa4>
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118b <random_int_list+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <random_int_list+0xa4>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x28(%rbp),%rdi
call   1040 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dc <random_int_list+0x9c>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <random_int_list+0x68>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_int_list>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    11b4 <random_int_list+0x74>
mov    %edi,%ebp
mov    $0x4,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11b4 <random_int_list+0x74>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rdi
call   1040 <srand@plt>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <random_int_list+0x40>
jmp    11b7 <random_int_list+0x77>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
define i32* @random_int_list(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.timeval
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32* null, i32** %2
br label %37
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32* @calloc(i32 %11, i32 4)
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i32* null, i32** %2
br label %37
16: ; preds = %10
%17 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%19 = load i64, i64* %18
%20 = call i32 @srand(i64 %19)
store i32 0, i32* %5
br label %21
21: ; preds = %32, %16
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 20
%28 = load i32*, i32** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %21
35: ; preds = %21
%36 = load i32*, i32** %4
store i32* %36, i32** %2
br label %37
37: ; preds = %35, %15, %9
%38 = load i32*, i32** %2
ret i32* %38
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
define noalias i32* @random_int_list(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = icmp slt i32 %0, 1
br i1 %4, label %21, label %5
5: ; preds = %1
%6 = tail call i32* @calloc(i32 %0, i32 4)
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %5
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i64, i64* %10
%12 = tail call i32 @srand(i64 %11)
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %8, %14
%15 = phi i64 [ 0, %8 ], [ %19, %14 ]
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 20
%18 = getelementptr inbounds i32, i32* %6, i64 %15
store i32 %17, i32* %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %13
br i1 %20, label %21, label %14
21: ; preds = %14, %5, %1
%22 = phi i32* [ null, %1 ], [ null, %5 ], [ %6, %14 ]
ret i32* %22
}