#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*/ printf(char *, ...);
int sorttest(void foo(int *, int, int), char *name, int debug) {
  int testarr[] = {5, 3, 1, 4, 2, 11, 9, 10, 8, 6, 7};
  foo(testarr, 0, 10);
  int i;
  int result = 1;
  for (i = 0; i < 11; i++) {
    if (debug) {
      printf("%d\n", testarr[i]);
    }
    if (testarr[i] != i + 1) {
      result = 0;
    }
  }
  if (result) {
    printf("%s test has passed.\n", name);
  } else {
    printf("%s test has failed.\n", name);
  }
  return result;
}


x86 assembly (clang, -O0):
<sorttest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec2(%rip),%rsi
mov    $0x2c,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   *%rax
movl   $0x1,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0xb,-0x44(%rbp)
jge    11c1 <sorttest+0xa1>
cmpl   $0x0,-0x14(%rbp)
je     1191 <sorttest+0x71>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    -0x44(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     11ae <sorttest+0x8e>
movl   $0x0,-0x48(%rbp)
jmp    11b3 <sorttest+0x93>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1167 <sorttest+0x47>
cmpl   $0x0,-0x48(%rbp)
je     11e2 <sorttest+0xc2>
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f4 <sorttest+0xd4>
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorttest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebx
mov    %rsi,0x40(%rsp)
mov    %rdi,%rax
movups 0xeed(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   *%rax
mov    (%rsp),%esi
test   %ebx,%ebx
je     1250 <sorttest+0x140>
lea    0xec3(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%eax
mov    %eax,0x3c(%rsp)
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
mov    %eax,0x38(%rsp)
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x34(%rsp)
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%eax
mov    %eax,0x30(%rsp)
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%r14d
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%r13d
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%r15d
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%r12d
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%ebx
mov    0x28(%rsp),%esi
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x30(%rsp),%edx
mov    0x34(%rsp),%ecx
mov    0x38(%rsp),%eax
mov    0x3c(%rsp),%esi
jmp    1278 <sorttest+0x168>
mov    0x4(%rsp),%eax
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%r14d
mov    0x18(%rsp),%r13d
mov    0x1c(%rsp),%r15d
mov    0x20(%rsp),%r12d
mov    0x24(%rsp),%ebx
xor    $0x9,%r12d
xor    $0x7,%r13d
xor    $0x5,%edx
xor    $0x3,%ecx
xor    $0x1,%esi
xor    $0x2,%eax
xor    $0x4,%ebp
or     %ecx,%ebp
or     %eax,%ebp
xor    $0x6,%r14d
or     %r13d,%r14d
or     %edx,%r14d
xor    $0x8,%r15d
or     %r12d,%r15d
xor    $0xa,%ebx
mov    0x28(%rsp),%eax
xor    $0xb,%eax
or     %ebx,%eax
or     %r15d,%eax
or     %r14d,%eax
or     %ebp,%eax
xor    %ebx,%ebx
or     %esi,%eax
sete   %bl
lea    0xd6a(%rip),%rax
lea    0xd78(%rip),%rdi
cmove  %rax,%rdi
mov    0x40(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.sorttest.testarr = [11 x i32] [i32 5, i32 3, i32 1, i32 4, i32 2, i32 11, i32 9, i32 10, i32 8, i32 6, i32 7]
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [21 x i8] c"%s test has passed.\0A\00"
@.str.2 = [21 x i8] c"%s test has failed.\0A\00"
define i32 @sorttest(void (i32*, i32, i32)* %0, i8* %1, i32 %2) {
%4 = alloca void (i32*, i32, i32)*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [11 x i32]
%8 = alloca i32
%9 = alloca i32
store void (i32*, i32, i32)* %0, void (i32*, i32, i32)** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = bitcast [11 x i32]* %7 to i8*
%11 = load void (i32*, i32, i32)*, void (i32*, i32, i32)** %4
%12 = getelementptr inbounds [11 x i32], [11 x i32]* %7, i64 0, i64 0
store i32 1, i32* %9
store i32 0, i32* %8
br label %13
13: ; preds = %35, %3
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 11
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [11 x i32], [11 x i32]* %7, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19, %16
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [11 x i32], [11 x i32]* %7, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 0, i32* %9
br label %34
34: ; preds = %33, %25
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %13
38: ; preds = %13
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %47
44: ; preds = %38
%45 = load i8*, i8** %5
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %41
%48 = load i32, i32* %9
ret i32 %48
}

LLVM IR (-O2):
@__const.sorttest.testarr = [11 x i32] [i32 5, i32 3, i32 1, i32 4, i32 2, i32 11, i32 9, i32 10, i32 8, i32 6, i32 7]
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [21 x i8] c"%s test has passed.\0A\00"
@.str.2 = [21 x i8] c"%s test has failed.\0A\00"
define i32 @sorttest(void (i32*, i32, i32)* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [11 x i32]
%5 = bitcast [11 x i32]* %4 to i8*
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 0
%7 = icmp eq i32 %2, 0
%8 = load i32, i32* %6
br i1 %7, label %9, label %28
9: ; preds = %3
%10 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 6
%21 = load i32, i32* %20
%22 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 7
%23 = load i32, i32* %22
%24 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 8
%25 = load i32, i32* %24
%26 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 9
%27 = load i32, i32* %26
br label %79
28: ; preds = %3
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%30 = load i32, i32* %6
%31 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 2
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 2
%40 = load i32, i32* %39
%41 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 3
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 3
%45 = load i32, i32* %44
%46 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 4
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 4
%50 = load i32, i32* %49
%51 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 5
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 5
%55 = load i32, i32* %54
%56 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 6
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 6
%60 = load i32, i32* %59
%61 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 7
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 7
%65 = load i32, i32* %64
%66 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 8
%67 = load i32, i32* %66
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 8
%70 = load i32, i32* %69
%71 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 9
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %72)
%74 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 9
%75 = load i32, i32* %74
%76 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 10
%77 = load i32, i32* %76
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %9, %28
%80 = phi i32 [ %27, %9 ], [ %75, %28 ]
%81 = phi i32 [ %23, %9 ], [ %65, %28 ]
%82 = phi i32 [ %19, %9 ], [ %55, %28 ]
%83 = phi i32 [ %15, %9 ], [ %45, %28 ]
%84 = phi i32 [ %11, %9 ], [ %35, %28 ]
%85 = phi i32 [ %8, %9 ], [ %30, %28 ]
%86 = phi i32 [ %13, %9 ], [ %40, %28 ]
%87 = phi i32 [ %17, %9 ], [ %50, %28 ]
%88 = phi i32 [ %21, %9 ], [ %60, %28 ]
%89 = phi i32 [ %25, %9 ], [ %70, %28 ]
%90 = icmp eq i32 %89, 9
%91 = icmp eq i32 %88, 7
%92 = icmp eq i32 %87, 5
%93 = icmp eq i32 %86, 3
%94 = icmp eq i32 %85, 1
%95 = icmp eq i32 %84, 2
%96 = icmp eq i32 %83, 4
%97 = icmp eq i32 %82, 6
%98 = icmp eq i32 %81, 8
%99 = icmp eq i32 %80, 10
%100 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 10
%101 = load i32, i32* %100
%102 = icmp eq i32 %101, 11
%103 = select i1 %102, i1 %99, i1 false
%104 = select i1 %103, i1 %90, i1 false
%105 = select i1 %104, i1 %98, i1 false
%106 = select i1 %105, i1 %91, i1 false
%107 = select i1 %106, i1 %97, i1 false
%108 = select i1 %107, i1 %92, i1 false
%109 = select i1 %108, i1 %96, i1 false
%110 = select i1 %109, i1 %93, i1 false
%111 = select i1 %110, i1 %95, i1 false
%112 = select i1 %111, i1 %94, i1 false
%113 = select i1 %112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0)
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %113, i8* %1)
%115 = zext i1 %112 to i32
ret i32 %115
}