#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*/ scanf(char *, int *);
int legge(int **a, int *len) {
  int i;
  scanf("%d", len);
  if (*len <= 0)
    return 1;
  *a = (int *)malloc(*len * sizeof(int));
  if (*a == NULL)
    return 1;
  for (i = 0; i < *len; i++)
    scanf("%d", (*a) + i);
  return 0;
}


x86 assembly (clang, -O0):
<legge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xec5(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1159 <legge+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <legge+0xb8>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118f <legge+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <legge+0xb8>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11d1 <legge+0xb1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe42(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <legge+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<legge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r12
lea    0xec8(%rip),%rdi
call   1040 <scanf@plt>
mov    0x0(%r13),%edi
mov    $0x1,%r14d
test   %edi,%edi
jle    11b0 <legge+0x90>
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11b0 <legge+0x90>
xor    %r14d,%r14d
cmpl   $0x0,0x0(%r13)
jle    11b0 <legge+0x90>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
call   1040 <scanf@plt>
cmpl   $0x2,0x0(%r13)
jl     11b0 <legge+0x90>
mov    $0x1,%ebp
mov    $0x4,%ebx
lea    0xe73(%rip),%r15
nopl   (%rax)
mov    (%r12),%rsi
add    %rbx,%rsi
mov    %r15,%rdi
call   1040 <scanf@plt>
add    $0x1,%rbp
movslq 0x0(%r13),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     1190 <legge+0x70>
mov    %r14d,%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"%d\00"
define i32 @legge(i32** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %43
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
%21 = load i32**, i32*** %4
store i32* %20, i32** %21
%22 = load i32**, i32*** %4
%23 = load i32*, i32** %22
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %13
store i32 1, i32* %3
br label %43
26: ; preds = %13
store i32 0, i32* %6
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %6
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = load i32**, i32*** %4
%34 = load i32*, i32** %33
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %27
42: ; preds = %27
store i32 0, i32* %3
br label %43
43: ; preds = %42, %25, %12
%44 = load i32, i32* %3
ret i32 %44
}

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