#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*/ *fopen(char *, char *);
int /*<<< orphan*/ print_arr(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int read_arr(int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ srednee(int *, int, float *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ writing(int /*<<< orphan*/ *, float);
int main(int argc, char **argv) {
  setbuf(stdout, NULL);
  int arr[20];
  int size;
  float sredn;
  FILE *f1, *f2;
  if (argc != 3) {
    printf("Incorrect args count");
    return -1;
  }
  f1 = fopen(argv[1], "r");
  f2 = fopen(argv[2], "w");
  if ((f1 == NULL) || (f2 == NULL)) {
    printf("There is an error with opening files\n");
    return -3;
  }
  if (read_arr(f1, arr, &size) == -2) {
    printf("There are no numbers in the file\n");
    return -2;
  } else {
    printf("An array:\n");
    print_arr(arr, size);
    if (srednee(arr, size, &sredn) == 0) {
      writing(f2, sredn);
      printf("\nSrednee had been written in the second file\n");
      printf("Srednee = %f", sredn);
      return -4;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11bf <main+0x4f>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d2 <main+0x162>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1205 <main+0x95>
cmpq   $0x0,-0x78(%rbp)
jne    121f <main+0xaf>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12d2 <main+0x162>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
call   1060 <read_arr@plt>
cmp    $0xfffffffe,%eax
jne    1253 <main+0xe3>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d2 <main+0x162>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1030 <print_arr@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
lea    -0x68(%rbp),%rdx
call   1080 <srednee@plt>
cmp    $0x0,%rax
jne    12c6 <main+0x156>
mov    -0x78(%rbp),%rdi
movss  -0x68(%rbp),%xmm0
call   1070 <writing@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movss  -0x68(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde7(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    12d2 <main+0x162>
jmp    12cb <main+0x15b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
cmp    $0x3,%ebp
jne    11ff <main+0x7f>
mov    0x8(%rbx),%rdi
lea    0xe68(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %r14,%r14
je     1217 <main+0x97>
mov    %rax,%rbx
test   %rax,%rax
je     1217 <main+0x97>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1070 <read_arr@plt>
cmp    $0xfffffffe,%eax
jne    122a <main+0xaa>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%eax
jmp    1299 <main+0x119>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1299 <main+0x119>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffd,%eax
jmp    1299 <main+0x119>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <print_arr@plt>
mov    0xc(%rsp),%esi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1090 <srednee@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1299 <main+0x119>
movss  0x8(%rsp),%xmm0
mov    %rbx,%rdi
call   1080 <writing@plt>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd8c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0xfffffffc,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [21 x i8] c"Incorrect args count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [38 x i8] c"There is an error with opening files\0A\00"
@.str.4 = [34 x i8] c"There are no numbers in the file\0A\00"
@.str.5 = [11 x i8] c"An array:\0A\00"
@.str.6 = [46 x i8] c"\0ASrednee had been written in the second file\0A\00"
@.str.7 = [13 x i8] c"Srednee = %f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i32]
%7 = alloca i32
%8 = alloca float
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @stdout
%12 = call i32 @setbuf(i32 %11, i32* null)
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %59
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %9
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %9
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %17
%29 = load i32*, i32** %10
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28, %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 -3, i32* %3
br label %59
33: ; preds = %28
%34 = load i32*, i32** %9
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%36 = call i32 @read_arr(i32* %34, i32* %35, i32* %7)
%37 = icmp eq i32 %36, -2
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 -2, i32* %3
br label %59
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i32 @print_arr(i32* %42, i32 %43)
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%46 = load i32, i32* %7
%47 = call i64 @srednee(i32* %45, i32 %46, float* %8)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %40
%50 = load i32*, i32** %10
%51 = load float, float* %8
%52 = call i32 @writing(i32* %50, float %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
%54 = load float, float* %8
%55 = fpext float %54 to double
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), double %55)
store i32 -4, i32* %3
br label %59
57: ; preds = %40
br label %58
58: ; preds = %57
store i32 0, i32* %3
br label %59
59: ; preds = %58, %49, %38, %31, %15
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [21 x i8] c"Incorrect args count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.7 = [13 x i8] c"Srednee = %f\00"
@str = [10 x i8] c"An array:\00"
@str.8 = [45 x i8] c"\0ASrednee had been written in the second file\00"
@str.9 = [33 x i8] c"There are no numbers in the file\00"
@str.10 = [37 x i8] c"There is an error with opening files\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i32]
%4 = alloca i32
%5 = alloca float
%6 = load i32, i32* @stdout
%7 = tail call i32 @setbuf(i32 %6, i32* null)
%8 = bitcast [20 x i32]* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast float* %5 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %46
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %17, null
%22 = icmp eq i32* %20, null
%23 = or i1 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.10, i64 0, i64 0))
br label %46
26: ; preds = %14
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%28 = call i32 @read_arr(i32* %17, i32* %27, i32* %4)
%29 = icmp eq i32 %28, -2
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.9, i64 0, i64 0))
br label %46
32: ; preds = %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 @print_arr(i32* %27, i32 %34)
%36 = load i32, i32* %4
%37 = call i64 @srednee(i32* %27, i32 %36, float* %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load float, float* %5
%41 = call i32 @writing(i32* %20, float %40)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.8, i64 0, i64 0))
%43 = load float, float* %5
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), double %44)
br label %46
46: ; preds = %32, %39, %30, %24, %12
%47 = phi i32 [ -1, %12 ], [ -3, %24 ], [ -2, %30 ], [ -4, %39 ], [ 0, %32 ]
ret i32 %47
}