#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *values;
  int numValues;
  int i;
  printf("Example of Dynamic Array Allocation and Use\n\n");
  printf("Indicate the number of values to be entered:\n");
  do {
    printf("Enter a value in the range of 5 to 15: ");
    scanf("%d", &numValues);
    if (numValues >= 5 && numValues <= 15)
      break;
    printf("Number entered out of range; try again.\n\n");
  } while (1);
  printf("\n");
  values = (int *)malloc(sizeof(int) * numValues);
  for (i = 0; i < numValues; i++) {
    printf("Enter value #%d: ", i + 1);
    scanf("%d", &values[i]);
  }
  printf("\nThe values entered were: ");
  for (i = 0; i < numValues; i++)
    printf("%d ", *(values + i));
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf14(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x5,-0x14(%rbp)
jl     1192 <main+0x62>
cmpl   $0xf,-0x14(%rbp)
jg     1192 <main+0x62>
jmp    11af <main+0x7f>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    115b <main+0x2b>
jmp    11af <main+0x7f>
lea    0xef9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1220 <main+0xf0>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d7 <main+0xa7>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1268 <main+0x138>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1235 <main+0x105>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf19(%rip),%rdi
call   1040 <puts@plt>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xfffffffb,%eax
cmp    $0xb,%eax
jb     11e9 <main+0x99>
lea    0xf0f(%rip),%r14
lea    0xe52(%rip),%r15
lea    0xe73(%rip),%r12
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xfffffffb,%eax
cmp    $0xa,%eax
ja     11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0xc(%rsp)
jle    1249 <main+0xf9>
lea    0xe1b(%rip),%r14
lea    0xe11(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     1220 <main+0xd0>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    128c <main+0x13c>
lea    0xdf3(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1270 <main+0x120>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Example of Dynamic Array Allocation and Use\0A\0A\00"
@.str.1 = [46 x i8] c"Indicate the number of values to be entered:\0A\00"
@.str.2 = [40 x i8] c"Enter a value in the range of 5 to 15: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [42 x i8] c"Number entered out of range; try again.\0A\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [18 x i8] c"Enter value #%d: \00"
@.str.7 = [27 x i8] c"\0AThe values entered were: \00"
@.str.8 = [4 x i8] c"%d \00"
@.str.9 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %18, %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 5
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 15
br i1 %14, label %15, label %16
15: ; preds = %12
br label %19
16: ; preds = %12, %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16
br i1 true, label %7, label %19
19: ; preds = %18, %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = mul i64 4, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %2
store i32 0, i32* %4
br label %27
27: ; preds = %40, %19
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = load i32*, i32** %2
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %27
43: ; preds = %27
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %45
45: ; preds = %56, %43
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %59
49: ; preds = %45
%50 = load i32*, i32** %2
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %45
59: ; preds = %45
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [40 x i8] c"Enter a value in the range of 5 to 15: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.6 = [18 x i8] c"Enter value #%d: \00"
@.str.7 = [27 x i8] c"\0AThe values entered were: \00"
@.str.8 = [4 x i8] c"%d \00"
@str = [45 x i8] c"Example of Dynamic Array Allocation and Use\0A\00"
@str.10 = [45 x i8] c"Indicate the number of values to be entered:\00"
@str.11 = [41 x i8] c"Number entered out of range; try again.\0A\00"
@str.12 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.10, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add i32 %7, -5
%9 = icmp ult i32 %8, 11
br i1 %9, label %17, label %10
10: ; preds = %0, %10
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.11, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = add i32 %14, -5
%16 = icmp ult i32 %15, 11
br i1 %16, label %17, label %10
17: ; preds = %10, %0
%18 = call i32 @putchar(i32 10)
%19 = load i32, i32* %1
%20 = shl i32 %19, 2
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %17, %25
%26 = phi i64 [ %27, %25 ], [ 0, %17 ]
%27 = add nuw nsw i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i32, i32* %22, i64 %26
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %30)
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %27, %33
br i1 %34, label %25, label %35
35: ; preds = %25, %17
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %35, %39
%40 = phi i64 [ %44, %39 ], [ 0, %35 ]
%41 = getelementptr inbounds i32, i32* %22, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = load i32, i32* %1
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %39, label %48
48: ; preds = %39, %35
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}