#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 /*<<< orphan*/ printf(char *, int, int);
int *realloc(int *, int);
int scanf(char *, int *);
int *readNumbers(int *count) {
  int mycount = 0;
  int size = 1;
  int *a;
  int n;
  a = malloc(sizeof(int) * size);
  if (a == 0)
    return 0;
  while (scanf("%d", &n) == 1) {
    while (mycount >= size) {
      size *= 2;
      a = realloc(a, sizeof(int) * size);
      if (a == 0)
        return 0;
    }
    a[mycount++] = n;
    printf("%d %d\n", a[mycount - 1], n);
  }
  a = realloc(a, sizeof(int) * mycount);
  *count = mycount;
  *count++;
  return a;
}


x86 assembly (clang, -O0):
<readNumbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1185 <readNumbers+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1261 <readNumbers+0x121>
jmp    118a <readNumbers+0x4a>
lea    0xe6f(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    122d <readNumbers+0xed>
jmp    11a8 <readNumbers+0x68>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11f1 <readNumbers+0xb1>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ec <readNumbers+0xac>
movq   $0x0,-0x8(%rbp)
jmp    1261 <readNumbers+0x121>
jmp    11a8 <readNumbers+0x68>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x24(%rbp),%edx
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
jmp    118a <readNumbers+0x4a>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNumbers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x4,%edi
call   1040 <malloc@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     1202 <readNumbers+0xc2>
mov    %rax,%rbx
lea    0xe92(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11ea <readNumbers+0xaa>
mov    $0x1,%r12d
xor    %r15d,%r15d
xor    %r13d,%r13d
nopl   0x0(%rax)
movslq %r12d,%rax
cmp    %rax,%r13
jl     11b8 <readNumbers+0x78>
lea    (%r12,%r12,1),%ebp
shl    $0x3,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    %ebp,%r12d
test   %rax,%rax
jne    1190 <readNumbers+0x50>
jmp    1205 <readNumbers+0xc5>
mov    0x4(%rsp),%esi
mov    %esi,(%rbx,%r13,4)
add    $0x1,%r13
mov    0x4(%rsp),%edx
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
lea    0xe25(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     1190 <readNumbers+0x50>
lea    0x0(,%r13,4),%esi
mov    %rbx,%rdi
call   1050 <realloc@plt>
mov    %rax,%r15
mov    %r13d,(%r14)
jmp    1205 <readNumbers+0xc5>
xor    %r15d,%r15d
mov    %r15,%rax
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"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32* @readNumbers(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
store i32 1, i32* %5
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
store i32* null, i32** %2
br label %66
16: ; preds = %1
br label %17
17: ; preds = %38, %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %53
20: ; preds = %17
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32, i32* %5
%27 = mul nsw i32 %26, 2
store i32 %27, i32* %5
%28 = load i32*, i32** %6
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = mul i64 4, %30
%32 = trunc i64 %31 to i32
%33 = call i32* @realloc(i32* %28, i32 %32)
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %25
store i32* null, i32** %2
br label %66
37: ; preds = %25
br label %21
38: ; preds = %21
%39 = load i32, i32* %7
%40 = load i32*, i32** %6
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32 %39, i32* %44
%45 = load i32*, i32** %6
%46 = load i32, i32* %4
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = load i32, i32* %49
%51 = load i32, i32* %7
%52 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %51)
br label %17
53: ; preds = %17
%54 = load i32*, i32** %6
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = mul i64 4, %56
%58 = trunc i64 %57 to i32
%59 = call i32* @realloc(i32* %54, i32 %58)
store i32* %59, i32** %6
%60 = load i32, i32* %4
%61 = load i32*, i32** %3
store i32 %60, i32* %61
%62 = load i32*, i32** %3
%63 = getelementptr inbounds i32, i32* %62, i32 1
store i32* %63, i32** %3
%64 = load i32, i32* %62
%65 = load i32*, i32** %6
store i32* %65, i32** %2
br label %66
66: ; preds = %53, %36, %15
%67 = load i32*, i32** %2
ret i32* %67
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32* @readNumbers(i32* nocapture writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @malloc(i32 4)
%5 = icmp eq i32* %4, null
br i1 %5, label %38, label %6
6: ; preds = %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %33
9: ; preds = %6, %23
%10 = phi i64 [ %25, %23 ], [ 0, %6 ]
%11 = phi i32* [ %15, %23 ], [ %4, %6 ]
%12 = phi i32 [ %14, %23 ], [ 1, %6 ]
br label %13
13: ; preds = %9, %18
%14 = phi i32 [ %19, %18 ], [ %12, %9 ]
%15 = phi i32* [ %21, %18 ], [ %11, %9 ]
%16 = sext i32 %14 to i64
%17 = icmp slt i64 %10, %16
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = shl nsw i32 %14, 1
%20 = shl i32 %14, 3
%21 = call i32* @realloc(i32* %15, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %38, label %13
23: ; preds = %13
%24 = load i32, i32* %2
%25 = add nuw nsw i64 %10, 1
%26 = getelementptr inbounds i32, i32* %15, i64 %10
store i32 %24, i32* %26
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %27)
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%30 = icmp eq i32 %29, 1
br i1 %30, label %9, label %31
31: ; preds = %23
%32 = trunc i64 %25 to i32
br label %33
33: ; preds = %31, %6
%34 = phi i32 [ 0, %6 ], [ %32, %31 ]
%35 = phi i32* [ %4, %6 ], [ %15, %31 ]
%36 = shl i32 %34, 2
%37 = call i32* @realloc(i32* %35, i32 %36)
store i32 %34, i32* %0
br label %38
38: ; preds = %18, %1, %33
%39 = phi i32* [ %37, %33 ], [ null, %1 ], [ null, %18 ]
ret i32* %39
}