#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 int /*<<< orphan*/ time_t;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, double);
int rand();
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void punjenjeListe(int lista[], int odabir, int brojGeneriranihZnakova) {
  time_t startTime, endTime;
  double diffTime;
  int i;
  if (odabir == 1) {
    time(&startTime);
    for (i = 0; i < brojGeneriranihZnakova; i++) {
      lista[i] = rand();
    }
    time(&endTime);
    diffTime = difftime(endTime, startTime);
    printf("Dodavanje na pocetak %d slucajno generiranih znakova trajalo je: "
           "%lf s",
           brojGeneriranihZnakova, diffTime);
  }
  if (odabir == 2) {
    time(&startTime);
    for (i = 100000 / 2; i < (100000 / 2) + brojGeneriranihZnakova; i++) {
      lista[i] = rand();
    }
    time(&endTime);
    diffTime = difftime(endTime, startTime);
    printf(
        "Dodavanje u sredinu %d slucajno generiranih znakova trajalo je: %lf s",
        brojGeneriranihZnakova, diffTime);
  }
  if (odabir == 3) {
    time(&startTime);
    for (i = 100000; i >= 100000 - brojGeneriranihZnakova; i--) {
      lista[i] = rand();
    }
    time(&endTime);
    diffTime = difftime(endTime, startTime);
    printf(
        "Dodavanje na kraj %d slucajno generiranih znakova trajalo je: %lf s",
        brojGeneriranihZnakova, diffTime);
  }
}


x86 assembly (clang, -O0):
<punjenjeListe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11c7 <punjenjeListe+0x87>
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <punjenjeListe+0x5a>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <punjenjeListe+0x2c>
lea    -0x18(%rbp),%rdi
call   1050 <time@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0xc(%rbp)
jne    1244 <punjenjeListe+0x104>
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
movl   $0xc350,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0xc350,%ecx
cmp    %ecx,%eax
jge    1217 <punjenjeListe+0xd7>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e1 <punjenjeListe+0xa1>
lea    -0x18(%rbp),%rdi
call   1050 <time@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x3,-0xc(%rbp)
jne    12c0 <punjenjeListe+0x180>
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
movl   $0x186a0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x186a0,%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jl     1293 <punjenjeListe+0x153>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    125e <punjenjeListe+0x11e>
lea    -0x18(%rbp),%rdi
call   1050 <time@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<punjenjeListe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rdi,%r12
cmp    $0x3,%esi
je     1244 <punjenjeListe+0x104>
mov    %esi,%r15d
cmp    $0x2,%esi
je     11c7 <punjenjeListe+0x87>
cmp    $0x1,%r15d
jne    12ab <punjenjeListe+0x16b>
lea    0xc(%rsp),%rdi
call   1050 <time@plt>
test   %r14d,%r14d
jle    11a4 <punjenjeListe+0x64>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <punjenjeListe+0x50>
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1040 <difftime@plt>
lea    0xe3e(%rip),%rdi
jmp    12a3 <punjenjeListe+0x163>
lea    0xc(%rsp),%rdi
call   1050 <time@plt>
test   %r14d,%r14d
jle    1218 <punjenjeListe+0xd8>
lea    0xc34f(%r14),%eax
cmp    $0xc351,%eax
mov    $0xc350,%ebp
cmovge %eax,%ebp
add    $0xffffffffffff3cb1,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x30d40(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <punjenjeListe+0xc0>
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1040 <difftime@plt>
lea    0xe11(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
cmp    $0x3,%r15d
jne    12ab <punjenjeListe+0x16b>
lea    0xc(%rsp),%rdi
call   1050 <time@plt>
test   %r14d,%r14d
js     1285 <punjenjeListe+0x145>
mov    $0x186a0,%eax
sub    %r14d,%eax
movslq %eax,%rbp
mov    $0x186a1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,-0x4(%r12,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    %rbp,%rbx
jg     1270 <punjenjeListe+0x130>
lea    0x8(%rsp),%rdi
call   1050 <time@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1040 <difftime@plt>
lea    0xdea(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [71 x i8] c"Dodavanje na pocetak %d slucajno generiranih znakova trajalo je: %lf s\00"
@.str.1 = [70 x i8] c"Dodavanje u sredinu %d slucajno generiranih znakova trajalo je: %lf s\00"
@.str.2 = [68 x i8] c"Dodavanje na kraj %d slucajno generiranih znakova trajalo je: %lf s\00"
define void @punjenjeListe(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %36
13: ; preds = %3
%14 = call i32 @time(i32* %7)
store i32 0, i32* %10
br label %15
15: ; preds = %25, %13
%16 = load i32, i32* %10
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = load i32*, i32** %4
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
br label %15
28: ; preds = %15
%29 = call i32 @time(i32* %8)
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = call double @difftime(i32 %30, i32 %31)
store double %32, double* %9
%33 = load i32, i32* %6
%34 = load double, double* %9
%35 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %33, double %34)
br label %36
36: ; preds = %28, %3
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %63
39: ; preds = %36
%40 = call i32 @time(i32* %7)
store i32 50000, i32* %10
br label %41
41: ; preds = %52, %39
%42 = load i32, i32* %10
%43 = load i32, i32* %6
%44 = add nsw i32 50000, %43
%45 = icmp slt i32 %42, %44
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = call i32 (...) @rand()
%48 = load i32*, i32** %4
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
store i32 %47, i32* %51
br label %52
52: ; preds = %46
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %41
55: ; preds = %41
%56 = call i32 @time(i32* %8)
%57 = load i32, i32* %8
%58 = load i32, i32* %7
%59 = call double @difftime(i32 %57, i32 %58)
store double %59, double* %9
%60 = load i32, i32* %6
%61 = load double, double* %9
%62 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %60, double %61)
br label %63
63: ; preds = %55, %36
%64 = load i32, i32* %5
%65 = icmp eq i32 %64, 3
br i1 %65, label %66, label %90
66: ; preds = %63
%67 = call i32 @time(i32* %7)
store i32 100000, i32* %10
br label %68
68: ; preds = %79, %66
%69 = load i32, i32* %10
%70 = load i32, i32* %6
%71 = sub nsw i32 100000, %70
%72 = icmp sge i32 %69, %71
br i1 %72, label %73, label %82
73: ; preds = %68
%74 = call i32 (...) @rand()
%75 = load i32*, i32** %4
%76 = load i32, i32* %10
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %75, i64 %77
store i32 %74, i32* %78
br label %79
79: ; preds = %73
%80 = load i32, i32* %10
%81 = add nsw i32 %80, -1
store i32 %81, i32* %10
br label %68
82: ; preds = %68
%83 = call i32 @time(i32* %8)
%84 = load i32, i32* %8
%85 = load i32, i32* %7
%86 = call double @difftime(i32 %84, i32 %85)
store double %86, double* %9
%87 = load i32, i32* %6
%88 = load double, double* %9
%89 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %87, double %88)
br label %90
90: ; preds = %82, %63
ret void
}

LLVM IR (-O2):
@.str = [71 x i8] c"Dodavanje na pocetak %d slucajno generiranih znakova trajalo je: %lf s\00"
@.str.1 = [70 x i8] c"Dodavanje u sredinu %d slucajno generiranih znakova trajalo je: %lf s\00"
@.str.2 = [68 x i8] c"Dodavanje na kraj %d slucajno generiranih znakova trajalo je: %lf s\00"
define void @punjenjeListe(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
switch i32 %1, label %64 [
i32 1, label %8
i32 2, label %25
i32 3, label %46
]
8: ; preds = %3
%9 = call i32 @time(i32* %4)
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %17, %13 ]
%15 = call i32 (...) @rand()
%16 = getelementptr inbounds i32, i32* %0, i64 %14
store i32 %15, i32* %16
%17 = add nuw nsw i64 %14, 1
%18 = icmp eq i64 %17, %12
br i1 %18, label %19, label %13
19: ; preds = %13, %8
%20 = call i32 @time(i32* %5)
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = call double @difftime(i32 %21, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %2, double %23)
br label %64
25: ; preds = %3
%26 = call i32 @time(i32* %4)
%27 = icmp sgt i32 %2, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = add nuw i32 %2, 49999
%30 = call i32 @llvm.smax.i32(i32 %29, i32 50000)
%31 = add nuw i32 %30, 1
%32 = zext i32 %31 to i64
br label %33
33: ; preds = %28, %33
%34 = phi i64 [ 50000, %28 ], [ %37, %33 ]
%35 = call i32 (...) @rand()
%36 = getelementptr inbounds i32, i32* %0, i64 %34
store i32 %35, i32* %36
%37 = add nuw nsw i64 %34, 1
%38 = icmp eq i64 %37, %32
br i1 %38, label %39, label %33
39: ; preds = %33, %25
%40 = call i32 @time(i32* %5)
%41 = load i32, i32* %5
%42 = load i32, i32* %4
%43 = call double @difftime(i32 %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %2, double %43)
%45 = icmp eq i32 %1, 3
br i1 %45, label %46, label %64
46: ; preds = %3, %39
%47 = call i32 @time(i32* %4)
%48 = icmp slt i32 %2, 0
br i1 %48, label %58, label %49
49: ; preds = %46
%50 = sub nsw i32 100000, %2
%51 = sext i32 %50 to i64
br label %52
52: ; preds = %49, %52
%53 = phi i64 [ 100000, %49 ], [ %56, %52 ]
%54 = call i32 (...) @rand()
%55 = getelementptr inbounds i32, i32* %0, i64 %53
store i32 %54, i32* %55
%56 = add nsw i64 %53, -1
%57 = icmp sgt i64 %53, %51
br i1 %57, label %52, label %58
58: ; preds = %52, %46
%59 = call i32 @time(i32* %5)
%60 = load i32, i32* %5
%61 = load i32, i32* %4
%62 = call double @difftime(i32 %60, i32 %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %2, double %62)
br label %64
64: ; preds = %19, %3, %58, %39
ret void
}