#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 const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int get_input(const char *filename, int *n, int **p) {
  FILE *fd;
  int i;
  if ((fd = fopen(filename, "r")) == NULL) {
    return -1;
  }
  if (fscanf(fd, "%d", n) != 1) {
    goto out;
  }
  if ((*p = (int *)malloc(sizeof(int) * (*n))) == NULL) {
    goto out;
  }
  for (i = 0; i < *n; i++) {
    if (fscanf(fd, "%d", *p + i) != 1) {
      goto out;
    }
  }
  fclose(fd);
  return 0;
out:
  fclose(fd);
  return -1;
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    117e <get_input+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <get_input+0x106>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11a0 <get_input+0x60>
jmp    1236 <get_input+0xf6>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11c8 <get_input+0x88>
jmp    1236 <get_input+0xf6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1221 <get_input+0xe1>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe07(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     120e <get_input+0xce>
jmp    1236 <get_input+0xf6>
jmp    1213 <get_input+0xd3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cf <get_input+0x8f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <get_input+0x106>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r13
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ed <get_input+0xad>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1040 <fscanf@plt>
mov    $0xffffffff,%r14d
cmp    $0x1,%eax
jne    11f8 <get_input+0xb8>
mov    0x0(%r13),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11f8 <get_input+0xb8>
cmpl   $0x0,0x0(%r13)
jle    11f5 <get_input+0xb5>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11f8 <get_input+0xb8>
mov    $0x4,%edx
xor    %ebp,%ebp
nop
movslq 0x0(%r13),%rax
add    $0x1,%rbp
cmp    %rax,%rbp
jge    11f5 <get_input+0xb5>
lea    0x4(%rdx),%r12
add    (%r15),%rdx
mov    %rbx,%rdi
lea    0xe24(%rip),%rsi
call   1040 <fscanf@plt>
mov    %r12,%rdx
cmp    $0x1,%eax
je     11c0 <get_input+0x80>
jmp    11f8 <get_input+0xb8>
mov    $0xffffffff,%r14d
jmp    1200 <get_input+0xc0>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @get_input(i8* nocapture %0, i32* %1, i32** nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %35, label %6
6: ; preds = %3
%7 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = load i32, i32* %1
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %2
%14 = icmp eq i64 %12, 0
br i1 %14, label %32, label %15
15: ; preds = %9
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %32
21: ; preds = %18, %26
%22 = phi i64 [ %31, %26 ], [ 1, %18 ]
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32*, i32** %2
%28 = getelementptr inbounds i32, i32* %27, i64 %22
%29 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
%30 = icmp eq i32 %29, 1
%31 = add nuw nsw i64 %22, 1
br i1 %30, label %21, label %32
32: ; preds = %21, %26, %18, %6, %9, %15
%33 = phi i32 [ 0, %15 ], [ -1, %9 ], [ -1, %6 ], [ -1, %18 ], [ -1, %26 ], [ 0, %21 ]
%34 = tail call i32 @fclose(i32* %4)
br label %35
35: ; preds = %32, %3
%36 = phi i32 [ -1, %3 ], [ %33, %32 ]
ret i32 %36
}