#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 *malloc(int);
int *realloc(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int *leggiInput(int *dim) {
  int *arr = malloc(sizeof(int) * 20), input;
  *dim = 0;
  scanf("%d", &input);
  while (input != 0) {
    arr[*dim] = input;
    (*dim)++;
    scanf("%d", &input);
  }
  return realloc(arr, sizeof(int) * (*dim));
}


x86 assembly (clang, -O0):
<leggiInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x50,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
lea    0xea5(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
je     119f <leggiInput+0x6f>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    0xe6f(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1164 <leggiInput+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leggiInput>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x50,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movl   $0x0,(%rbx)
lea    0xeab(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     119f <leggiInput+0x6f>
lea    0xe92(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq (%rbx),%rcx
mov    %eax,(%r14,%rcx,4)
lea    0x1(%rcx),%eax
mov    %eax,(%rbx)
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jne    1180 <leggiInput+0x50>
mov    (%rbx),%esi
shl    $0x2,%esi
mov    %r14,%rdi
call   1040 <realloc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32* @leggiInput(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32* @malloc(i32 80)
store i32* %5, i32** %3
%6 = load i32*, i32** %2
store i32 0, i32* %6
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32*, i32** %3
%14 = load i32*, i32** %2
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %13, i64 %16
store i32 %12, i32* %17
%18 = load i32*, i32** %2
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %8
22: ; preds = %8
%23 = load i32*, i32** %3
%24 = load i32*, i32** %2
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = mul i64 4, %26
%28 = trunc i64 %27 to i32
%29 = call i32* @realloc(i32* %23, i32 %28)
ret i32* %29
}

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