#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num;
  printf("Enter the size of array : ");
  scanf("%d", &num);
  int a[num];
  printf("Enter array elements");
  for (int i = 0; i < num; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 0; i < num; i++) {
    ans = ans + (a[i] * (num - i) * (i + 1));
  }
  printf("The sum of all subarrays is : %d", ans);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11be <main+0x9e>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xea3(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <main+0x69>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120b <main+0xeb>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%eax
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
mov    -0x8(%rbp),%edx
sub    -0x24(%rbp),%edx
imul   %edx,%ecx
mov    -0x24(%rbp),%edx
add    $0x1,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cc <main+0xac>
mov    -0x20(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf3b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf79(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xf1b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    132b <main+0x20b>
xor    %r13d,%r13d
lea    0xf33(%rip),%r14
mov    %r12,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1190 <main+0x70>
mov    %eax,%eax
test   %eax,%eax
jle    11c0 <main+0xa0>
cmp    $0x8,%eax
jae    11c7 <main+0xa7>
xor    %ecx,%ecx
xor    %ebx,%ebx
jmp    1307 <main+0x1e7>
xor    %ebx,%ebx
jmp    132b <main+0x20b>
movd   %eax,%xmm0
mov    %eax,%ecx
and    $0xfffffff8,%ecx
pshufd $0x0,%xmm0,%xmm12
lea    0x0(,%rax,4),%rdx
and    $0xffffffffffffffe0,%rdx
movaps 0xe17(%rip),%xmm1
movaps 0xe20(%rip),%xmm7
movdqa 0xe28(%rip),%xmm4
pxor   %xmm14,%xmm14
xor    %esi,%esi
pcmpeqd %xmm9,%xmm9
movdqa 0xe33(%rip),%xmm10
movdqa 0xe3a(%rip),%xmm13
movdqa 0xe41(%rip),%xmm11
pxor   %xmm15,%xmm15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa %xmm12,%xmm0
psubd  %xmm4,%xmm0
movaps %xmm7,%xmm3
shufps $0x88,%xmm1,%xmm3
movaps %xmm3,%xmm5
psubd  %xmm9,%xmm5
pshufd $0xf5,%xmm0,%xmm2
pshufd $0xf5,%xmm5,%xmm6
pmuludq %xmm0,%xmm5
psubd  0xdd2(%rip),%xmm0
paddd  %xmm10,%xmm3
pmuludq %xmm2,%xmm6
pshufd $0xf5,%xmm0,%xmm2
pshufd $0xf5,%xmm3,%xmm8
pmuludq %xmm2,%xmm8
pmuludq %xmm0,%xmm3
movdqa (%r12,%rsi,1),%xmm0
pmuludq %xmm0,%xmm5
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm6,%xmm0
pshufd $0xe8,%xmm5,%xmm2
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
paddd  %xmm2,%xmm14
movdqa 0x10(%r12,%rsi,1),%xmm0
pmuludq %xmm0,%xmm3
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm8,%xmm0
pshufd $0xe8,%xmm3,%xmm2
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
paddd  %xmm2,%xmm15
paddq  %xmm13,%xmm7
paddq  %xmm13,%xmm1
paddd  %xmm11,%xmm4
add    $0x20,%rsi
cmp    %rsi,%rdx
jne    1230 <main+0x110>
paddd  %xmm14,%xmm15
pshufd $0xee,%xmm15,%xmm0
paddd  %xmm15,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebx
cmp    %rax,%rcx
je     132b <main+0x20b>
mov    %eax,%edx
sub    %ecx,%edx
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rsi
mov    %esi,%edi
imul   %edx,%edi
imul   (%r12,%rcx,4),%edi
add    %edi,%ebx
add    $0xffffffff,%edx
mov    %rsi,%rcx
cmp    %rsi,%rax
jne    1310 <main+0x1f0>
lea    0xd6e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter the size of array : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Enter array elements\00"
@.str.3 = [33 x i8] c"The sum of all subarrays is : %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %15
15: ; preds = %24, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %13, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
store i32 0, i32* %6
store i32 0, i32* %7
br label %28
28: ; preds = %46, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %49
32: ; preds = %28
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %13, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %2
%39 = load i32, i32* %7
%40 = sub nsw i32 %38, %39
%41 = mul nsw i32 %37, %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
%44 = mul nsw i32 %41, %43
%45 = add nsw i32 %33, %44
store i32 %45, i32* %6
br label %46
46: ; preds = %32
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %28
49: ; preds = %28
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load i8*, i8** %3
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter the size of array : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Enter array elements\00"
@.str.3 = [33 x i8] c"The sum of all subarrays is : %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %59, label %67
12: ; preds = %59
%13 = icmp sgt i32 %64, 0
br i1 %13, label %14, label %67
14: ; preds = %12
%15 = zext i32 %64 to i64
%16 = icmp ult i32 %64, 8
br i1 %16, label %56, label %17
17: ; preds = %14
%18 = and i64 %15, 4294967288
%19 = insertelement <4 x i32> poison, i32 %64, i64 0
%20 = shufflevector <4 x i32> %19, <4 x i32> poison, <4 x i32> zeroinitializer
%21 = insertelement <4 x i32> poison, i32 %64, i64 0
%22 = shufflevector <4 x i32> %21, <4 x i32> poison, <4 x i32> zeroinitializer
br label %23
23: ; preds = %23, %17
%24 = phi i64 [ 0, %17 ], [ %48, %23 ]
%25 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %17 ], [ %49, %23 ]
%26 = phi <4 x i32> [ zeroinitializer, %17 ], [ %46, %23 ]
%27 = phi <4 x i32> [ zeroinitializer, %17 ], [ %47, %23 ]
%28 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %17 ], [ %50, %23 ]
%29 = add <4 x i32> %28, <i32 4, i32 4, i32 4, i32 4>
%30 = getelementptr inbounds i32, i32* %8, i64 %24
%31 = bitcast i32* %30 to <4 x i32>*
%32 = load <4 x i32>, <4 x i32>* %31
%33 = getelementptr inbounds i32, i32* %30, i64 4
%34 = bitcast i32* %33 to <4 x i32>*
%35 = load <4 x i32>, <4 x i32>* %34
%36 = sub nsw <4 x i32> %20, %28
%37 = sub nsw <4 x i32> %22, %29
%38 = trunc <4 x i64> %25 to <4 x i32>
%39 = add <4 x i32> %38, <i32 1, i32 1, i32 1, i32 1>
%40 = trunc <4 x i64> %25 to <4 x i32>
%41 = add <4 x i32> %40, <i32 5, i32 5, i32 5, i32 5>
%42 = mul <4 x i32> %36, %39
%43 = mul <4 x i32> %37, %41
%44 = mul <4 x i32> %42, %32
%45 = mul <4 x i32> %43, %35
%46 = add <4 x i32> %44, %26
%47 = add <4 x i32> %45, %27
%48 = add nuw i64 %24, 8
%49 = add <4 x i64> %25, <i64 8, i64 8, i64 8, i64 8>
%50 = add <4 x i32> %28, <i32 8, i32 8, i32 8, i32 8>
%51 = icmp eq i64 %48, %18
br i1 %51, label %52, label %23
52: ; preds = %23
%53 = add <4 x i32> %47, %46
%54 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %53)
%55 = icmp eq i64 %18, %15
br i1 %55, label %67, label %56
56: ; preds = %14, %52
%57 = phi i64 [ 0, %14 ], [ %18, %52 ]
%58 = phi i32 [ 0, %14 ], [ %54, %52 ]
br label %70
59: ; preds = %0, %59
%60 = phi i64 [ %63, %59 ], [ 0, %0 ]
%61 = getelementptr inbounds i32, i32* %8, i64 %60
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %61)
%63 = add nuw nsw i64 %60, 1
%64 = load i32, i32* %1
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %63, %65
br i1 %66, label %59, label %12
67: ; preds = %70, %52, %0, %12
%68 = phi i32 [ 0, %12 ], [ 0, %0 ], [ %54, %52 ], [ %81, %70 ]
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %68)
ret i32 0
70: ; preds = %56, %70
%71 = phi i64 [ %77, %70 ], [ %57, %56 ]
%72 = phi i32 [ %81, %70 ], [ %58, %56 ]
%73 = getelementptr inbounds i32, i32* %8, i64 %71
%74 = load i32, i32* %73
%75 = trunc i64 %71 to i32
%76 = sub nsw i32 %64, %75
%77 = add nuw nsw i64 %71, 1
%78 = trunc i64 %77 to i32
%79 = mul i32 %76, %78
%80 = mul i32 %79, %74
%81 = add nsw i32 %80, %72
%82 = icmp eq i64 %77, %15
br i1 %82, label %67, label %70
}