#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *f;
  int n, i, x, sum, min, max;
  f = fopen("primer2.txt", "r");
  if (f == NULL) {
    printf("Datoteka primer2.txt nije otvorena");
    exit(1);
  }
  sum = 0;
  fscanf(f, "%d", &n);
  for (i = 1; i <= n; i++) {
    fscanf(f, "%d", &x);
    sum += x;
    if (i == 1)
      min = max = x;
    else {
      if (x < min)
        min = x;
      if (x > max)
        ;
      max = x;
    }
  }
  printf("Min. = %d\n", min);
  printf("Max. = %d\n", max);
  printf("Avg. = %lf\n", (double)sum / n);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1238 <main+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe5f(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    11fc <main+0xac>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    %eax,-0x24(%rbp)
jmp    1225 <main+0xd5>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    120e <main+0xbe>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    121f <main+0xcf>
jmp    121f <main+0xcf>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    122a <main+0xda>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <main+0x6b>
mov    -0x24(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdl -0x20(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xddb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1223 <main+0xd3>
mov    %rax,%r12
lea    0xeb0(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
xor    %r14d,%r14d
lea    0x4(%rsp),%r15
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
lea    0xe87(%rip),%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    0x4(%rsp),%ebx
add    %ebx,%r13d
cmp    %ebp,%ebx
cmovl  %ebx,%ebp
test   %r14d,%r14d
cmove  %ebx,%ebp
add    $0x1,%r14d
cmp    (%rsp),%r14d
jl     11a0 <main+0x50>
lea    0xe5f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cvtsi2sd %r13d,%xmm0
cvtsi2sdl (%rsp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe47(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"primer2.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"Datoteka primer2.txt nije otvorena\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [11 x i8] c"Min. = %d\0A\00"
@.str.5 = [11 x i8] c"Max. = %d\0A\00"
@.str.6 = [12 x i8] c"Avg. = %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
store i32 0, i32* %6
%16 = load i32*, i32** %2
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
store i32 1, i32* %4
br label %18
18: ; preds = %46, %15
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load i32*, i32** %2
%24 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add nsw i32 %26, %25
store i32 %27, i32* %6
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load i32, i32* %5
store i32 %31, i32* %8
store i32 %31, i32* %7
br label %45
32: ; preds = %22
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i32, i32* %5
store i32 %37, i32* %7
br label %38
38: ; preds = %36, %32
%39 = load i32, i32* %5
%40 = load i32, i32* %8
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %38
br label %43
43: ; preds = %42, %38
%44 = load i32, i32* %5
store i32 %44, i32* %8
br label %45
45: ; preds = %43, %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %18
49: ; preds = %18
%50 = load i32, i32* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %6
%55 = sitofp i32 %54 to double
%56 = load i32, i32* %3
%57 = sitofp i32 %56 to double
%58 = fdiv double %55, %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %58)
%60 = load i32*, i32** %2
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"primer2.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"Datoteka primer2.txt nije otvorena\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [11 x i8] c"Min. = %d\0A\00"
@.str.5 = [11 x i8] c"Max. = %d\0A\00"
@.str.6 = [12 x i8] c"Avg. = %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br label %14
14: ; preds = %10, %14
%15 = phi i32 [ %24, %14 ], [ undef, %10 ]
%16 = phi i32 [ %20, %14 ], [ 0, %10 ]
%17 = phi i32 [ %25, %14 ], [ 1, %10 ]
%18 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, %16
%21 = icmp eq i32 %17, 1
%22 = icmp slt i32 %19, %15
%23 = select i1 %21, i1 true, i1 %22
%24 = select i1 %23, i32 %19, i32 %15
%25 = add nuw nsw i32 %17, 1
%26 = load i32, i32* %1
%27 = icmp slt i32 %17, %26
br i1 %27, label %14, label %28
28: ; preds = %14
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%31 = sitofp i32 %20 to double
%32 = load i32, i32* %1
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %34)
%36 = call i32 @fclose(i32* %5)
ret i32 0
}