#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int n, i;
  int *arr[20];
  FILE *f = fopen("numeros.txt", "rt");
  if (!f) {
    printf("Error al abrir el archivo de texto");
    return 0;
  }
  fscanf(f, "%d", &n);
  for (i = 0; i < n; i++) {
    arr[i] = (int *)malloc(sizeof(int));
    fscanf(f, "%d", arr[i]);
  }
  fclose(f);
  printf("Numeros positivos: ");
  for (i = 0; i < n; i++) {
    if (*(arr[i]) > 0) {
      if (i != 0) {
        printf(", ");
      }
      printf("%d", *(arr[i]));
    }
  }
  printf("\n");
  for (i = 0; i < n; i++) {
    free(arr[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    11b4 <main+0x54>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f4 <main+0x194>
mov    -0xb8(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <fscanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0xc4>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0xb8(%rbp),%rdi
movslq -0xc(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdx
ff
lea    0xe21(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <main+0x72>
mov    -0xb8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ad <main+0x14d>
movslq -0xc(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rax
ff
cmpl   $0x0,(%rax)
jle    129a <main+0x13a>
cmpl   $0x0,-0xc(%rbp)
je     127e <main+0x11e>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0xc(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rax
ff
mov    (%rax),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    129f <main+0x13f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1245 <main+0xe5>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ed <main+0x18d>
movslq -0xc(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12c2 <main+0x162>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ba <main+0x14a>
mov    %rax,%r15
lea    0xe8e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11fb <main+0x8b>
xor    %ebx,%ebx
lea    0xe71(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp,%rbx,8)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1070 <fscanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1286 <main+0x116>
mov    0x10(%rsp),%rcx
mov    (%rcx),%esi
test   %esi,%esi
jle    1236 <main+0xc6>
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jl     1286 <main+0x116>
mov    $0x1,%ebx
lea    0xe02(%rip),%r14
lea    0xde4(%rip),%r15
jmp    125c <main+0xec>
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1286 <main+0x116>
mov    0x10(%rsp,%rbx,8),%r12
cmpl   $0x0,(%r12)
jle    1250 <main+0xe0>
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%eax
jmp    1250 <main+0xe0>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    12c8 <main+0x158>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     12a0 <main+0x130>
jmp    12c8 <main+0x158>
lea    0xd4e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"numeros.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [35 x i8] c"Error al abrir el archivo de texto\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [20 x i8] c"Numeros positivos: \00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i32*]
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %80
11: ; preds = %0
%12 = load i32*, i32** %5
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %14
14: ; preds = %30, %11
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = call i64 @malloc(i32 4)
%20 = inttoptr i64 %19 to i32*
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i32*], [20 x i32*]* %4, i64 0, i64 %22
store i32* %20, i32** %23
%24 = load i32*, i32** %5
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [20 x i32*], [20 x i32*]* %4, i64 0, i64 %26
%28 = load i32*, i32** %27
%29 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %18
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %14
33: ; preds = %14
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %37
37: ; preds = %61, %33
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %64
41: ; preds = %37
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [20 x i32*], [20 x i32*]* %4, i64 0, i64 %43
%45 = load i32*, i32** %44
%46 = load i32, i32* %45
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %41
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [20 x i32*], [20 x i32*]* %4, i64 0, i64 %55
%57 = load i32*, i32** %56
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %53, %41
br label %61
61: ; preds = %60
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
br label %37
64: ; preds = %37
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %66
66: ; preds = %76, %64
%67 = load i32, i32* %3
%68 = load i32, i32* %2
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %79
70: ; preds = %66
%71 = load i32, i32* %3
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [20 x i32*], [20 x i32*]* %4, i64 0, i64 %72
%74 = load i32*, i32** %73
%75 = call i32 @free(i32* %74)
br label %76
76: ; preds = %70
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
br label %66
79: ; preds = %66
store i32 0, i32* %1
br label %80
80: ; preds = %79, %9
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
@.str = [12 x i8] c"numeros.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [35 x i8] c"Error al abrir el archivo de texto\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [20 x i8] c"Numeros positivos: \00"
@.str.5 = [3 x i8] c", \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [20 x i32*]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %69
9: ; preds = %0
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9, %13
%14 = phi i64 [ %19, %13 ], [ 0, %9 ]
%15 = call i64 @malloc(i32 4)
%16 = inttoptr i64 %15 to i32*
%17 = getelementptr inbounds [20 x i32*], [20 x i32*]* %2, i64 0, i64 %14
store i32* %16, i32** %17
%18 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%19 = add nuw nsw i64 %14, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %9
%24 = call i32 @fclose(i32* %5)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %56
28: ; preds = %23
%29 = getelementptr inbounds [20 x i32*], [20 x i32*]* %2, i64 0, i64 0
%30 = load i32*, i32** %29
%31 = load i32, i32* %30
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%35 = load i32, i32* %1
br label %36
36: ; preds = %33, %28
%37 = phi i32 [ %35, %33 ], [ %26, %28 ]
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %56
39: ; preds = %36, %51
%40 = phi i32 [ %52, %51 ], [ %37, %36 ]
%41 = phi i64 [ %53, %51 ], [ 1, %36 ]
%42 = getelementptr inbounds [20 x i32*], [20 x i32*]* %2, i64 0, i64 %41
%43 = load i32*, i32** %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* %43
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %1
br label %51
51: ; preds = %39, %46
%52 = phi i32 [ %40, %39 ], [ %50, %46 ]
%53 = add nuw nsw i64 %41, 1
%54 = sext i32 %52 to i64
%55 = icmp slt i64 %53, %54
br i1 %55, label %39, label %56
56: ; preds = %51, %36, %23
%57 = call i32 @putchar(i32 10)
%58 = load i32, i32* %1
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %56, %60
%61 = phi i64 [ %65, %60 ], [ 0, %56 ]
%62 = getelementptr inbounds [20 x i32*], [20 x i32*]* %2, i64 0, i64 %61
%63 = load i32*, i32** %62
%64 = call i32 @free(i32* %63)
%65 = add nuw nsw i64 %61, 1
%66 = load i32, i32* %1
%67 = sext i32 %66 to i64
%68 = icmp slt i64 %65, %67
br i1 %68, label %60, label %69
69: ; preds = %60, %56, %7
ret i32 0
}