#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int *rdin() {
  int l, r;
  int *ay = NULL;
  int *ayp = NULL;
  r = scanf("%d", &l);
  if (r != 1 || l <= 0) {
    printf("first value invalid\n");
    return NULL;
  }
  ay = (int *)malloc((l + 1) * sizeof(int));
  if (ay != NULL) {
    ayp = ay;
    *ayp++ = l;
    for (r = 0; r < l; r++) {
      if (scanf("%d", ayp++) != 1) {
        printf("int value invalid\n");
        return NULL;
      }
    }
  }
  return ay;
}


x86 assembly (clang, -O0):
<rdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xeb1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    116f <rdin+0x3f>
cmpl   $0x0,-0xc(%rbp)
jg     1188 <rdin+0x58>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1236 <rdin+0x106>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122e <rdin+0xfe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %ecx,(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1229 <rdin+0xf9>
mov    -0x20(%rbp),%rsi
mov    %rsi,%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
lea    0xe11(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1216 <rdin+0xe6>
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1236 <rdin+0x106>
jmp    121b <rdin+0xeb>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cd <rdin+0x9d>
jmp    122e <rdin+0xfe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xec1(%rip),%r14
cmp    $0x1,%eax
jne    11bf <rdin+0x8f>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11bf <rdin+0x8f>
lea    0x4(,%rax,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11ca <rdin+0x9a>
mov    0xc(%rsp),%eax
mov    %eax,(%r15)
cmpl   $0x0,0xc(%rsp)
jle    11ca <rdin+0x9a>
mov    %r15,%rbx
add    $0x4,%rbx
xor    %ebp,%ebp
lea    0xe6d(%rip),%r12
lea    0xe69(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11bf <rdin+0x8f>
add    $0x1,%ebp
add    $0x4,%rbx
cmp    0xc(%rsp),%ebp
jl     11a0 <rdin+0x70>
jmp    11ca <rdin+0x9a>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [18 x i8] c"int value invalid\00"
@str.3 = [20 x i8] c"first value invalid\00"
define i32* @rdin() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp ne i32 %3, 1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %28, label %8
8: ; preds = %0
%9 = shl i32 %5, 2
%10 = add i32 %9, 4
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %31, label %14
14: ; preds = %8
%15 = load i32, i32* %1
store i32 %15, i32* %12
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %21, label %31
18: ; preds = %21
%19 = load i32, i32* %1
%20 = icmp slt i32 %27, %19
br i1 %20, label %21, label %31
21: ; preds = %14, %18
%22 = phi i32* [ %24, %18 ], [ %12, %14 ]
%23 = phi i32 [ %27, %18 ], [ 0, %14 ]
%24 = getelementptr inbounds i32, i32* %22, i64 1
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = icmp eq i32 %25, 1
%27 = add nuw nsw i32 %23, 1
br i1 %26, label %18, label %28
28: ; preds = %21, %0
%29 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, i64 0, i64 0), %0 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0), %21 ]
%30 = call i32 @puts(i8* dereferenceable(1) %29)
br label %31
31: ; preds = %18, %28, %14, %8
%32 = phi i32* [ %12, %8 ], [ %12, %14 ], [ null, %28 ], [ %12, %18 ]
ret i32* %32
}