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

/* Variables and functions */
double RAND_MAX;
int /*<<< orphan*/ exit(int);
double *fmalloc(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
scalar_t__ sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int i, n, m;
  double *a, *b, result = 0;
  if (argc < 2) {
    printf("usage: %s number\n", argv[0]);
    exit(1);
  }
  if ((sscanf(argv[1], "%d", &n) == 0) || (n <= 0)) {
    printf("bad number format\n");
    exit(1);
  }
  a = fmalloc(n);
  b = fmalloc(n);
  srand(3847293);
  for (i = 0; i < n; i++) {
    a[i] = (double)rand() / RAND_MAX;
    b[i] = (double)rand() / RAND_MAX;
  }
  for (i = 0; i < m; i++)
    result += a[i] * b[i];
  printf("iloczyn: %f\n", result / n);
  free(a);
  free(b);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
je     11e3 <main+0x73>
cmpl   $0x0,-0x18(%rbp)
jg     11fb <main+0x8b>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <fmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <fmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x3ab47d,%edi
call   1060 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1286 <main+0x116>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2da5(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2d81(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1224 <main+0xb4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d3 <main+0x163>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    128d <main+0x11d>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xd40(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    126c <main+0xec>
mov    0x8(%rsi),%rdi
lea    0xe76(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1080 <sscanf@plt>
test   %rax,%rax
je     1287 <main+0x107>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    1287 <main+0x107>
call   1050 <fmalloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
call   1050 <fmalloc@plt>
mov    %rax,%r15
mov    $0x3ab47d,%edi
call   1070 <srand@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1234 <main+0xb4>
mov    0x2e00(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
xor    %eax,%eax
call   10a0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0x70>
cvtsi2sd %eax,%xmm1
xorpd  %xmm0,%xmm0
divsd  %xmm1,%xmm0
lea    0xdce(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%rsi),%rsi
lea    0xd8a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"usage: %s number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"bad number format\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.3 = [13 x i8] c"iloczyn: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26, %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %26
%33 = load i32, i32* %7
%34 = call double* @fmalloc(i32 %33)
store double* %34, double** %9
%35 = load i32, i32* %7
%36 = call double* @fmalloc(i32 %35)
store double* %36, double** %10
%37 = call i32 @srand(i32 3847293)
store i32 0, i32* %6
br label %38
38: ; preds = %59, %32
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %62
42: ; preds = %38
%43 = call i64 (...) @rand()
%44 = sitofp i64 %43 to double
%45 = load double, double* @RAND_MAX
%46 = fdiv double %44, %45
%47 = load double*, double** %9
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double %46, double* %50
%51 = call i64 (...) @rand()
%52 = sitofp i64 %51 to double
%53 = load double, double* @RAND_MAX
%54 = fdiv double %52, %53
%55 = load double*, double** %10
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
store double %54, double* %58
br label %59
59: ; preds = %42
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %38
62: ; preds = %38
store i32 0, i32* %6
br label %63
63: ; preds = %80, %62
%64 = load i32, i32* %6
%65 = load i32, i32* %8
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %83
67: ; preds = %63
%68 = load double*, double** %9
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = load double*, double** %10
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = load double, double* %11
%79 = call double @llvm.fmuladd.f64(double %72, double %77, double %78)
store double %79, double* %11
br label %80
80: ; preds = %67
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %6
br label %63
83: ; preds = %63
%84 = load double, double* %11
%85 = load i32, i32* %7
%86 = sitofp i32 %85 to double
%87 = fdiv double %84, %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %87)
%89 = load double*, double** %9
%90 = call i32 @free(double* %89)
%91 = load double*, double** %10
%92 = call i32 @free(double* %91)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"usage: %s number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@RAND_MAX = global double 0.000000e+00
@.str.3 = [13 x i8] c"iloczyn: %f\0A\00"
@str = [18 x i8] c"bad number format\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 1
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = call double* @fmalloc(i32 %15)
%23 = load i32, i32* %3
%24 = call double* @fmalloc(i32 %23)
%25 = call i32 @srand(i32 3847293)
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %21, %28
%29 = phi i64 [ %40, %28 ], [ 0, %21 ]
%30 = call i64 (...) @rand()
%31 = sitofp i64 %30 to double
%32 = load double, double* @RAND_MAX
%33 = fdiv double %31, %32
%34 = getelementptr inbounds double, double* %22, i64 %29
store double %33, double* %34
%35 = call i64 (...) @rand()
%36 = sitofp i64 %35 to double
%37 = load double, double* @RAND_MAX
%38 = fdiv double %36, %37
%39 = getelementptr inbounds double, double* %24, i64 %29
store double %38, double* %39
%40 = add nuw nsw i64 %29, 1
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %28, label %44
44: ; preds = %28, %21
%45 = phi i32 [ %26, %21 ], [ %41, %28 ]
%46 = sitofp i32 %45 to double
%47 = fdiv double 0.000000e+00, %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %47)
%49 = call i32 @free(double* %22)
%50 = call i32 @free(double* %24)
ret i32 0
}