#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_init_vector(int, int);
int /*<<< orphan*/ free(int *);
int *malloc_init_vector(int);
int /*<<< orphan*/ print_vect(int *, int);
int main(void) {
  int *v, *v1, *v2;
  int size = 10;
  v = malloc_init_vector(size);
  if (!v)
    return 1;
  print_vect(v, size);
  v1 = malloc_init_vector(size * 2);
  if (!v1)
    return 1;
  print_vect(v1, size * 2);
  v2 = calloc_init_vector(size * 3, sizeof(int));
  if (!v2)
    return 1;
  print_vect(v2, size * 3);
  free(v1);
  free(v2);
  free(v);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <malloc_init_vector@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <main+0x39>
movl   $0x1,-0x4(%rbp)
jmp    1212 <main+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <print_vect@plt>
mov    -0x24(%rbp),%edi
shl    $0x1,%edi
call   1040 <malloc_init_vector@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <main+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    1212 <main+0xd2>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
shl    $0x1,%esi
call   1050 <print_vect@plt>
imul   $0x3,-0x24(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc_init_vector@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <main+0xa3>
movl   $0x1,-0x4(%rbp)
jmp    1212 <main+0xd2>
mov    -0x20(%rbp),%rdi
imul   $0x3,-0x24(%rbp),%esi
call   1050 <print_vect@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   1040 <malloc_init_vector@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11ca <main+0x8a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <print_vect@plt>
mov    $0x14,%edi
call   1040 <malloc_init_vector@plt>
test   %rax,%rax
je     11ca <main+0x8a>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x14,%esi
call   1050 <print_vect@plt>
mov    $0x1e,%edi
mov    $0x4,%esi
call   1060 <calloc_init_vector@plt>
test   %rax,%rax
je     11ca <main+0x8a>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1e,%esi
call   1050 <print_vect@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %5
%6 = load i32, i32* %5
%7 = call i32* @malloc_init_vector(i32 %6)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %0
store i32 1, i32* %1
br label %43
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = load i32, i32* %5
%14 = call i32 @print_vect(i32* %12, i32 %13)
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 2
%17 = call i32* @malloc_init_vector(i32 %16)
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %11
store i32 1, i32* %1
br label %43
21: ; preds = %11
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, 2
%25 = call i32 @print_vect(i32* %22, i32 %24)
%26 = load i32, i32* %5
%27 = mul nsw i32 %26, 3
%28 = call i32* @calloc_init_vector(i32 %27, i32 4)
store i32* %28, i32** %4
%29 = load i32*, i32** %4
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %21
store i32 1, i32* %1
br label %43
32: ; preds = %21
%33 = load i32*, i32** %4
%34 = load i32, i32* %5
%35 = mul nsw i32 %34, 3
%36 = call i32 @print_vect(i32* %33, i32 %35)
%37 = load i32*, i32** %3
%38 = call i32 @free(i32* %37)
%39 = load i32*, i32** %4
%40 = call i32 @free(i32* %39)
%41 = load i32*, i32** %2
%42 = call i32 @free(i32* %41)
store i32 0, i32* %1
br label %43
43: ; preds = %32, %31, %20, %10
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc_init_vector(i32 10)
%2 = icmp eq i32* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i32 @print_vect(i32* %1, i32 10)
%5 = tail call i32* @malloc_init_vector(i32 20)
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = tail call i32 @print_vect(i32* %5, i32 20)
%9 = tail call i32* @calloc_init_vector(i32 30, i32 4)
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i32 @print_vect(i32* %9, i32 30)
%13 = tail call i32 @free(i32* %5)
%14 = tail call i32 @free(i32* %9)
%15 = tail call i32 @free(i32* %1)
br label %16
16: ; preds = %7, %3, %0, %11
%17 = phi i32 [ 0, %11 ], [ 1, %0 ], [ 1, %3 ], [ 1, %7 ]
ret i32 %17
}