#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 */
int *calloc(int, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *getarr(int n) {
  int *arr = calloc(n, sizeof(int));
  srand(time(NULL));
  while (n--) {
    arr[n] = (rand() % 100);
    printf("%d, ", arr[n]);
  }
  printf("\n");
  return arr;
}


x86 assembly (clang, -O0):
<getarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11c8 <getarr+0x78>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117c <getarr+0x2c>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getarr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edi,%r12d
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
test   %r12d,%r12d
je     11eb <getarr+0x8b>
movslq %r12d,%rax
lea    (%r14,%rax,4),%r13
add    $0xfffffffffffffffc,%r13
neg    %r12d
lea    0xe5f(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rsi
imul   $0x51eb851f,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%esi
mov    %esi,0x0(%r13,%rbx,4)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r12d
jne    11b0 <getarr+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d, \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32* @getarr(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32* @calloc(i32 %4, i32 4)
store i32* %5, i32** %3
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
br label %8
8: ; preds = %12, %1
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 100
%15 = load i32*, i32** %3
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
%19 = load i32*, i32** %3
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %8
25: ; preds = %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32*, i32** %3
ret i32* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d, \00"
define noalias i32* @getarr(i32 %0) {
%2 = tail call i32* @calloc(i32 %0, i32 4)
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp eq i32 %0, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = sext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 100
%13 = getelementptr inbounds i32, i32* %2, i64 %10
store i32 %12, i32* %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%15 = trunc i64 %10 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %1
%18 = tail call i32 @putchar(i32 10)
ret i32* %2
}