#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 */
struct node {
  int dummy;
};

/* Variables and functions */
struct node *getSegmentTree(int *, int);
int getSumQuery(struct node *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ inOrderWalk(struct node *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ updateQuery(struct node *, int, int, int /*<<< orphan*/);
int main() {
  int n;
  printf("Enter the size of input -\n");
  scanf("%d", &n);
  int arr[n + 1], i;
  printf("\nEnter %d Integers -\n", n);
  arr[0] = -1;
  for (i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }
  struct node *SegmentTree = getSegmentTree(arr, n);
  printf("\nIn-Order Walk of the Segment Tree -\n");
  inOrderWalk(SegmentTree);
  int low, high;
  printf("\nEnter the range for sum query - [1, %d]\n", n);
  scanf("%d%d", &low, &high);
  printf("\nSum = %d\n", getSumQuery(SegmentTree, low, high, 0));
  printf("\nEnter the index of number and new value to update -\n");
  scanf("%d%d", &i, &low);
  updateQuery(SegmentTree, i, low, 0);
  printf("\nIn-Order Walk of the Segment Tree after Update -\n");
  inOrderWalk(SegmentTree);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1030 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xef9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1216 <main+0xb6>
mov    -0x38(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11df <main+0x7f>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <getSegmentTree@plt>
mov    %rax,-0x28(%rbp)
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <inOrderWalk@plt>
mov    -0x8(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2c(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
xor    %ecx,%ecx
call   1060 <getSumQuery@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde7(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%edx
xor    %ecx,%ecx
call   1050 <updateQuery@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <inOrderWalk@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
sub    $0x18,%rsp
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r15,%r14
sub    %rbx,%r14
mov    %r14,%rsp
neg    %rbx
mov    -0x2c(%rbp),%esi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0xffffffff,(%r15,%rbx,1)
ff
movl   $0x1,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1223 <main+0xb3>
lea    0x4(%r14),%r13
mov    $0x2,%ebx
lea    0xe48(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    %ebx,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
add    $0x4,%r13
lea    0x1(%rbx),%eax
add    $0xffffffff,%ebx
cmp    %esi,%ebx
mov    %eax,%ebx
jl     1200 <main+0x90>
mov    %r14,%rdi
call   1080 <getSegmentTree@plt>
mov    %rax,%rbx
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <inOrderWalk@plt>
mov    -0x2c(%rbp),%esi
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xde6(%rip),%r15
lea    -0x34(%rbp),%r14
lea    -0x38(%rbp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1070 <getSumQuery@plt>
lea    0xdbf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1060 <updateQuery@plt>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <inOrderWalk@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):
%struct.node = type { i32 }
@.str = [27 x i8] c"Enter the size of input -\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0AEnter %d Integers -\0A\00"
@.str.3 = [38 x i8] c"\0AIn-Order Walk of the Segment Tree -\0A\00"
@.str.4 = [42 x i8] c"\0AEnter the range for sum query - [1, %d]\0A\00"
@.str.5 = [5 x i8] c"%d%d\00"
@.str.6 = [11 x i8] c"\0ASum = %d\0A\00"
@.str.7 = [54 x i8] c"\0AEnter the index of number and new value to update -\0A\00"
@.str.8 = [51 x i8] c"\0AIn-Order Walk of the Segment Tree after Update -\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.node*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i32, i64 %13
store i64 %13, i64* %4
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds i32, i32* %15, i64 0
store i32 -1, i32* %18
store i32 1, i32* %5
br label %19
19: ; preds = %28, %0
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %15, i64 %25
%27 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load i32, i32* %2
%33 = call %struct.node* @getSegmentTree(i32* %15, i32 %32)
store %struct.node* %33, %struct.node** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%35 = load %struct.node*, %struct.node** %6
%36 = call i32 @inOrderWalk(%struct.node* %35)
%37 = load i32, i32* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* %7, i32* %8)
%40 = load %struct.node*, %struct.node** %6
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = call i32 @getSumQuery(%struct.node* %40, i32 %41, i32 %42, i32 0)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* %5, i32* %7)
%47 = load %struct.node*, %struct.node** %6
%48 = load i32, i32* %5
%49 = load i32, i32* %7
%50 = call i32 @updateQuery(%struct.node* %47, i32 %48, i32 %49, i32 0)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0))
%52 = load %struct.node*, %struct.node** %6
%53 = call i32 @inOrderWalk(%struct.node* %52)
store i32 0, i32* %1
%54 = load i8*, i8** %3
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0AEnter %d Integers -\0A\00"
@.str.4 = [42 x i8] c"\0AEnter the range for sum query - [1, %d]\0A\00"
@.str.5 = [5 x i8] c"%d%d\00"
@.str.6 = [11 x i8] c"\0ASum = %d\0A\00"
@str = [26 x i8] c"Enter the size of input -\00"
@str.9 = [37 x i8] c"\0AIn-Order Walk of the Segment Tree -\00"
@str.10 = [53 x i8] c"\0AEnter the index of number and new value to update -\00"
@str.11 = [50 x i8] c"\0AIn-Order Walk of the Segment Tree after Update -\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = bitcast i32* %2 to i8*
%14 = load i32, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 -1, i32* %12
store i32 1, i32* %2
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 1
br i1 %17, label %26, label %18
18: ; preds = %0, %18
%19 = phi i32 [ %23, %18 ], [ 1, %0 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %12, i64 %20
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = add nuw nsw i32 %19, 1
store i32 %23, i32* %2
%24 = load i32, i32* %1
%25 = icmp slt i32 %19, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %0
%27 = phi i32 [ %16, %0 ], [ %24, %18 ]
%28 = call %struct.node* @getSegmentTree(i32* %12, i32 %27)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.9, i64 0, i64 0))
%30 = call i32 @inOrderWalk(%struct.node* %28)
%31 = bitcast i32* %3 to i8*
%32 = bitcast i32* %4 to i8*
%33 = load i32, i32* %1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* %3, i32* %4)
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 @getSumQuery(%struct.node* %28, i32 %36, i32 %37, i32 0)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0))
%41 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* %2, i32* %3)
%42 = load i32, i32* %2
%43 = load i32, i32* %3
%44 = call i32 @updateQuery(%struct.node* %28, i32 %42, i32 %43, i32 0)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.11, i64 0, i64 0))
%46 = call i32 @inOrderWalk(%struct.node* %28)
ret i32 0
}