#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 /*<<< orphan*/ free(int *);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, *ptr;
  ptr = (int *)malloc(10 * sizeof(int));
  if (ptr == NULL) {
    free(ptr);
    printf("\nError allocating memory.\n[Press Enter to close]");
    getchar();
    return 1;
  }
  printf("\nPlease enter %d integers:\n", 10);
  for (i = 0; i < 10; i++) {
    scanf("%d", ptr + i);
    getchar();
  }
  printf("Contents of allocated memory:\n");
  for (i = 0; i < 10; i++) {
    printf("Position %d: %d\t(address: %p)\n", i + 1, *(ptr + i), ptr + i);
  }
  printf("\n");
  free(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <main+0x52>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x11f>
lea    0xe88(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11f6 <main+0xa6>
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe71(%rip),%rdi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bc <main+0x6c>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1251 <main+0x101>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120b <main+0xbb>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x28,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     139b <main+0x22b>
mov    %rax,%rbx
lea    0xe96(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9f(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x4(%rbx),%rsi
mov    %rsi,0x30(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x8(%rbx),%rsi
mov    %rsi,0x28(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xc(%rbx),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x10(%rbx),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x14(%rbx),%rsi
mov    %rsi,0x20(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x18(%rbx),%rsi
mov    %rsi,0x18(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x1c(%rbx),%rsi
mov    %rsi,0x10(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0x20(%rbx),%rsi
mov    %rsi,0x8(%rsp)
mov    %r15,%rdi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %rbx,%r14
add    $0x24,%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
mov    (%rbx),%edx
lea    0xda6(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rbx),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
mov    0x30(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%edx
mov    %rbp,%rdi
mov    $0x3,%esi
mov    0x28(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rbx),%edx
mov    %rbp,%rdi
mov    $0x4,%esi
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%edx
mov    %rbp,%rdi
mov    $0x5,%esi
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x14(%rbx),%edx
mov    %rbp,%rdi
mov    $0x6,%esi
mov    0x20(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%edx
mov    %rbp,%rdi
mov    $0x7,%esi
mov    0x18(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %rbp,%rdi
mov    $0x8,%esi
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rbx),%edx
mov    %rbp,%rdi
mov    $0x9,%esi
mov    0x8(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x24(%rbx),%edx
mov    %rbp,%rdi
mov    $0xa,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    13bc <main+0x24c>
xor    %edi,%edi
call   1030 <free@plt>
lea    0xc57(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"\0AError allocating memory.\0A[Press Enter to close]\00"
@.str.1 = [28 x i8] c"\0APlease enter %d integers:\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [31 x i8] c"Contents of allocated memory:\0A\00"
@.str.4 = [31 x i8] c"Position %d: %d\09(address: %p)\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 40)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32*, i32** %3
%10 = call i32 @free(i32* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @getchar()
store i32 1, i32* %1
br label %53
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 10)
store i32 0, i32* %2
br label %15
15: ; preds = %25, %13
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %22)
%24 = call i32 (...) @getchar()
br label %25
25: ; preds = %18
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %15
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %30
30: ; preds = %46, %28
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
%36 = load i32*, i32** %3
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32*, i32** %3
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %40, i32* %44)
br label %46
46: ; preds = %33
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %30
49: ; preds = %30
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32*, i32** %3
%52 = call i32 @free(i32* %51)
store i32 0, i32* %1
br label %53
53: ; preds = %49, %8
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [49 x i8] c"\0AError allocating memory.\0A[Press Enter to close]\00"
@.str.1 = [28 x i8] c"\0APlease enter %d integers:\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Position %d: %d\09(address: %p)\0A\00"
@str = [30 x i8] c"Contents of allocated memory:\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 40)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @free(i32* null)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @getchar()
br label %62
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 10)
%10 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = tail call i32 (...) @getchar()
%12 = getelementptr inbounds i32, i32* %2, i64 1
%13 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%14 = tail call i32 (...) @getchar()
%15 = getelementptr inbounds i32, i32* %2, i64 2
%16 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%17 = tail call i32 (...) @getchar()
%18 = getelementptr inbounds i32, i32* %2, i64 3
%19 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %18)
%20 = tail call i32 (...) @getchar()
%21 = getelementptr inbounds i32, i32* %2, i64 4
%22 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %21)
%23 = tail call i32 (...) @getchar()
%24 = getelementptr inbounds i32, i32* %2, i64 5
%25 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %24)
%26 = tail call i32 (...) @getchar()
%27 = getelementptr inbounds i32, i32* %2, i64 6
%28 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %27)
%29 = tail call i32 (...) @getchar()
%30 = getelementptr inbounds i32, i32* %2, i64 7
%31 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %30)
%32 = tail call i32 (...) @getchar()
%33 = getelementptr inbounds i32, i32* %2, i64 8
%34 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %33)
%35 = tail call i32 (...) @getchar()
%36 = getelementptr inbounds i32, i32* %2, i64 9
%37 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %36)
%38 = tail call i32 (...) @getchar()
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%40 = load i32, i32* %2
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %40, i32* %2)
%42 = load i32, i32* %12
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %42, i32* %12)
%44 = load i32, i32* %15
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 %44, i32* %15)
%46 = load i32, i32* %18
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 %46, i32* %18)
%48 = load i32, i32* %21
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 %48, i32* %21)
%50 = load i32, i32* %24
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 %50, i32* %24)
%52 = load i32, i32* %27
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 %52, i32* %27)
%54 = load i32, i32* %30
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 8, i32 %54, i32* %30)
%56 = load i32, i32* %33
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 9, i32 %56, i32* %33)
%58 = load i32, i32* %36
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 10, i32 %58, i32* %36)
%60 = tail call i32 @putchar(i32 10)
%61 = tail call i32 @free(i32* %2)
br label %62
62: ; preds = %8, %4
%63 = phi i32 [ 1, %4 ], [ 0, %8 ]
ret i32 %63
}