#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 fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int read_arr(FILE *f, int *arr, int *size) {
  if ((fscanf(f, "%i", size) != 1) || (*size > 20) || (*size < 1)) {
    printf("Incorrect size\n");
    return -2;
  }
  for (int i = 0; i < *size; i++) {
    if (fscanf(f, "%i", &(arr[i])) != 1) {
      printf("Incorrect input\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xebd(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    116b <read_arr+0x4b>
mov    -0x20(%rbp),%rax
cmpl   $0x14,(%rax)
jg     116b <read_arr+0x4b>
mov    -0x20(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1183 <read_arr+0x63>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f3 <read_arr+0xd3>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    11ec <read_arr+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe4d(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11d9 <read_arr+0xb9>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <read_arr+0xd3>
jmp    11de <read_arr+0xbe>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <read_arr+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_arr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xec5(%rip),%rsi
call   1040 <fscanf@plt>
mov    $0xfffffffe,%ebp
lea    0xec7(%rip),%r12
cmp    $0x1,%eax
jne    119c <read_arr+0x7c>
mov    (%r14),%eax
add    $0xffffffeb,%eax
cmp    $0xffffffec,%eax
jb     119c <read_arr+0x7c>
xor    %ebp,%ebp
lea    0xe9b(%rip),%r13
lea    0xe97(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1197 <read_arr+0x77>
add    $0x1,%rbp
movslq (%r14),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     1170 <read_arr+0x50>
xor    %ebp,%ebp
jmp    11a4 <read_arr+0x84>
mov    $0xffffffff,%ebp
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [16 x i8] c"Incorrect size\0A\00"
@.str.2 = [17 x i8] c"Incorrect input\0A\00"
define i32 @read_arr(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %5
%10 = load i32*, i32** %7
%11 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %21, label %13
13: ; preds = %3
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
%16 = icmp sgt i32 %15, 20
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32*, i32** %7
%19 = load i32, i32* %18
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %17, %13, %3
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %4
br label %44
23: ; preds = %17
store i32 0, i32* %8
br label %24
24: ; preds = %40, %23
%25 = load i32, i32* %8
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %43
29: ; preds = %24
%30 = load i32*, i32** %5
%31 = load i32*, i32** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
39: ; preds = %29
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %24
43: ; preds = %24
store i32 0, i32* %4
br label %44
44: ; preds = %43, %37, %21
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@str = [16 x i8] c"Incorrect input\00"
@str.3 = [15 x i8] c"Incorrect size\00"
define i32 @read_arr(i32* nocapture %0, i32* %1, i32* %2) {
%4 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = load i32, i32* %2
%8 = add i32 %7, -21
%9 = icmp ult i32 %8, -20
br i1 %9, label %20, label %14
10: ; preds = %14
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %19, %12
br i1 %13, label %14, label %24
14: ; preds = %6, %10
%15 = phi i64 [ %19, %10 ], [ 0, %6 ]
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %16)
%18 = icmp eq i32 %17, 1
%19 = add nuw nsw i64 %15, 1
br i1 %18, label %10, label %20
20: ; preds = %14, %3, %6
%21 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0), %3 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), %14 ]
%22 = phi i32 [ -2, %6 ], [ -2, %3 ], [ -1, %14 ]
%23 = tail call i32 @puts(i8* dereferenceable(1) %21)
br label %24
24: ; preds = %10, %20
%25 = phi i32 [ %22, %20 ], [ 0, %10 ]
ret i32 %25
}