#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int lines(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort_bubble(int *);
int /*<<< orphan*/ sort_qsort(int *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ utworz_spis(char *, int *);
int main(int args, char *arg[]) {
  if (args == 2) {
    char name[100];
    sscanf(arg[1], "%s", name);
    int l;
    l = lines(name);
    if (l > 10000) {
      printf("Za duzo osob! Nie dam rady!\n");
      return 0;
    }
    printf("Zeskanowalem %i linii z pliku %s\n", l, arg[1]);
    utworz_spis(name, &l);
    clock_t begin = clock();
    sort_qsort(&l);
    clock_t end = clock();
    printf("\nCzas wykonania qsorta: %lf sek.\n\n",
           (double)(end - begin) / CLOCKS_PER_SEC);
    clock_t begin2 = clock();
    sort_bubble(&l);
    clock_t end2 = clock();
    printf("\nCzas wykonania bubble: %lf sek.\n\n",
           (double)(end2 - begin2) / CLOCKS_PER_SEC);
    printf("\nPosortowane!\n\n");
    return 0;
  } else
    printf("\nNiepoprawne wywolanie programu!\n");
  printf("Wywolanie programu wymaga argumentu!\n");
  printf("./zad2b nazwapliku(lub lokalizacja pliku)!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12d2 <main+0x162>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1080 <sscanf@plt>
lea    -0x80(%rbp),%rdi
call   1090 <lines@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x2710,-0x84(%rbp)
jle    11e4 <main+0x74>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1303 <main+0x193>
mov    -0x84(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x84(%rbp),%rsi
call   1030 <utworz_spis@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %rax,-0x90(%rbp)
lea    -0x84(%rbp),%rdi
call   1050 <sort_qsort@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
sub    -0x90(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d96(%rip),%rax
divsd  (%rax),%xmm0
lea    0xde5(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x84(%rbp),%rdi
call   1040 <sort_bubble@plt>
mov    $0x0,%al
call   1060 <clock@plt>
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
sub    -0xa0(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d42(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdb4(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1303 <main+0x193>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jne    11cb <main+0x4b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe61(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1090 <sscanf@plt>
mov    %r14,%rdi
call   10a0 <lines@plt>
mov    %eax,0xc(%rsp)
cmp    $0x2710,%eax
jle    11ef <main+0x6f>
lea    0xf25(%rip),%rdi
jmp    128e <main+0x10e>
lea    0xe99(%rip),%rdi
call   1060 <puts@plt>
lea    0xeae(%rip),%rdi
call   1060 <puts@plt>
lea    0xec7(%rip),%rdi
jmp    128e <main+0x10e>
mov    0x8(%rbx),%rdx
lea    0xe09(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r14
mov    %r14,%rsi
call   1030 <utworz_spis@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <sort_qsort@plt>
xor    %eax,%eax
call   1070 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2dab(%rip),%r15
divsd  (%r15),%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
xor    %eax,%eax
call   1070 <clock@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <sort_bubble@plt>
xor    %eax,%eax
call   1070 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
lea    0xdc8(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xe4e(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [29 x i8] c"Za duzo osob! Nie dam rady!\0A\00"
@.str.2 = [34 x i8] c"Zeskanowalem %i linii z pliku %s\0A\00"
@.str.3 = [35 x i8] c"\0ACzas wykonania qsorta: %lf sek.\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [35 x i8] c"\0ACzas wykonania bubble: %lf sek.\0A\0A\00"
@.str.5 = [16 x i8] c"\0APosortowane!\0A\0A\00"
@.str.6 = [34 x i8] c"\0ANiepoprawne wywolanie programu!\0A\00"
@.str.7 = [38 x i8] c"Wywolanie programu wymaga argumentu!\0A\00"
@.str.8 = [44 x i8] c"./zad2b nazwapliku(lub lokalizacja pliku)!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %55
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i32 @lines(i8* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 10000
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %60
26: ; preds = %14
%27 = load i32, i32* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %27, i8* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%33 = call i32 @utworz_spis(i8* %32, i32* %7)
%34 = call i64 (...) @clock()
store i64 %34, i64* %8
%35 = call i32 @sort_qsort(i32* %7)
%36 = call i64 (...) @clock()
store i64 %36, i64* %9
%37 = load i64, i64* %9
%38 = load i64, i64* %8
%39 = sub nsw i64 %37, %38
%40 = sitofp i64 %39 to double
%41 = load double, double* @CLOCKS_PER_SEC
%42 = fdiv double %40, %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double %42)
%44 = call i64 (...) @clock()
store i64 %44, i64* %10
%45 = call i32 @sort_bubble(i32* %7)
%46 = call i64 (...) @clock()
store i64 %46, i64* %11
%47 = load i64, i64* %11
%48 = load i64, i64* %10
%49 = sub nsw i64 %47, %48
%50 = sitofp i64 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %60
55: ; preds = %2
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %60
60: ; preds = %57, %26, %24
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [34 x i8] c"Zeskanowalem %i linii z pliku %s\0A\00"
@.str.3 = [35 x i8] c"\0ACzas wykonania qsorta: %lf sek.\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [35 x i8] c"\0ACzas wykonania bubble: %lf sek.\0A\0A\00"
@str = [33 x i8] c"\0ANiepoprawne wywolanie programu!\00"
@str.9 = [37 x i8] c"Wywolanie programu wymaga argumentu!\00"
@str.10 = [43 x i8] c"./zad2b nazwapliku(lub lokalizacja pliku)!\00"
@str.11 = [15 x i8] c"\0APosortowane!\0A\00"
@str.12 = [28 x i8] c"Za duzo osob! Nie dam rady!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %37
6: ; preds = %2
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%11 = bitcast i32* %4 to i8*
%12 = call i32 @lines(i8* %7)
store i32 %12, i32* %4
%13 = icmp sgt i32 %12, 10000
br i1 %13, label %34, label %14
14: ; preds = %6
%15 = load i8*, i8** %8
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %15)
%17 = call i32 @utworz_spis(i8* %7, i32* %4)
%18 = call i64 (...) @clock()
%19 = call i32 @sort_qsort(i32* %4)
%20 = call i64 (...) @clock()
%21 = sub nsw i64 %20, %18
%22 = sitofp i64 %21 to double
%23 = load double, double* @CLOCKS_PER_SEC
%24 = fdiv double %22, %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), double %24)
%26 = call i64 (...) @clock()
%27 = call i32 @sort_bubble(i32* %4)
%28 = call i64 (...) @clock()
%29 = sub nsw i64 %28, %26
%30 = sitofp i64 %29 to double
%31 = load double, double* @CLOCKS_PER_SEC
%32 = fdiv double %30, %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %32)
br label %34
34: ; preds = %6, %14
%35 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0), %14 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.12, i64 0, i64 0), %6 ]
%36 = call i32 @puts(i8* dereferenceable(1) %35)
br label %41
37: ; preds = %2
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.9, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.10, i64 0, i64 0))
br label %41
41: ; preds = %37, %34
ret i32 0
}