#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, float);
int fscanf(int /*<<< orphan*/ *, char *, char **, int *, int *, int *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *ulaz, *izlaz;
  char grad[15];
  int JAN, FEB, MAR;
  ulaz = fopen("gradovi.txt", "r");
  izlaz = fopen("prosjeci.txt", "w");
  if (ulaz == NULL) {
    printf("Greska!");
    exit(1);
  }
  if (izlaz == NULL) {
    close(ulaz);
    printf("Greska!");
    exit(2);
  }
  while (fscanf(ulaz, "%15s%10d%10d%10d", &grad, &JAN, &FEB, &MAR) == 4) {
    fprintf(izlaz, "%-15s%-10.2f\n", grad, (float)((JAN + FEB + MAR) / 3.));
  }
  close(ulaz);
  close(izlaz);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe92(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <main+0x5e>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11e8 <main+0x88>
mov    -0x10(%rbp),%rdi
call   1050 <close@plt>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
jmp    11ed <main+0x8d>
mov    -0x10(%rbp),%rdi
lea    -0x27(%rbp),%rdx
lea    0xe31(%rip),%rsi
lea    -0x2c(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jne    124c <main+0xec>
mov    -0x18(%rbp),%rdi
lea    -0x27(%rbp),%rdx
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
add    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdcd(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ed <main+0x8d>
mov    -0x10(%rbp),%rdi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe93(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe8b(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %r14,%r14
je     1262 <main+0x102>
mov    %rax,%r12
test   %rax,%rax
je     1278 <main+0x118>
lea    0xe7a(%rip),%rsi
lea    0x19(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14,%rdi
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jne    1241 <main+0xe1>
lea    0x19(%rsp),%rbx
lea    0x14(%rsp),%rbp
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%eax
add    0x14(%rsp),%eax
add    0xc(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdf5(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %r12,%rdi
lea    0xe25(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
lea    0xe02(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r15,%r8
mov    %r13,%r9
call   1040 <fscanf@plt>
cmp    $0x4,%eax
je     11f0 <main+0x90>
mov    %r14,%rdi
call   1050 <close@plt>
mov    %r12,%rdi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbc(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %r14,%rdi
call   1050 <close@plt>
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"gradovi.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"prosjeci.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [8 x i8] c"Greska!\00"
@.str.5 = [17 x i8] c"%15s%10d%10d%10d\00"
@.str.6 = [14 x i8] c"%-15s%-10.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [15 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = 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* %8, i32** %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32*, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32*, i32** %2
%20 = call i32 @close(i32* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %15
br label %24
24: ; preds = %29, %23
%25 = load i32*, i32** %2
%26 = bitcast [15 x i8]* %4 to i8**
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %26, i32* %5, i32* %6, i32* %7)
%28 = icmp eq i32 %27, 4
br i1 %28, label %29, label %41
29: ; preds = %24
%30 = load i32*, i32** %3
%31 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %7
%36 = add nsw i32 %34, %35
%37 = sitofp i32 %36 to double
%38 = fdiv double %37, 3.000000e+00
%39 = fptrunc double %38 to float
%40 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %31, float %39)
br label %24
41: ; preds = %24
%42 = load i32*, i32** %2
%43 = call i32 @close(i32* %42)
%44 = load i32*, i32** %3
%45 = call i32 @close(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"gradovi.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"prosjeci.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [8 x i8] c"Greska!\00"
@.str.5 = [17 x i8] c"%15s%10d%10d%10d\00"
@.str.6 = [14 x i8] c"%-15s%-10.2f\0A\00"
define i32 @main() {
%1 = alloca [15 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = 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))
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %9, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = icmp eq i32* %10, null
br i1 %16, label %21, label %17
17: ; preds = %15
%18 = bitcast [15 x i8]* %1 to i8**
%19 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %18, i32* %2, i32* %3, i32* %4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %25, label %37
21: ; preds = %15
%22 = tail call i32 @close(i32* %9)
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 2)
unreachable
25: ; preds = %17, %25
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = add nsw i32 %27, %26
%29 = load i32, i32* %4
%30 = add nsw i32 %28, %29
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, 3.000000e+00
%33 = fptrunc double %32 to float
%34 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %5, float %33)
%35 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %18, i32* %2, i32* %3, i32* %4)
%36 = icmp eq i32 %35, 4
br i1 %36, label %25, label %37
37: ; preds = %25, %17
%38 = call i32 @close(i32* %9)
%39 = call i32 @close(i32* %10)
ret i32 0
}