#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__ malloc(size_t);
int rand();
int *geraAleatorios(size_t *tamanho) {
  size_t n = rand() % 9 + 1;
  int *vetor, i;
  if ((vetor = (int *)malloc(n * sizeof(int))) == NULL) {
    *tamanho = 0;
    return NULL;
  }
  *tamanho = n;
  for (i = 0; i < n; i++) {
    vetor[i] = rand();
  }
  return vetor;
}


x86 assembly (clang, -O0):
<geraAleatorios>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x2,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1178 <geraAleatorios+0x58>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11c2 <geraAleatorios+0xa2>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ba <geraAleatorios+0x9a>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <geraAleatorios+0x6a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geraAleatorios>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%eax
movslq %eax,%r15
lea    0x4(,%r15,4),%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     11a6 <geraAleatorios+0x86>
mov    %rax,%r12
add    $0x1,%r15
mov    %r15,(%r14)
test   %r15d,%r15d
je     11b0 <geraAleatorios+0x90>
cmp    $0x2,%r15
mov    $0x1,%r14d
cmovae %r15,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1190 <geraAleatorios+0x70>
jmp    11b0 <geraAleatorios+0x90>
movq   $0x0,(%r14)
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32* @geraAleatorios(i64* nocapture writeonly %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 9
%4 = add nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = shl nsw i64 %5, 2
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i64 0, i64* %0
br label %21
11: ; preds = %1
store i64 %5, i64* %0
%12 = icmp eq i32 %4, 0
br i1 %12, label %21, label %13
13: ; preds = %11
%14 = call i64 @llvm.umax.i64(i64 %5, i64 1)
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %19, %15 ]
%17 = tail call i32 (...) @rand()
%18 = getelementptr inbounds i32, i32* %8, i64 %16
store i32 %17, i32* %18
%19 = add nuw i64 %16, 1
%20 = icmp eq i64 %19, %14
br i1 %20, label %21, label %15
21: ; preds = %15, %11, %10
%22 = phi i32* [ null, %10 ], [ %8, %11 ], [ %8, %15 ]
ret i32* %22
}