#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 *liefere_max_int_array(int *, int);
int /*<<< orphan*/ vertausche(int *, int *);
void int_selection_sort_2(int array[], int laenge) {
  int *max = NULL;
  for (int i = laenge - 1; i > 0; i--) {
    max = liefere_max_int_array(array, i);
    if (*max > array[i])
      vertausche(max, &array[i]);
  }
}


x86 assembly (clang, -O0):
<int_selection_sort_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    119c <int_selection_sort_2+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <liefere_max_int_array@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1189 <int_selection_sort_2+0x69>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <vertausche@plt>
jmp    118e <int_selection_sort_2+0x6e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <int_selection_sort_2+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_selection_sort_2>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1160 <int_selection_sort_2+0x40>
mov    %rdi,%r14
mov    %esi,%ebx
jmp    113a <int_selection_sort_2+0x1a>
lea    0x1(%rbx),%rax
cmp    $0x2,%rax
jbe    1160 <int_selection_sort_2+0x40>
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <liefere_max_int_array@plt>
mov    (%rax),%edx
mov    %ebx,%ecx
cmp    (%r14,%rcx,4),%edx
jle    1130 <int_selection_sort_2+0x10>
lea    (%r14,%rcx,4),%rsi
mov    %rax,%rdi
call   1040 <vertausche@plt>
jmp    1130 <int_selection_sort_2+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @int_selection_sort_2(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32* null, i32** %5
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %6
br label %9
9: ; preds = %32, %2
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %35
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i32, i32* %6
%15 = call i32* @liefere_max_int_array(i32* %13, i32 %14)
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = load i32*, i32** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = icmp sgt i32 %17, %22
br i1 %23, label %24, label %31
24: ; preds = %12
%25 = load i32*, i32** %5
%26 = load i32*, i32** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = call i32 @vertausche(i32* %25, i32* %29)
br label %31
31: ; preds = %24, %12
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %9
35: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @int_selection_sort_2(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %19, %2
ret void
7: ; preds = %4, %19
%8 = phi i64 [ %5, %4 ], [ %9, %19 ]
%9 = add nsw i64 %8, -1
%10 = trunc i64 %9 to i32
%11 = tail call i32* @liefere_max_int_array(i32* %0, i32 %10)
%12 = load i32, i32* %11
%13 = and i64 %9, 4294967295
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = icmp sgt i32 %12, %15
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 @vertausche(i32* %11, i32* %14)
br label %19
19: ; preds = %7, %17
%20 = icmp ugt i64 %8, 2
br i1 %20, label %7, label %6
}