#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 atoi(char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sortColors2(int *, int);
int main(int argc, char **argv) {
  int i;
  if (argc < 2) {
    printf("sortColor <color1> [color2] [...] [colorN]\n");
    return 0;
  }
  int *a = (int *)malloc(sizeof(int) * (argc - 1));
  for (i = 0; i < argc - 1; ++i) {
    a[i] = atoi(argv[i + 1]);
  }
  sortColors2(a, argc - 1);
  for (i = 0; i < argc - 1; ++i) {
    printf("%d ", a[i]);
  }
  printf("\n");
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1256 <main+0x106>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ea <main+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x58>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <sortColors2@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1238 <main+0xe8>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1200 <main+0xb0>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1191 <main+0x21>
lea    0xe7d(%rip),%rdi
call   1050 <puts@plt>
jmp    121a <main+0xaa>
mov    %rsi,%r12
mov    %edi,%r15d
lea    -0x1(%r15),%r14d
lea    -0x4(,%r15,4),%edi
ff
call   1080 <malloc@plt>
mov    %rax,%r13
xor    %ebx,%ebx
nopl   (%rax)
lea    0x1(%rbx),%rbp
mov    0x8(%r12,%rbx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,0x0(%r13,%rbx,4)
mov    %rbp,%rbx
cmp    %rbp,%r14
jne    11b0 <main+0x40>
mov    %r13,%rdi
mov    %r14d,%esi
call   1070 <sortColors2@plt>
cmp    $0x2,%r15d
jl     1208 <main+0x98>
lea    0xe1d(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11f0 <main+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"sortColor <color1> [color2] [...] [colorN]\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %64
12: ; preds = %2
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %7
store i32 0, i32* %6
br label %20
20: ; preds = %37, %12
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = load i32*, i32** %7
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %25
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %20
40: ; preds = %20
%41 = load i32*, i32** %7
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 1
%44 = call i32 @sortColors2(i32* %41, i32 %43)
store i32 0, i32* %6
br label %45
45: ; preds = %57, %40
%46 = load i32, i32* %6
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %60
50: ; preds = %45
%51 = load i32*, i32** %7
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %45
60: ; preds = %45
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32*, i32** %7
%63 = call i32 @free(i32* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %60, %10
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
@str = [43 x i8] c"sortColor <color1> [color2] [...] [colorN]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %35
6: ; preds = %2
%7 = add nsw i32 %0, -1
%8 = shl i32 %7, 2
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = zext i32 %7 to i64
br label %12
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %14, %12 ]
%14 = add nuw nsw i64 %13, 1
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i32, i32* %10, i64 %13
store i32 %17, i32* %18
%19 = icmp eq i64 %14, %11
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = tail call i32 @sortColors2(i32* %10, i32 %7)
%22 = icmp sgt i32 %0, 1
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = zext i32 %7 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %30, %25 ]
%27 = getelementptr inbounds i32, i32* %10, i64 %26
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, %24
br i1 %31, label %32, label %25
32: ; preds = %25, %20
%33 = tail call i32 @putchar(i32 10)
%34 = tail call i32 @free(i32* %10)
br label %35
35: ; preds = %32, %4
ret i32 0
}