#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*/ printf(char *, ...);
int scanf(char *, int *);
int read_array(int *array) {
  int size;
  printf("Input the size of an array, up to %d:\n", 10);
  if (scanf("%i", &size) != 1) {
    printf("Incorrect size");
    return -1;
  } else {
    if (size >= 0) {
      for (int i = 0; i < size; i++) {
        scanf("%d", &array[i]);
      }
    } else {
      printf("Incorrect size");
      return -1;
    }
  }
  return size;
}


x86 assembly (clang, -O0):
<read_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xecd(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     1172 <read_array+0x52>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <read_array+0xc2>
cmpl   $0x0,-0x14(%rbp)
jl     11bd <read_array+0x9d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b8 <read_array+0x98>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe94(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1183 <read_array+0x63>
jmp    11d7 <read_array+0xb7>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <read_array+0xc2>
jmp    11dc <read_array+0xbc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_array>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
lea    0xecd(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    118f <read_array+0x6f>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     118f <read_array+0x6f>
je     11ac <read_array+0x8c>
xor    %ebx,%ebx
lea    0xed1(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1170 <read_array+0x50>
jmp    11a2 <read_array+0x82>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
jmp    11a2 <read_array+0x82>

LLVM IR (-O0):
@.str = [39 x i8] c"Input the size of an array, up to %d:\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Incorrect size\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @read_array(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
11: ; preds = %1
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
store i32 0, i32* %5
br label %15
15: ; preds = %25, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = load i32, i32* %5
%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.3, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
br label %31
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
31: ; preds = %28
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
store i32 %33, i32* %2
br label %34
34: ; preds = %32, %29, %9
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [39 x i8] c"Input the size of an array, up to %d:\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Incorrect size\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @read_array(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 10)
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = icmp eq i32 %8, 0
br i1 %11, label %22, label %12
12: ; preds = %10, %12
%13 = phi i64 [ %16, %12 ], [ 0, %10 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %22
20: ; preds = %7, %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %12, %20, %10
%23 = phi i32 [ 0, %10 ], [ -1, %20 ], [ %17, %12 ]
ret i32 %23
}