#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 length of the array\n");
    return -2;
  }
  for (int i = 0; i < *size; i++) {
    if (fscanf(f, "%i", &(arr[i])) != 1) {
      return -3;
    }
  }
  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    11e7 <read_arr+0xc7>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    11e0 <read_arr+0xc0>
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     11cd <read_arr+0xad>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11e7 <read_arr+0xc7>
jmp    11d2 <read_arr+0xb2>
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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
lea    0xec7(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    114e <read_arr+0x2e>
mov    (%r14),%eax
add    $0xffffffeb,%eax
cmp    $0xffffffec,%eax
jae    1169 <read_arr+0x49>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
lea    0xe8e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11a7 <read_arr+0x87>
add    $0x1,%rbx
movslq (%r14),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     1180 <read_arr+0x60>
xor    %eax,%eax
jmp    115f <read_arr+0x3f>
mov    $0xfffffffd,%eax
jmp    115f <read_arr+0x3f>

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [31 x i8] c"Incorrect length of the array\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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %4
br label %43
23: ; preds = %17
store i32 0, i32* %8
br label %24
24: ; preds = %39, %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 %42
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 %38
37: ; preds = %29
store i32 -3, i32* %4
br label %43
38: ; preds = %29
br label %39
39: ; preds = %38
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %24
42: ; preds = %24
store i32 0, i32* %4
br label %43
43: ; preds = %42, %37, %21
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@str = [30 x i8] c"Incorrect length of the array\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 %10
6: ; preds = %3
%7 = load i32, i32* %2
%8 = add i32 %7, -21
%9 = icmp ult i32 %8, -20
br i1 %9, label %10, label %16
10: ; preds = %6, %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %22
12: ; preds = %16
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %21, %14
br i1 %15, label %16, label %22
16: ; preds = %6, %12
%17 = phi i64 [ %21, %12 ], [ 0, %6 ]
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%19 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = icmp eq i32 %19, 1
%21 = add nuw nsw i64 %17, 1
br i1 %20, label %12, label %22
22: ; preds = %16, %12, %10
%23 = phi i32 [ -2, %10 ], [ -3, %16 ], [ 0, %12 ]
ret i32 %23
}