#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 *allocate_ints(unsigned int);
int /*<<< orphan*/ exchange(int, int);
int /*<<< orphan*/ exchange_ptr(int *, int *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int x = 5, y = 8;
  printf("first:\nx = %d, y = %d\n\n", x, y);
  exchange(x, y);
  printf("exchange:\nx = %d, y = %d\n\n", x, y);
  exchange_ptr(&x, &y);
  printf("exchange_ptr:\nx = %d, y = %d\n\n", x, y);
  unsigned size;
  printf("How many elements would you like to store? ");
  scanf("%u", &size);
  int *nums = allocate_ints(size);
  if (!nums) {
    perror("Cannot allocate array of that size.");
    return 1;
  }
  unsigned pos = 0;
  printf("Enter data:\n");
  while (pos < size) {
    printf("%u = ", pos);
    scanf("%d", &nums[pos++]);
  }
  printf("The stored data is as follows:");
  while (pos)
    printf(" %d", nums[--pos]);
  free(nums);
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x8,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10a0 <exchange@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <exchange_ptr@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1030 <allocate_ints@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1240 <main+0xc0>
lea    0xe52(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x178>
movl   $0x0,-0x1c(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    129d <main+0x11d>
mov    -0x1c(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
jmp    1255 <main+0xd5>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12da <main+0x15a>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ab <main+0x12b>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
movl   $0x5,0xc(%rsp)
movl   $0x8,0x8(%rsp)
lea    0xe4c(%rip),%rdi
mov    $0x5,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
mov    $0x8,%esi
call   10b0 <exchange@plt>
lea    0xe3d(%rip),%rdi
mov    $0x5,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <exchange_ptr@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe58(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1030 <allocate_ints@plt>
test   %rax,%rax
je     131d <main+0x18d>
mov    %rax,%r14
lea    0xe80(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x4(%rsp)
je     12e7 <main+0x157>
lea    0xe40(%rip),%r15
lea    0xe5f(%rip),%r12
xor    %ebx,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13
lea    (%r14,%rbx,1),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0x4,%rbx
cmp    %rax,%r13
jb     1280 <main+0xf0>
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r13d,%r13d
je     12f5 <main+0x165>
lea    0xe04(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    -0x4(%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xfffffffffffffffc,%rbx
jne    12d0 <main+0x140>
jmp    12f5 <main+0x165>
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd5d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
jmp    130d <main+0x17d>

LLVM IR (-O0):
@.str = [24 x i8] c"first:\0Ax = %d, y = %d\0A\0A\00"
@.str.1 = [27 x i8] c"exchange:\0Ax = %d, y = %d\0A\0A\00"
@.str.2 = [31 x i8] c"exchange_ptr:\0Ax = %d, y = %d\0A\0A\00"
@.str.3 = [44 x i8] c"How many elements would you like to store? \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [36 x i8] c"Cannot allocate array of that size.\00"
@.str.6 = [13 x i8] c"Enter data:\0A\00"
@.str.7 = [6 x i8] c"%u = \00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"The stored data is as follows:\00"
@.str.10 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %2
store i32 8, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32 @exchange(i32 %10, i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i32 @exchange_ptr(i32* %2, i32* %3)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%22 = load i32, i32* %4
%23 = call i32* @allocate_ints(i32 %22)
store i32* %23, i32** %5
%24 = load i32*, i32** %5
%25 = icmp ne i32* %24, null
br i1 %25, label %28, label %26
26: ; preds = %0
%27 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %61
28: ; preds = %0
store i32 0, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %34, %28
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %5
%38 = load i32, i32* %6
%39 = add i32 %38, 1
store i32 %39, i32* %6
%40 = zext i32 %38 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %41)
br label %30
43: ; preds = %30
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
br label %45
45: ; preds = %48, %43
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i32*, i32** %5
%50 = load i32, i32* %6
%51 = add i32 %50, -1
store i32 %51, i32* %6
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 %54)
br label %45
56: ; preds = %45
%57 = load i32*, i32** %5
%58 = call i32 @free(i32* %57)
%59 = call i32 (...) @getchar()
%60 = call i32 (...) @getchar()
store i32 0, i32* %1
br label %61
61: ; preds = %56, %26
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [24 x i8] c"first:\0Ax = %d, y = %d\0A\0A\00"
@.str.1 = [27 x i8] c"exchange:\0Ax = %d, y = %d\0A\0A\00"
@.str.2 = [31 x i8] c"exchange_ptr:\0Ax = %d, y = %d\0A\0A\00"
@.str.3 = [44 x i8] c"How many elements would you like to store? \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [36 x i8] c"Cannot allocate array of that size.\00"
@.str.7 = [6 x i8] c"%u = \00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"The stored data is as follows:\00"
@.str.10 = [4 x i8] c" %d\00"
@str = [12 x i8] c"Enter data:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 8, i32* %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 5, i32 8)
%7 = tail call i32 @exchange(i32 5, i32 8)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 8)
%9 = call i32 @exchange_ptr(i32* %1, i32* %2)
%10 = load i32, i32* %1
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %11)
%13 = bitcast i32* %3 to i8*
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = call i32* @allocate_ints(i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %54
21: ; preds = %0
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
br label %50
27: ; preds = %21, %27
%28 = phi i64 [ %31, %27 ], [ 0, %21 ]
%29 = trunc i64 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %28, 1
%32 = getelementptr inbounds i32, i32* %17, i64 %28
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %32)
%34 = load i32, i32* %3
%35 = zext i32 %34 to i64
%36 = icmp ult i64 %31, %35
br i1 %36, label %27, label %37
37: ; preds = %27
%38 = trunc i64 %31 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%40 = icmp eq i32 %38, 0
br i1 %40, label %50, label %41
41: ; preds = %37
%42 = and i64 %31, 4294967295
br label %43
43: ; preds = %41, %43
%44 = phi i64 [ %42, %41 ], [ %45, %43 ]
%45 = add nsw i64 %44, -1
%46 = getelementptr inbounds i32, i32* %17, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 %47)
%49 = icmp eq i64 %45, 0
br i1 %49, label %50, label %43
50: ; preds = %43, %25, %37
%51 = call i32 @free(i32* %17)
%52 = call i32 (...) @getchar()
%53 = call i32 (...) @getchar()
br label %54
54: ; preds = %50, %19
%55 = phi i32 [ 0, %50 ], [ 1, %19 ]
ret i32 %55
}