#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 */
int RAND_MAX;
double *calloc(int, int);
int /*<<< orphan*/ printf(char *, double);
int rand();
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  char *stringa;
  int i, j, N;
  double s = 0, *A;
  stringa = argv[1];
  sscanf(stringa, "%u", &N);
  printf("%u 	\n", N);
  A = calloc(N * N, sizeof(double));
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      A[i + j * N] = 1. * rand() / RAND_MAX;
      s += A[i + j * N];
    }
  }
  printf("%f ", s);
  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,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
cvtsi2sdl -0x24(%rbp),%xmm0
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
imul   -0x24(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    124b <main+0x10b>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1238 <main+0xf8>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe23(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e00(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x24(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x24(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11be <main+0x7e>
jmp    123d <main+0xfd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ab <main+0x6b>
movsd  -0x30(%rbp),%xmm0
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
lea    0xea9(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
cvtsi2sdl 0x4(%rsp),%xmm0
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
imul   %ebp,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %ebp,%ebp
jle    1203 <main+0xc3>
mov    %rax,%r15
xorpd  %xmm0,%xmm0
mov    0x2e50(%rip),%r14
xor    %r12d,%r12d
jmp    11a9 <main+0x69>
nopl   (%rax)
add    $0x1,%r12d
cmp    %ebp,%r12d
jge    1207 <main+0xc7>
test   %ebp,%ebp
jle    11a0 <main+0x60>
xor    %ebx,%ebx
nop
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%r14),%xmm1
divsd  %xmm1,%xmm0
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
imul   %ebx,%eax
add    %r12d,%eax
cltq
movsd  %xmm0,(%r15,%rax,8)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebx
cmp    %ebp,%ebx
jl     11b0 <main+0x70>
jmp    11a0 <main+0x60>
xorpd  %xmm0,%xmm0
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"%u \09\0A\00"
@RAND_MAX = global i32 0
@.str.2 = [4 x i8] c"%f \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%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* %10
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%17 = load i32, i32* %9
%18 = sitofp i32 %17 to double
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %18)
%20 = load i32, i32* %9
%21 = load i32, i32* %9
%22 = mul nsw i32 %20, %21
%23 = call double* @calloc(i32 %22, i32 8)
store double* %23, double** %11
store i32 0, i32* %7
br label %24
24: ; preds = %63, %2
%25 = load i32, i32* %7
%26 = load i32, i32* %9
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %66
28: ; preds = %24
store i32 0, i32* %8
br label %29
29: ; preds = %59, %28
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %62
33: ; preds = %29
%34 = call i32 (...) @rand()
%35 = sitofp i32 %34 to double
%36 = fmul double 1.000000e+00, %35
%37 = load i32, i32* @RAND_MAX
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
%40 = load double*, double** %11
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = mul nsw i32 %42, %43
%45 = add nsw i32 %41, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %40, i64 %46
store double %39, double* %47
%48 = load double*, double** %11
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = mul nsw i32 %50, %51
%53 = add nsw i32 %49, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %48, i64 %54
%56 = load double, double* %55
%57 = load double, double* %10
%58 = fadd double %57, %56
store double %58, double* %10
br label %59
59: ; preds = %33
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %29
62: ; preds = %29
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %24
66: ; preds = %24
%67 = load double, double* %10
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"%u \09\0A\00"
@RAND_MAX = global i32 0
@.str.2 = [4 x i8] c"%f \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = sitofp i32 %8 to double
%10 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %9)
%11 = load i32, i32* %3
%12 = mul nsw i32 %11, %11
%13 = call double* @calloc(i32 %12, i32 8)
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %41
15: ; preds = %2, %36
%16 = phi i32 [ %37, %36 ], [ %11, %2 ]
%17 = phi i32 [ %39, %36 ], [ 0, %2 ]
%18 = phi double [ %38, %36 ], [ 0.000000e+00, %2 ]
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %36
20: ; preds = %15, %20
%21 = phi double [ %33, %20 ], [ %18, %15 ]
%22 = phi i32 [ %34, %20 ], [ 0, %15 ]
%23 = call i32 (...) @rand()
%24 = sitofp i32 %23 to double
%25 = load i32, i32* @RAND_MAX
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
%28 = load i32, i32* %3
%29 = mul nsw i32 %28, %22
%30 = add nsw i32 %29, %17
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %13, i64 %31
store double %27, double* %32
%33 = fadd double %21, %27
%34 = add nuw nsw i32 %22, 1
%35 = icmp slt i32 %34, %28
br i1 %35, label %20, label %36
36: ; preds = %20, %15
%37 = phi i32 [ %16, %15 ], [ %28, %20 ]
%38 = phi double [ %18, %15 ], [ %33, %20 ]
%39 = add nuw nsw i32 %17, 1
%40 = icmp slt i32 %39, %37
br i1 %40, label %15, label %41
41: ; preds = %36, %2
%42 = phi double [ 0.000000e+00, %2 ], [ %38, %36 ]
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %42)
ret i32 0
}