#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ random();
int rollsum_sum(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ srandom(int);
int /*<<< orphan*/ stderr;
int bupsplit_selftest() {
  uint8_t *buf = malloc(100000);
  uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b;
  unsigned count;
  srandom(1);
  for (count = 0; count < 100000; count++)
    buf[count] = random();
  sum1a = rollsum_sum(buf, 0, 100000);
  sum1b = rollsum_sum(buf, 1, 100000);
  sum2a = rollsum_sum(buf, 100000 - (1 << ((7) - 1)) * 5 / 2,
                      100000 - (1 << ((7) - 1)));
  sum2b = rollsum_sum(buf, 0, 100000 - (1 << ((7) - 1)));
  sum3a = rollsum_sum(buf, 0, (1 << ((7) - 1)) + 3);
  sum3b = rollsum_sum(buf, 3, (1 << ((7) - 1)) + 3);
  fprintf(stderr, "sum1a = 0x%08x\n", sum1a);
  fprintf(stderr, "sum1b = 0x%08x\n", sum1b);
  fprintf(stderr, "sum2a = 0x%08x\n", sum2a);
  fprintf(stderr, "sum2b = 0x%08x\n", sum2b);
  fprintf(stderr, "sum3a = 0x%08x\n", sum3a);
  fprintf(stderr, "sum3b = 0x%08x\n", sum3b);
  free(buf);
  return sum1a != sum1b || sum2a != sum2b || sum3a != sum3b;
}


x86 assembly (clang, -O0):
<bupsplit_selftest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x186a0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x1,%edi
call   1040 <srandom@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x186a0,-0x24(%rbp)
jae    11b5 <bupsplit_selftest+0x55>
mov    $0x0,%al
call   1060 <random@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1187 <bupsplit_selftest+0x27>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x18600,%esi
mov    $0x18660,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x18660,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x43,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
mov    $0x43,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,-0x20(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdbd(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xdb5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdad(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xda5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd9d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd95(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%ecx
mov    $0x1,%al
cmp    -0x10(%rbp),%ecx
mov    %al,-0x25(%rbp)
jne    12f7 <bupsplit_selftest+0x197>
mov    -0x14(%rbp),%ecx
mov    $0x1,%al
cmp    -0x18(%rbp),%ecx
mov    %al,-0x25(%rbp)
jne    12f7 <bupsplit_selftest+0x197>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bupsplit_selftest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x186a0,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1040 <srandom@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <random@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x186a0,%rbp
jne    1190 <bupsplit_selftest+0x30>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,%r15d
mov    %eax,0x14(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x18600,%esi
mov    $0x18660,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18660,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x43,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x43,%edx
call   1080 <rollsum_sum@plt>
mov    %eax,0xc(%rsp)
mov    0x2db7(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdcd(%rip),%rsi
mov    %r15d,%edx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdcb(%rip),%rsi
mov    %r14d,%edx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdc9(%rip),%rsi
mov    %r12d,%edx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdc7(%rip),%rsi
mov    0x10(%rsp),%r15d
mov    %r15d,%edx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdc0(%rip),%rsi
mov    %r13d,%edx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdbe(%rip),%rsi
mov    0xc(%rsp),%ebp
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%eax
xor    %r14d,%eax
xor    %r15d,%r12d
or     %eax,%r12d
xor    %ebp,%r13d
xor    %eax,%eax
or     %r12d,%r13d
setne  %al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"sum1a = 0x%08x\0A\00"
@.str.1 = [16 x i8] c"sum1b = 0x%08x\0A\00"
@.str.2 = [16 x i8] c"sum2a = 0x%08x\0A\00"
@.str.3 = [16 x i8] c"sum2b = 0x%08x\0A\00"
@.str.4 = [16 x i8] c"sum3a = 0x%08x\0A\00"
@.str.5 = [16 x i8] c"sum3b = 0x%08x\0A\00"
define i32 @bupsplit_selftest() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = call i32* @malloc(i32 100000)
store i32* %9, i32** %1
%10 = call i32 @srandom(i32 1)
store i32 0, i32* %8
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %8
%13 = icmp ult i32 %12, 100000
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = call i32 (...) @random()
%16 = load i32*, i32** %1
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %8
%22 = add i32 %21, 1
store i32 %22, i32* %8
br label %11
23: ; preds = %11
%24 = load i32*, i32** %1
%25 = call i32 @rollsum_sum(i32* %24, i32 0, i32 100000)
store i32 %25, i32* %2
%26 = load i32*, i32** %1
%27 = call i32 @rollsum_sum(i32* %26, i32 1, i32 100000)
store i32 %27, i32* %3
%28 = load i32*, i32** %1
%29 = call i32 @rollsum_sum(i32* %28, i32 99840, i32 99936)
store i32 %29, i32* %4
%30 = load i32*, i32** %1
%31 = call i32 @rollsum_sum(i32* %30, i32 0, i32 99936)
store i32 %31, i32* %5
%32 = load i32*, i32** %1
%33 = call i32 @rollsum_sum(i32* %32, i32 0, i32 67)
store i32 %33, i32* %6
%34 = load i32*, i32** %1
%35 = call i32 @rollsum_sum(i32* %34, i32 3, i32 67)
store i32 %35, i32* %7
%36 = load i32, i32* @stderr
%37 = load i32, i32* %2
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @stderr
%40 = load i32, i32* %3
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @stderr
%43 = load i32, i32* %4
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @stderr
%46 = load i32, i32* %5
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @stderr
%49 = load i32, i32* %6
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @stderr
%52 = load i32, i32* %7
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i32*, i32** %1
%55 = call i32 @free(i32* %54)
%56 = load i32, i32* %2
%57 = load i32, i32* %3
%58 = icmp ne i32 %56, %57
br i1 %58, label %67, label %59
59: ; preds = %23
%60 = load i32, i32* %4
%61 = load i32, i32* %5
%62 = icmp ne i32 %60, %61
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i32, i32* %6
%65 = load i32, i32* %7
%66 = icmp ne i32 %64, %65
br label %67
67: ; preds = %63, %59, %23
%68 = phi i1 [ true, %59 ], [ true, %23 ], [ %66, %63 ]
%69 = zext i1 %68 to i32
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"sum1a = 0x%08x\0A\00"
@.str.1 = [16 x i8] c"sum1b = 0x%08x\0A\00"
@.str.2 = [16 x i8] c"sum2a = 0x%08x\0A\00"
@.str.3 = [16 x i8] c"sum2b = 0x%08x\0A\00"
@.str.4 = [16 x i8] c"sum3a = 0x%08x\0A\00"
@.str.5 = [16 x i8] c"sum3b = 0x%08x\0A\00"
define i32 @bupsplit_selftest() {
%1 = tail call i32* @malloc(i32 100000)
%2 = tail call i32 @srandom(i32 1)
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %7, %3 ]
%5 = tail call i32 (...) @random()
%6 = getelementptr inbounds i32, i32* %1, i64 %4
store i32 %5, i32* %6
%7 = add nuw nsw i64 %4, 1
%8 = icmp eq i64 %7, 100000
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i32 @rollsum_sum(i32* %1, i32 0, i32 100000)
%11 = tail call i32 @rollsum_sum(i32* %1, i32 1, i32 100000)
%12 = tail call i32 @rollsum_sum(i32* %1, i32 99840, i32 99936)
%13 = tail call i32 @rollsum_sum(i32* %1, i32 0, i32 99936)
%14 = tail call i32 @rollsum_sum(i32* %1, i32 0, i32 67)
%15 = tail call i32 @rollsum_sum(i32* %1, i32 3, i32 67)
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%28 = tail call i32 @free(i32* %1)
%29 = icmp ne i32 %10, %11
%30 = icmp ne i32 %12, %13
%31 = select i1 %29, i1 true, i1 %30
%32 = icmp ne i32 %14, %15
%33 = select i1 %31, i1 true, i1 %32
%34 = zext i1 %33 to i32
ret i32 %34
}