#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i;
  int *arr;
  printf("Introduzca numero de elementos: ");
  scanf("%d", &n);
  arr = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    printf("introduzca el elemento con indice %d: ", i);
    scanf("%d", &(arr[i]));
  }
  printf("\n");
  printf("Elementos positivos: ");
  for (i = 0; i < n; i++) {
    if (*(arr + i) > 0) {
      if (i != 0)
        printf(", ");
      printf("%d", *(arr + i));
    }
  }
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <main+0x8d>
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe67(%rip),%rdi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <main+0x47>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1252 <main+0x112>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    123f <main+0xff>
cmpl   $0x0,-0xc(%rbp)
je     1226 <main+0xe6>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1244 <main+0x104>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f0 <main+0xb0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeaf(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0xc(%rsp)
jle    11d9 <main+0x89>
lea    0xe8b(%rip),%r14
lea    0xe81(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11b0 <main+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1261 <main+0x111>
mov    (%r12),%esi
test   %esi,%esi
jle    1213 <main+0xc3>
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jl     1261 <main+0x111>
mov    $0x1,%ebx
lea    0xe3d(%rip),%r14
lea    0xdf6(%rip),%r15
jmp    123c <main+0xec>
nopl   (%rax)
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1261 <main+0x111>
cmpl   $0x0,(%r12,%rbx,4)
jle    1230 <main+0xe0>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
jmp    1230 <main+0xe0>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Introduzca numero de elementos: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"introduzca el elemento con indice %d: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [22 x i8] c"Elementos positivos: \00"
@.str.5 = [3 x i8] c", \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %4
store i32 0, i32* %3
br label %13
13: ; preds = %25, %0
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %4
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %13
28: ; preds = %13
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %31
31: ; preds = %55, %28
%32 = load i32, i32* %3
%33 = load i32, i32* %2
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = load i32*, i32** %4
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %35
%43 = load i32, i32* %3
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = load i32*, i32** %4
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %47, %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %31
58: ; preds = %31
%59 = load i32*, i32** %4
%60 = call i32 @free(i32* %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Introduzca numero de elementos: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"introduzca el elemento con indice %d: \00"
@.str.4 = [22 x i8] c"Elementos positivos: \00"
@.str.5 = [3 x i8] c", \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %0, %11
%12 = phi i64 [ %17, %11 ], [ 0, %0 ]
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i32, i32* %8, i64 %12
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = add nuw nsw i64 %12, 1
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %0
%22 = call i32 @putchar(i32 10)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* %1
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %51
26: ; preds = %21
%27 = load i32, i32* %8
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%31 = load i32, i32* %1
br label %32
32: ; preds = %29, %26
%33 = phi i32 [ %31, %29 ], [ %24, %26 ]
%34 = icmp sgt i32 %33, 1
br i1 %34, label %35, label %51
35: ; preds = %32, %46
%36 = phi i32 [ %47, %46 ], [ %33, %32 ]
%37 = phi i64 [ %48, %46 ], [ 1, %32 ]
%38 = getelementptr inbounds i32, i32* %8, i64 %37
%39 = load i32, i32* %38
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %38
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %1
br label %46
46: ; preds = %35, %41
%47 = phi i32 [ %36, %35 ], [ %45, %41 ]
%48 = add nuw nsw i64 %37, 1
%49 = sext i32 %47 to i64
%50 = icmp slt i64 %48, %49
br i1 %50, label %35, label %51
51: ; preds = %46, %32, %21
%52 = call i32 @free(i32* %8)
ret i32 0
}