#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 main(int argc, char *argv[]) {
  {
    int nums[] = {-2, 0, 3, -5, 2, -1};
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    struct NumArray *numArray = NumArrayCreate(nums, numsSize);
    printf("%d\n", sumRange(numArray, 0, 2));
    printf("%d\n", sumRange(numArray, 2, 5));
    printf("%d\n", sumRange(numArray, 0, 5));
    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 < 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    0xe80(%rip),%rax
mov    %rax,-0x20(%rbp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movl   $0x6,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1050 <NumArrayCreate@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    %esi,-0x90(%rbp)
mov    $0x2,%edx
mov    %edx,-0x94(%rbp)
call   1030 <sumRange@plt>
mov    %rax,%rsi
lea    0xe3c(%rip),%rdi
mov    %rdi,-0x88(%rbp)
call   1040 <printf@plt>
mov    -0x94(%rbp),%esi
mov    -0x40(%rbp),%rdi
mov    $0x5,%edx
mov    %edx,-0x8c(%rbp)
call   1030 <sumRange@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    -0x90(%rbp),%esi
mov    -0x8c(%rbp),%edx
mov    -0x40(%rbp),%rdi
call   1030 <sumRange@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1080 <NumArrayFree@plt>
movl   $0x2710,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    12a7 <main+0x137>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x1388,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1273 <main+0x103>
mov    -0x80(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1050 <NumArrayCreate@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
cmpl   $0x2710,-0x6c(%rbp)
jge    1353 <main+0x1e3>
mov    $0x0,%al
call   1090 <rand@plt>
cltd
idivl  -0x44(%rbp)
mov    %edx,-0x70(%rbp)
mov    -0x70(%rbp),%eax
add    $0x3e8,%eax
cltd
idivl  -0x44(%rbp)
mov    %edx,-0x74(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x74(%rbp),%eax
jle    1306 <main+0x196>
mov    -0x70(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x70(%rbp),%esi
mov    -0x74(%rbp),%edx
call   1070 <sum@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%esi
mov    -0x74(%rbp),%edx
call   1030 <sumRange@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12be <main+0x14e>
mov    -0x68(%rbp),%rdi
call   1080 <NumArrayFree@plt>
mov    -0x50(%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    $0x9c68,%rsp
mov    0xe88(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x6,%esi
call   1050 <NumArrayCreate@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <sumRange@plt>
lea    0xe5a(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x5,%edx
call   1030 <sumRange@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1030 <sumRange@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1080 <NumArrayFree@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <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,0x20(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1210 <main+0xa0>
lea    0x20(%rsp),%r14
mov    $0x2710,%r13d
mov    %r14,%rdi
mov    $0x2710,%esi
call   1050 <NumArrayCreate@plt>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <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,%ebp
sub    %ecx,%ebp
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,%ebp
mov    %ebp,%ebx
cmovg  %eax,%ebx
cmovle %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1070 <sum@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <sumRange@plt>
xor    %edi,%edi
cmp    %rax,%r12
sete   %dil
call   1060 <assert@plt>
add    $0xffffffff,%r13d
jne    1270 <main+0x100>
mov    %r15,%rdi
call   1080 <NumArrayFree@plt>
xor    %eax,%eax
add    $0x9c68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.NumArray = type { i32 }
@__const.main.nums = [6 x i32] [i32 -2, i32 0, i32 3, i32 -5, i32 2, i32 -1]
@.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 [6 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = bitcast [6 x i32]* %6 to i8*
store i32 6, i32* %7
%19 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call %struct.NumArray* @NumArrayCreate(i32* %19, i32 %20)
store %struct.NumArray* %21, %struct.NumArray** %8
%22 = load %struct.NumArray*, %struct.NumArray** %8
%23 = call i64 @sumRange(%struct.NumArray* %22, i32 0, i32 2)
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = load %struct.NumArray*, %struct.NumArray** %8
%26 = call i64 @sumRange(%struct.NumArray* %25, i32 2, i32 5)
%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 i64 @sumRange(%struct.NumArray* %28, i32 0, i32 5)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %29)
%31 = load %struct.NumArray*, %struct.NumArray** %8
%32 = call i32 @NumArrayFree(%struct.NumArray* %31)
store i32 10000, i32* %9
%33 = load i32, i32* %9
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %10
%36 = alloca i32, i64 %34
store i64 %34, i64* %11
store i32 0, i32* %12
br label %37
37: ; preds = %47, %2
%38 = load i32, i32* %12
%39 = load i32, i32* %9
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = call i32 (...) @rand()
%43 = srem i32 %42, 5000
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %36, i64 %45
store i32 %43, i32* %46
br label %47
47: ; preds = %41
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %37
50: ; preds = %37
%51 = load i32, i32* %9
%52 = call %struct.NumArray* @NumArrayCreate(i32* %36, i32 %51)
store %struct.NumArray* %52, %struct.NumArray** %13
store i32 0, i32* %14
br label %53
53: ; preds = %82, %50
%54 = load i32, i32* %14
%55 = icmp slt i32 %54, 10000
br i1 %55, label %56, label %85
56: ; preds = %53
%57 = call i32 (...) @rand()
%58 = load i32, i32* %9
%59 = srem i32 %57, %58
store i32 %59, i32* %15
%60 = load i32, i32* %15
%61 = add nsw i32 %60, 1000
%62 = load i32, i32* %9
%63 = srem i32 %61, %62
store i32 %63, i32* %16
%64 = load i32, i32* %15
%65 = load i32, i32* %16
%66 = icmp sgt i32 %64, %65
br i1 %66, label %67, label %71
67: ; preds = %56
%68 = load i32, i32* %15
store i32 %68, i32* %17
%69 = load i32, i32* %16
store i32 %69, i32* %15
%70 = load i32, i32* %17
store i32 %70, i32* %16
br label %71
71: ; preds = %67, %56
%72 = load i32, i32* %15
%73 = load i32, i32* %16
%74 = call i64 @sum(i32* %36, i32 %72, i32 %73)
%75 = load %struct.NumArray*, %struct.NumArray** %13
%76 = load i32, i32* %15
%77 = load i32, i32* %16
%78 = call i64 @sumRange(%struct.NumArray* %75, i32 %76, i32 %77)
%79 = icmp eq i64 %74, %78
%80 = zext i1 %79 to i32
%81 = call i32 @assert(i32 %80)
br label %82
82: ; preds = %71
%83 = load i32, i32* %14
%84 = add nsw i32 %83, 1
store i32 %84, i32* %14
br label %53
85: ; preds = %53
%86 = load %struct.NumArray*, %struct.NumArray** %13
%87 = call i32 @NumArrayFree(%struct.NumArray* %86)
%88 = load i8*, i8** %10
ret i32 0
}

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