#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ bench(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i;
  int from, to, step;
  int count;
  if (argc < 2) {
    printf("usage:\n");
    printf("%s <n>\n", argv[0]);
    printf("\tif n=1 the output is verbose for one attempt\n");
    printf("\tif n>1 the output reads:\n");
    printf("\t# of elements | method1 | method2 | ...\n");
    printf("\n");
    printf("%s <from> <to> <step>\n", argv[0]);
    printf("\twill loop over the number of elements in input\n");
    printf("\n");
    exit(EXIT_FAILURE);
  }
  if (argc == 2) {
    count = atoi(argv[1]);
    if (count == 1) {
      bench(1, (1024 * 1024));
    } else {
      printf("Size\tQS\tWirth\tAHU\tTorben\tpixel sort\n");
      for (i = 0; i < atoi(argv[1]); i++) {
        bench(0, (1024 * 1024));
      }
    }
  } else if (argc == 4) {
    from = atoi(argv[1]);
    to = atoi(argv[2]);
    step = atoi(argv[3]);
    for (count = from; count <= to; count += step) {
      bench(0, count);
    }
    return EXIT_SUCCESS;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11fa <main+0xba>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    128b <main+0x14b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1232 <main+0xf2>
mov    $0x1,%edi
mov    $0x100000,%esi
call   1030 <bench@plt>
jmp    1286 <main+0x146>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    1281 <main+0x141>
xor    %edi,%edi
mov    $0x100000,%esi
call   1030 <bench@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1247 <main+0x107>
jmp    1286 <main+0x146>
jmp    1305 <main+0x1c5>
cmpl   $0x4,-0x8(%rbp)
jne    1300 <main+0x1c0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     12ef <main+0x1af>
mov    -0x24(%rbp),%esi
xor    %edi,%edi
call   1030 <bench@plt>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12cb <main+0x18b>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1311 <main+0x1d1>
jmp    1305 <main+0x1c5>
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jle    1230 <main+0xd0>
cmp    $0x4,%edi
je     11a0 <main+0x40>
cmp    $0x2,%edi
jne    121c <main+0xbc>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
jne    11e2 <main+0x82>
mov    $0x1,%edi
mov    $0x100000,%esi
call   1050 <bench@plt>
jmp    121c <main+0xbc>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%r14),%rdi
call   1070 <atoi@plt>
cmp    %r15d,%ebp
jg     121c <main+0xbc>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %ebp,%esi
call   1050 <bench@plt>
add    %ebx,%ebp
cmp    %r15d,%ebp
jle    11d0 <main+0x70>
jmp    121c <main+0xbc>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    121c <main+0xbc>
xor    %ebx,%ebx
nopl   (%rax)
xor    %edi,%edi
mov    $0x100000,%esi
call   1050 <bench@plt>
add    $0x1,%ebx
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
cmp    %eax,%ebx
jl     1200 <main+0xa0>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0c(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%rsi
lea    0xdba(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r14),%rsi
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"usage:\0A\00"
@.str.1 = [8 x i8] c"%s <n>\0A\00"
@.str.2 = [47 x i8] c"\09if n=1 the output is verbose for one attempt\0A\00"
@.str.3 = [27 x i8] c"\09if n>1 the output reads:\0A\00"
@.str.4 = [42 x i8] c"\09# of elements | method1 | method2 | ...\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [23 x i8] c"%s <from> <to> <step>\0A\00"
@.str.7 = [49 x i8] c"\09will loop over the number of elements in input\0A\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [37 x i8] c"Size\09QS\09Wirth\09AHU\09Torben\09pixel sort\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %31
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %59
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @bench(i32 1, i32 1048576)
br label %58
43: ; preds = %34
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %6
br label %45
45: ; preds = %54, %43
%46 = load i32, i32* %6
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = icmp slt i32 %46, %50
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = call i32 @bench(i32 0, i32 1048576)
br label %54
54: ; preds = %52
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %45
57: ; preds = %45
br label %58
58: ; preds = %57, %41
br label %90
59: ; preds = %31
%60 = load i32, i32* %4
%61 = icmp eq i32 %60, 4
br i1 %61, label %62, label %89
62: ; preds = %59
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
store i32 %66, i32* %7
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 @atoi(i8* %69)
store i32 %70, i32* %8
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 3
%73 = load i8*, i8** %72
%74 = call i32 @atoi(i8* %73)
store i32 %74, i32* %9
%75 = load i32, i32* %7
store i32 %75, i32* %10
br label %76
76: ; preds = %83, %62
%77 = load i32, i32* %10
%78 = load i32, i32* %8
%79 = icmp sle i32 %77, %78
br i1 %79, label %80, label %87
80: ; preds = %76
%81 = load i32, i32* %10
%82 = call i32 @bench(i32 0, i32 %81)
br label %83
83: ; preds = %80
%84 = load i32, i32* %9
%85 = load i32, i32* %10
%86 = add nsw i32 %85, %84
store i32 %86, i32* %10
br label %76
87: ; preds = %76
%88 = load i32, i32* @EXIT_SUCCESS
store i32 %88, i32* %3
br label %92
89: ; preds = %59
br label %90
90: ; preds = %89, %58
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %90, %87
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"%s <n>\0A\00"
@.str.6 = [23 x i8] c"%s <from> <to> <step>\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [36 x i8] c"Size\09QS\09Wirth\09AHU\09Torben\09pixel sort\00"
@str.9 = [7 x i8] c"usage:\00"
@str.10 = [46 x i8] c"\09if n=1 the output is verbose for one attempt\00"
@str.11 = [26 x i8] c"\09if n>1 the output reads:\00"
@str.12 = [41 x i8] c"\09# of elements | method1 | method2 | ...\00"
@str.13 = [48 x i8] c"\09will loop over the number of elements in input\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @putchar(i32 10)
%12 = load i8*, i8** %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.13, i64 0, i64 0))
%15 = tail call i32 @putchar(i32 10)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
switch i32 %0, label %54 [
i32 2, label %19
i32 4, label %38
]
19: ; preds = %18
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @bench(i32 1, i32 1048576)
br label %54
26: ; preds = %19
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%28 = load i8*, i8** %20
%29 = tail call i32 @atoi(i8* %28)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %54
31: ; preds = %26, %31
%32 = phi i32 [ %34, %31 ], [ 0, %26 ]
%33 = tail call i32 @bench(i32 0, i32 1048576)
%34 = add nuw nsw i32 %32, 1
%35 = load i8*, i8** %20
%36 = tail call i32 @atoi(i8* %35)
%37 = icmp slt i32 %34, %36
br i1 %37, label %31, label %54
38: ; preds = %18
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = tail call i32 @atoi(i8* %40)
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = tail call i32 @atoi(i8* %43)
%45 = getelementptr inbounds i8*, i8** %1, i64 3
%46 = load i8*, i8** %45
%47 = tail call i32 @atoi(i8* %46)
%48 = icmp sgt i32 %41, %44
br i1 %48, label %54, label %49
49: ; preds = %38, %49
%50 = phi i32 [ %52, %49 ], [ %41, %38 ]
%51 = tail call i32 @bench(i32 0, i32 %50)
%52 = add nsw i32 %50, %47
%53 = icmp sgt i32 %52, %44
br i1 %53, label %54, label %49
54: ; preds = %49, %31, %38, %26, %24, %18
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}