#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 NumArray {
  int dummy;
};
typedef int /*<<< orphan*/ nums;

/* Variables and functions */
struct NumArray *NumArrayCreate(int *, int);
int /*<<< orphan*/ NumArrayFree(struct NumArray *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, scalar_t__);
int rand();
scalar_t__ sum(int *, int, int);
scalar_t__ sumRange(struct NumArray *, int, int);
int /*<<< orphan*/ update(struct NumArray *, int, int);
int main(int argc, char *argv[]) {
  {
    int nums[] = {1, 3, 5};
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    struct NumArray *numArray = NumArrayCreate(nums, numsSize);
    printf("%d\n", sumRange(numArray, 0, 2));
    update(numArray, 1, 2);
    printf("%d\n", sumRange(numArray, 0, 2));
    NumArrayFree(numArray);
  }
  {
    int numsSize = 10000;
    int nums[numsSize];
    for (int i = 0; i < numsSize; i++)
      nums[i] = rand() % 5000;
    struct NumArray *numArray = NumArrayCreate(nums, numsSize);
    for (int i = 0; i < 100; i++) {
      int d = rand() % numsSize;
      int v = rand() % 5000;
      update(numArray, d, v);
      nums[d] = v;
    }
    for (int i = 0; i < 10000; i++) {
      int l = rand() % numsSize, r = (l + 1000) % numsSize;
      if (l > r) {
        int t = l;
        l = r;
        r = t;
      }
      assert(sum(nums, l, r) == sumRange(numArray, l, r));
    }
    NumArrayFree(numArray);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe69(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe57(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x3,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1060 <NumArrayCreate@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    %esi,-0x90(%rbp)
mov    $0x2,%edx
mov    %edx,-0x8c(%rbp)
call   1040 <sumRange@plt>
mov    %rax,%rsi
lea    0xe22(%rip),%rdi
mov    %rdi,-0x88(%rbp)
call   1050 <printf@plt>
mov    -0x8c(%rbp),%edx
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1030 <update@plt>
mov    -0x90(%rbp),%esi
mov    -0x8c(%rbp),%edx
mov    -0x30(%rbp),%rdi
call   1040 <sumRange@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <NumArrayFree@plt>
movl   $0x2710,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12a0 <main+0x120>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x1388,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    126c <main+0xec>
mov    -0x80(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <NumArrayCreate@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x64,-0x5c(%rbp)
jge    130c <main+0x18c>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x34(%rbp)
mov    %edx,-0x60(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x1388,%ecx
cltd
idiv   %ecx
mov    %edx,-0x64(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    -0x64(%rbp),%edx
call   1030 <update@plt>
mov    -0x80(%rbp),%rax
mov    -0x64(%rbp),%edx
movslq -0x60(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12b7 <main+0x137>
movl   $0x0,-0x68(%rbp)
cmpl   $0x2710,-0x68(%rbp)
jge    13a8 <main+0x228>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x34(%rbp)
mov    %edx,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x3e8,%eax
cltd
idivl  -0x34(%rbp)
mov    %edx,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x70(%rbp),%eax
jle    135b <main+0x1db>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x70(%rbp),%edx
call   1080 <sum@plt>
mov    %rax,-0x98(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x70(%rbp),%edx
call   1040 <sumRange@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1313 <main+0x193>
mov    -0x58(%rbp),%rdi
call   1090 <NumArrayFree@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c58,%rsp
mov    0xe71(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xe5e(%rip),%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    $0x3,%esi
call   1060 <NumArrayCreate@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <sumRange@plt>
lea    0xe40(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <update@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <sumRange@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <NumArrayFree@plt>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2b,%rcx
add    %edx,%ecx
imul   $0x1388,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1210 <main+0x90>
lea    0x10(%rsp),%rdi
mov    $0x2710,%esi
call   1060 <NumArrayCreate@plt>
mov    %rax,%r15
mov    $0x64,%ebp
nopl   (%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%r14
imul   $0x68db8bad,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
imul   $0x2710,%eax,%eax
sub    %eax,%r14d
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%rbx
imul   $0x68db8bad,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2b,%rax
add    %ecx,%eax
imul   $0x1388,%eax,%eax
sub    %eax,%ebx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <update@plt>
movslq %r14d,%rax
mov    %ebx,0x10(%rsp,%rax,4)
add    $0xffffffff,%ebp
jne    1260 <main+0xe0>
mov    $0x2710,%r13d
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
mov    %eax,%ebx
sub    %ecx,%ebx
neg    %ecx
add    %ecx,%eax
add    $0x3e8,%eax
movswl %ax,%ecx
imul   $0x1a37,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x1a,%ecx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
cwtl
cmp    %eax,%ebx
mov    %ebx,%ebp
cmovg  %eax,%ebp
cmovle %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1080 <sum@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <sumRange@plt>
xor    %edi,%edi
cmp    %rax,%r12
sete   %dil
call   1070 <assert@plt>
add    $0xffffffff,%r13d
jne    12e0 <main+0x160>
mov    %r15,%rdi
call   1090 <NumArrayFree@plt>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.NumArray = type { i32 }
@__const.main.nums = [3 x i32] [i32 1, i32 3, i32 5]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i32]
%7 = alloca i32
%8 = alloca %struct.NumArray*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca %struct.NumArray*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = bitcast [3 x i32]* %6 to i8*
store i32 3, i32* %7
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call %struct.NumArray* @NumArrayCreate(i32* %22, i32 %23)
store %struct.NumArray* %24, %struct.NumArray** %8
%25 = load %struct.NumArray*, %struct.NumArray** %8
%26 = call i64 @sumRange(%struct.NumArray* %25, i32 0, i32 2)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = load %struct.NumArray*, %struct.NumArray** %8
%29 = call i32 @update(%struct.NumArray* %28, i32 1, i32 2)
%30 = load %struct.NumArray*, %struct.NumArray** %8
%31 = call i64 @sumRange(%struct.NumArray* %30, i32 0, i32 2)
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %31)
%33 = load %struct.NumArray*, %struct.NumArray** %8
%34 = call i32 @NumArrayFree(%struct.NumArray* %33)
store i32 10000, i32* %9
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
store i8* %37, i8** %10
%38 = alloca i32, i64 %36
store i64 %36, i64* %11
store i32 0, i32* %12
br label %39
39: ; preds = %49, %2
%40 = load i32, i32* %12
%41 = load i32, i32* %9
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = call i32 (...) @rand()
%45 = srem i32 %44, 5000
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %38, i64 %47
store i32 %45, i32* %48
br label %49
49: ; preds = %43
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %39
52: ; preds = %39
%53 = load i32, i32* %9
%54 = call %struct.NumArray* @NumArrayCreate(i32* %38, i32 %53)
store %struct.NumArray* %54, %struct.NumArray** %13
store i32 0, i32* %14
br label %55
55: ; preds = %72, %52
%56 = load i32, i32* %14
%57 = icmp slt i32 %56, 100
br i1 %57, label %58, label %75
58: ; preds = %55
%59 = call i32 (...) @rand()
%60 = load i32, i32* %9
%61 = srem i32 %59, %60
store i32 %61, i32* %15
%62 = call i32 (...) @rand()
%63 = srem i32 %62, 5000
store i32 %63, i32* %16
%64 = load %struct.NumArray*, %struct.NumArray** %13
%65 = load i32, i32* %15
%66 = load i32, i32* %16
%67 = call i32 @update(%struct.NumArray* %64, i32 %65, i32 %66)
%68 = load i32, i32* %16
%69 = load i32, i32* %15
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %38, i64 %70
store i32 %68, i32* %71
br label %72
72: ; preds = %58
%73 = load i32, i32* %14
%74 = add nsw i32 %73, 1
store i32 %74, i32* %14
br label %55
75: ; preds = %55
store i32 0, i32* %17
br label %76
76: ; preds = %105, %75
%77 = load i32, i32* %17
%78 = icmp slt i32 %77, 10000
br i1 %78, label %79, label %108
79: ; preds = %76
%80 = call i32 (...) @rand()
%81 = load i32, i32* %9
%82 = srem i32 %80, %81
store i32 %82, i32* %18
%83 = load i32, i32* %18
%84 = add nsw i32 %83, 1000
%85 = load i32, i32* %9
%86 = srem i32 %84, %85
store i32 %86, i32* %19
%87 = load i32, i32* %18
%88 = load i32, i32* %19
%89 = icmp sgt i32 %87, %88
br i1 %89, label %90, label %94
90: ; preds = %79
%91 = load i32, i32* %18
store i32 %91, i32* %20
%92 = load i32, i32* %19
store i32 %92, i32* %18
%93 = load i32, i32* %20
store i32 %93, i32* %19
br label %94
94: ; preds = %90, %79
%95 = load i32, i32* %18
%96 = load i32, i32* %19
%97 = call i64 @sum(i32* %38, i32 %95, i32 %96)
%98 = load %struct.NumArray*, %struct.NumArray** %13
%99 = load i32, i32* %18
%100 = load i32, i32* %19
%101 = call i64 @sumRange(%struct.NumArray* %98, i32 %99, i32 %100)
%102 = icmp eq i64 %97, %101
%103 = zext i1 %102 to i32
%104 = call i32 @assert(i32 %103)
br label %105
105: ; preds = %94
%106 = load i32, i32* %17
%107 = add nsw i32 %106, 1
store i32 %107, i32* %17
br label %76
108: ; preds = %76
%109 = load %struct.NumArray*, %struct.NumArray** %13
%110 = call i32 @NumArrayFree(%struct.NumArray* %109)
%111 = load i8*, i8** %10
ret i32 0
}

LLVM IR (-O2):
%struct.NumArray = type { i32 }
@__const.main.nums = [3 x i32] [i32 1, i32 3, i32 5]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %3 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%6 = call %struct.NumArray* @NumArrayCreate(i32* %5, i32 3)
%7 = call i64 @sumRange(%struct.NumArray* %6, i32 0, i32 2)
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = call i32 @update(%struct.NumArray* %6, i32 1, i32 2)
%10 = call i64 @sumRange(%struct.NumArray* %6, i32 0, i32 2)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = call i32 @NumArrayFree(%struct.NumArray* %6)
%13 = alloca [10000 x i32]
br label %17
14: ; preds = %17
%15 = getelementptr inbounds [10000 x i32], [10000 x i32]* %13, i64 0, i64 0
%16 = call %struct.NumArray* @NumArrayCreate(i32* %15, i32 10000)
br label %24
17: ; preds = %2, %17
%18 = phi i64 [ 0, %2 ], [ %22, %17 ]
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 5000
%21 = getelementptr inbounds [10000 x i32], [10000 x i32]* %13, i64 0, i64 %18
store i32 %20, i32* %21
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, 10000
br i1 %23, label %14, label %17
24: ; preds = %14, %24
%25 = phi i32 [ 0, %14 ], [ %33, %24 ]
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10000
%28 = call i32 (...) @rand()
%29 = srem i32 %28, 5000
%30 = call i32 @update(%struct.NumArray* %16, i32 %27, i32 %29)
%31 = sext i32 %27 to i64
%32 = getelementptr inbounds [10000 x i32], [10000 x i32]* %13, i64 0, i64 %31
store i32 %29, i32* %32
%33 = add nuw nsw i32 %25, 1
%34 = icmp eq i32 %33, 100
br i1 %34, label %37, label %24
35: ; preds = %37
%36 = call i32 @NumArrayFree(%struct.NumArray* %16)
ret i32 0
37: ; preds = %24, %37
%38 = phi i32 [ %53, %37 ], [ 0, %24 ]
%39 = call i32 (...) @rand()
%40 = srem i32 %39, 10000
%41 = trunc i32 %40 to i16
%42 = add nsw i16 %41, 1000
%43 = srem i16 %42, 10000
%44 = sext i16 %43 to i32
%45 = icmp sgt i32 %40, %44
%46 = select i1 %45, i32 %44, i32 %40
%47 = select i1 %45, i32 %40, i32 %44
%48 = call i64 @sum(i32* %15, i32 %46, i32 %47)
%49 = call i64 @sumRange(%struct.NumArray* %16, i32 %46, i32 %47)
%50 = icmp eq i64 %48, %49
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = add nuw nsw i32 %38, 1
%54 = icmp eq i32 %53, 10000
br i1 %54, label %35, label %37
}