#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 */
scalar_t__ malloc(int);
int mergeAndCount(long *, long *, int /*<<< orphan*/, int, int, int);
int countRangeSum(int *nums, int numsSize, int lower, int upper) {
  long *sums = (long *)malloc((numsSize + 1) * sizeof(long));
  long *buff = (long *)malloc((numsSize + 1) * sizeof(long));
  sums[0] = 0;
  int cnt = mergeAndCount(sums, buff, 0, numsSize + 1, lower, upper);
  return cnt;
}


x86 assembly (clang, -O0):
<countRangeSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
xor    %edx,%edx
call   1030 <mergeAndCount@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countRangeSum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%r15d
lea    0x1(%rsi),%r12d
lea    0x8(,%rsi,8),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <malloc@plt>
movq   $0x0,(%rbx)
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mergeAndCount@plt>

LLVM IR (-O0):
define i32 @countRangeSum(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i64*
store i64* %18, i64** %9
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i64*
store i64* %25, i64** %10
%26 = load i64*, i64** %9
%27 = getelementptr inbounds i64, i64* %26, i64 0
store i64 0, i64* %27
%28 = load i64*, i64** %9
%29 = load i64*, i64** %10
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call i32 @mergeAndCount(i64* %28, i64* %29, i32 0, i32 %31, i32 %32, i32 %33)
store i32 %34, i32* %11
%35 = load i32, i32* %11
ret i32 %35
}

LLVM IR (-O2):
define i32 @countRangeSum(i32* nocapture readnone %0, i32 %1, i32 %2, i32 %3) {
%5 = add nsw i32 %1, 1
%6 = shl i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i64*
%9 = tail call i64 @malloc(i32 %6)
%10 = inttoptr i64 %9 to i64*
store i64 0, i64* %8
%11 = tail call i32 @mergeAndCount(i64* %8, i64* %10, i32 0, i32 %5, i32 %2, i32 %3)
ret i32 %11
}