#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*/ parity_rearrange(int *, size_t);
int /*<<< orphan*/ print_array(int *, size_t);
int /*<<< orphan*/ printf(char *);
int scanf(char *, ...);
int main(void) {
  printf("Enter length of array, followed by the elements.\n");
  printf("Note: there must be the same number of even and odd elements.\n");
  printf("> ");
  size_t arr_sz;
  while (scanf("%zu", &arr_sz) == 1) {
    int arr[arr_sz];
    size_t i;
    for (i = 0; i < arr_sz; i++) {
      scanf("%d", &arr[i]);
    }
    parity_rearrange(arr, arr_sz);
    print_array(arr, arr_sz);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
call   1040 <printf@plt>
lea    0xf03(%rip),%rdi
call   1040 <printf@plt>
lea    0xefa(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    122c <main+0xec>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11fa <main+0xba>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11be <main+0x7e>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <parity_rearrange@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <print_array@plt>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1173 <main+0x33>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1243 <main+0xf3>
lea    0xe63(%rip),%rbx
jmp    11ec <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
xor    %esi,%esi
mov    %r14,%rdi
call   1060 <parity_rearrange@plt>
mov    -0x30(%rbp),%rsi
mov    %r14,%rdi
call   1040 <print_array@plt>
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rsp
lea    0xe27(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1243 <main+0xf3>
mov    %rsp,%r15
mov    -0x30(%rbp),%rax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpq   $0x0,-0x30(%rbp)
je     11b0 <main+0x60>
mov    %r14,%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%r12
mov    -0x30(%rbp),%rsi
add    $0x4,%r13
cmp    %rsi,%r12
jb     1220 <main+0xd0>
jmp    11b2 <main+0x62>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Enter length of array, followed by the elements.\0A\00"
@.str.1 = [63 x i8] c"Note: there must be the same number of even and odd elements.\0A\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [4 x i8] c"%zu\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %27, %0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load i64, i64* %2
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
store i64 0, i64* %5
br label %16
16: ; preds = %24, %12
%17 = load i64, i64* %5
%18 = load i64, i64* %2
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i64, i64* %5
%22 = getelementptr inbounds i32, i32* %15, i64 %21
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %5
%26 = add i64 %25, 1
store i64 %26, i64* %5
br label %16
27: ; preds = %16
%28 = load i64, i64* %2
%29 = call i32 @parity_rearrange(i32* %15, i64 %28)
%30 = load i64, i64* %2
%31 = call i32 @print_array(i32* %15, i64 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %3
br label %9
34: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [4 x i8] c"%zu\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [49 x i8] c"Enter length of array, followed by the elements.\00"
@str.5 = [62 x i8] c"Note: there must be the same number of even and odd elements.\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.5, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%5 = bitcast i64* %1 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %29
8: ; preds = %0, %21
%9 = load i64, i64* %1
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %8, %14
%15 = phi i64 [ %18, %14 ], [ 0, %8 ]
%16 = getelementptr inbounds i32, i32* %11, i64 %15
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %16)
%18 = add nuw i64 %15, 1
%19 = load i64, i64* %1
%20 = icmp ult i64 %18, %19
br i1 %20, label %14, label %21
21: ; preds = %14, %8
%22 = phi i64 [ 0, %8 ], [ %19, %14 ]
%23 = call i32 @parity_rearrange(i32* %11, i64 %22)
%24 = load i64, i64* %1
%25 = call i32 @print_array(i32* %11, i64 %24)
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%28 = icmp eq i32 %27, 1
br i1 %28, label %8, label %29
29: ; preds = %21, %0
ret i32 0
}