#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 *constructBITree(int *, int);
int getSum(int *, int);
int /*<<< orphan*/ printf(char *, int);
int rangeSum(int, int, int *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ updateBIT(int *, int, int, int);
int main() {
  int n;
  scanf("%d", &n);
  int freq[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &freq[i]);
  }
  int *BITree = constructBITree(freq, n);
  printf("%d\n", getSum(BITree, 5));
  freq[4] += 16;
  updateBIT(BITree, n, 4, 16);
  printf("%d\n", rangeSum(2, 7, BITree));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <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)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e2 <main+0x82>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe31(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ad <main+0x4d>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <constructBITree@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x5,%esi
call   1040 <getSum@plt>
mov    %eax,%esi
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%ecx
add    $0x10,%ecx
mov    %ecx,0x10(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x4,%edx
mov    $0x10,%ecx
call   1070 <updateBIT@plt>
mov    -0x28(%rbp),%rdx
mov    $0x2,%edi
mov    $0x7,%esi
call   1060 <rangeSum@plt>
mov    %eax,%esi
lea    0xdb6(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
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    0xe8b(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1080 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    11cc <main+0x6c>
xor    %r13d,%r13d
lea    0xe56(%rip),%r14
mov    %r15,%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r13
jl     11b0 <main+0x50>
mov    %r15,%rdi
call   1030 <constructBITree@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x5,%esi
call   1040 <getSum@plt>
lea    0xe18(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
addl   $0x10,0x10(%r15)
mov    -0x2c(%rbp),%esi
mov    %r14,%rdi
mov    $0x4,%edx
mov    $0x10,%ecx
call   1070 <updateBIT@plt>
mov    $0x2,%edi
mov    $0x7,%esi
mov    %r14,%rdx
call   1060 <rangeSum@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r12,%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 = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i32, i64 %9
store i64 %9, i64* %4
store i32 0, i32* %5
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %5
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %11, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = load i32, i32* %2
%26 = call i32* @constructBITree(i32* %11, i32 %25)
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = call i32 @getSum(i32* %27, i32 5)
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i32, i32* %11, i64 4
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 16
store i32 %32, i32* %30
%33 = load i32*, i32** %6
%34 = load i32, i32* %2
%35 = call i32 @updateBIT(i32* %33, i32 %34, i32 4, i32 16)
%36 = load i32*, i32** %6
%37 = call i32 @rangeSum(i32 2, i32 7, i32* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
store i32 0, i32* %1
%39 = load i8*, i8** %3
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i32, i64 %5
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %22, %0
%11 = phi i32 [ %8, %0 ], [ %27, %22 ]
%12 = call i32* @constructBITree(i32* %7, i32 %11)
%13 = call i32 @getSum(i32* %12, i32 5)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i32, i32* %7, i64 4
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 16
store i32 %17, i32* %15
%18 = load i32, i32* %1
%19 = call i32 @updateBIT(i32* %12, i32 %18, i32 4, i32 16)
%20 = call i32 @rangeSum(i32 2, i32 7, i32* %12)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
ret i32 0
22: ; preds = %0, %22
%23 = phi i64 [ %26, %22 ], [ 0, %0 ]
%24 = getelementptr inbounds i32, i32* %7, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = add nuw nsw i64 %23, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %22, label %10
}