#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sort012(int *, int);
int main() {
  int arr[] = {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1};
  int size = sizeof(arr) / sizeof(arr[0]);
  int i;
  printf("array before segregation:\t");
  printArray(arr, size);
  sort012(arr, size);
  printf("array After segregation:\t");
  printArray(arr, size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
movl   $0xc,-0x44(%rbp)
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <printArray@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1030 <sort012@plt>
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <printArray@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <printArray@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1030 <sort012@plt>
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <printArray@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.arr = [12 x i32] [i32 0, i32 1, i32 1, i32 0, i32 1, i32 2, i32 1, i32 2, i32 0, i32 0, i32 0, i32 1]
@.str = [27 x i8] c"array before segregation:\09\00"
@.str.1 = [26 x i8] c"array After segregation:\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [12 x i32]* %2 to i8*
store i32 12, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @printArray(i32* %7, i32 %8)
%10 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 @sort012(i32* %10, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @printArray(i32* %14, i32 %15)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [12 x i32] [i32 0, i32 1, i32 1, i32 0, i32 1, i32 2, i32 1, i32 2, i32 0, i32 0, i32 0, i32 1]
@.str = [27 x i8] c"array before segregation:\09\00"
@.str.1 = [26 x i8] c"array After segregation:\09\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = bitcast [12 x i32]* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%5 = call i32 @printArray(i32* %4, i32 12)
%6 = call i32 @sort012(i32* %4, i32 12)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printArray(i32* %4, i32 12)
ret i32 0
}