#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 */
char getchar();
long *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sort1(long *, int);
int /*<<< orphan*/ sort2(long *, int);
void *strtol(char *, char **, int);
int /*<<< orphan*/ wypisz(long *, int);
int main(void) {
  int dlug;
  long int *tab;
  char s[10000], *er, c;
  do {
    printf("Wprowadz dlugosc tablicy: ");
    scanf("%s", s);
    dlug = strtol(s, &er, 10);
  } while (*er);
  tab = malloc(dlug * sizeof(long int));
  printf("Wprowadz %i elementow:\n", dlug);
  for (int i = 0; i < dlug; ++i) {
    scanf("%s", s);
    tab[i] = strtol(s, &er, 10);
    if (*er)
      --i;
  }
  printf("1 wypisuje liczby posortowane rosnaco przez wybieranie, 2 wypisuje "
         "liczby posortowane malejaco przez wstawianie, q konczy prace "
         "programu\n");
  while ((c = getchar()) != 'q') {
    if (c == '1') {
      sort1(tab, dlug);
      wypisz(tab, dlug);
    }
    if (c == '2') {
      sort2(tab, dlug);
      wypisz(tab, dlug);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x2720(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x2720(%rbp),%rdi
lea    -0x2728(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x8(%rbp)
mov    -0x2728(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1192 <main+0x12>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2730(%rbp)
mov    -0x2730(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1290 <main+0x110>
lea    -0x2720(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x2720(%rbp),%rdi
lea    -0x2728(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x2730(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2728(%rbp),%rax
cmpb   $0x0,(%rax)
je     1277 <main+0xf7>
mov    -0x2730(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2730(%rbp)
jmp    127c <main+0xfc>
mov    -0x2730(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2730(%rbp)
jmp    120c <main+0x8c>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x2729(%rbp)
movsbl %al,%eax
cmp    $0x71,%eax
je     130c <main+0x18c>
movsbl -0x2729(%rbp),%eax
cmp    $0x31,%eax
jne    12df <main+0x15f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10a0 <sort1@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <wypisz@plt>
movsbl -0x2729(%rbp),%eax
cmp    $0x32,%eax
jne    1307 <main+0x187>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <sort2@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <wypisz@plt>
jmp    129e <main+0x11e>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
lea    0xe58(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c0 <main+0x30>
lea    0x0(,%rbx,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe16(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1264 <main+0xd4>
lea    0xdfd(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
movslq %ebp,%rbp
mov    %rax,(%r14,%rbp,8)
mov    0x8(%rsp),%rax
cmpb   $0x1,(%rax)
adc    $0xffffffff,%ebp
add    $0x1,%ebp
cmp    %ebx,%ebp
jl     1230 <main+0xa0>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
jmp    1294 <main+0x104>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <sort2@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10a0 <wypisz@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x31,%al
je     12b0 <main+0x120>
cmp    $0x32,%al
je     1280 <main+0xf0>
cmp    $0x71,%al
jne    1294 <main+0x104>
jmp    12bc <main+0x12c>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   10b0 <sort1@plt>
jmp    128a <main+0xfa>
xor    %eax,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Wprowadz dlugosc tablicy: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Wprowadz %i elementow:\0A\00"
@.str.3 = [138 x i8] c"1 wypisuje liczby posortowane rosnaco przez wybieranie, 2 wypisuje liczby posortowane malejaco przez wstawianie, q konczy prace programu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64*
%4 = alloca [10000 x i8]
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
br label %8
8: ; preds = %15, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%13 = call i8* @strtol(i8* %12, i8** %5, i32 10)
%14 = ptrtoint i8* %13 to i32
store i32 %14, i32* %2
br label %15
15: ; preds = %8
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %8, label %19
19: ; preds = %15
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64* @malloc(i32 %23)
store i64* %24, i64** %3
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %25)
store i32 0, i32* %7
br label %27
27: ; preds = %48, %19
%28 = load i32, i32* %7
%29 = load i32, i32* %2
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %51
31: ; preds = %27
%32 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%35 = call i8* @strtol(i8* %34, i8** %5, i32 10)
%36 = ptrtoint i8* %35 to i64
%37 = load i64*, i64** %3
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i64, i64* %37, i64 %39
store i64 %36, i64* %40
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %31
%45 = load i32, i32* %7
%46 = add nsw i32 %45, -1
store i32 %46, i32* %7
br label %47
47: ; preds = %44, %31
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %27
51: ; preds = %27
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %79, %51
%54 = call signext i8 (...) @getchar()
store i8 %54, i8* %6
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 113
br i1 %56, label %57, label %80
57: ; preds = %53
%58 = load i8, i8* %6
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 49
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i64*, i64** %3
%63 = load i32, i32* %2
%64 = call i32 @sort1(i64* %62, i32 %63)
%65 = load i64*, i64** %3
%66 = load i32, i32* %2
%67 = call i32 @wypisz(i64* %65, i32 %66)
br label %68
68: ; preds = %61, %57
%69 = load i8, i8* %6
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 50
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i64*, i64** %3
%74 = load i32, i32* %2
%75 = call i32 @sort2(i64* %73, i32 %74)
%76 = load i64*, i64** %3
%77 = load i32, i32* %2
%78 = call i32 @wypisz(i64* %76, i32 %77)
br label %79
79: ; preds = %72, %68
br label %53
80: ; preds = %53
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Wprowadz dlugosc tablicy: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Wprowadz %i elementow:\0A\00"
@str = [137 x i8] c"1 wypisuje liczby posortowane rosnaco przez wybieranie, 2 wypisuje liczby posortowane malejaco przez wstawianie, q konczy prace programu\00"
define i32 @main() {
%1 = alloca [10000 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
br label %5
5: ; preds = %5, %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i8* @strtol(i8* %3, i8** %2, i32 10)
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = ptrtoint i8* %8 to i64
%14 = trunc i64 %13 to i32
%15 = shl i32 %14, 3
%16 = call i64* @malloc(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%18 = icmp sgt i32 %14, 0
br i1 %18, label %21, label %19
19: ; preds = %21, %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([137 x i8], [137 x i8]* @str, i64 0, i64 0))
br label %35
21: ; preds = %12, %21
%22 = phi i32 [ %33, %21 ], [ 0, %12 ]
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%24 = call i8* @strtol(i8* %3, i8** %2, i32 10)
%25 = ptrtoint i8* %24 to i64
%26 = sext i32 %22 to i64
%27 = getelementptr inbounds i64, i64* %16, i64 %26
store i64 %25, i64* %27
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
%31 = sext i1 %30 to i32
%32 = add nsw i32 %22, 1
%33 = add nsw i32 %32, %31
%34 = icmp slt i32 %33, %14
br i1 %34, label %21, label %19
35: ; preds = %43, %19
%36 = call signext i8 (...) @getchar()
switch i8 %36, label %43 [
i8 113, label %44
i8 49, label %37
i8 50, label %39
]
37: ; preds = %35
%38 = call i32 @sort1(i64* %16, i32 %14)
br label %41
39: ; preds = %35
%40 = call i32 @sort2(i64* %16, i32 %14)
br label %41
41: ; preds = %39, %37
%42 = call i32 @wypisz(i64* %16, i32 %14)
br label %43
43: ; preds = %41, %35
br label %35
44: ; preds = %35
ret i32 0
}