#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 /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void arrayPrint(int p1) {
  int *arr;
  arr = (int *)malloc(sizeof(int) * p1);
  if (arr != NULL) {
    printf("You have a %d element array, and this are the elements values:\n",
           p1);
    for (int i = 0; i < p1; i++) {
      arr[i] = i;
      printf("%d", arr[i]);
    }
    free(arr);
  } else {
    printf("no hay memoria suficiente para %d elementos\n", p1);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<arrayPrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <arrayPrint+0x90>
mov    -0x4(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b2 <arrayPrint+0x82>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <arrayPrint+0x41>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    11d1 <arrayPrint+0xa1>
mov    -0x4(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayPrint>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b3 <arrayPrint+0x73>
mov    %rax,%r15
lea    0xe99(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    11a9 <arrayPrint+0x69>
mov    %r14d,%r12d
lea    0xec0(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,(%r15,%rbx,4)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <arrayPrint+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11c4 <arrayPrint+0x84>
lea    0xe89(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <putchar@plt>

LLVM IR (-O0):
@.str = [64 x i8] c"You have a %d element array, and this are the elements values:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"no hay memoria suficiente para %d elementos\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @arrayPrint(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = mul i64 4, %6
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %38
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 0, i32* %4
br label %16
16: ; preds = %32, %13
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
%26 = load i32*, i32** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %20
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %16
35: ; preds = %16
%36 = load i32*, i32** %3
%37 = call i32 @free(i32* %36)
br label %41
38: ; preds = %1
%39 = load i32, i32* %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [64 x i8] c"You have a %d element array, and this are the elements values:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"no hay memoria suficiente para %d elementos\0A\00"
define void @arrayPrint(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = zext i32 %0 to i64
br label %13
11: ; preds = %13, %6
%12 = tail call i32 @free(i32* %4)
br label %22
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %18, %13 ]
%15 = getelementptr inbounds i32, i32* %4, i64 %14
%16 = trunc i64 %14 to i32
store i32 %16, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %11, label %13
20: ; preds = %1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %22
22: ; preds = %20, %11
%23 = tail call i32 @putchar(i32 10)
ret void
}