#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 */
double RAND_MAX;
double rand();
size_t TestingAppend(size_t index, size_t total) {
  if (index > total - total / 5)
    return rand() * 1.0 / RAND_MAX * total;
  return index;
}


x86 assembly (clang, -O0):
<TestingAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    $0x5,%esi
xor    %edx,%edx
div    %rsi
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
sub    %rdx,%rcx
cmp    %rcx,%rax
jbe    11bd <TestingAppend+0xad>
xor    %eax,%eax
call   1030 <rand@plt>
mov    0x2e8d(%rip),%rax
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movaps 0xe96(%rip),%xmm2
movq   -0x18(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe95(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe7b(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <TestingAppend+0xb5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestingAppend>:
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rsi,%rax
mul    %rcx
mov    %rdi,%rax
shr    $0x2,%rdx
mov    %rsi,%rcx
sub    %rdx,%rcx
cmp    %rdi,%rcx
jae    118d <TestingAppend+0x7d>
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
mov    0x2ea4(%rip),%rax
divsd  (%rax),%xmm0
movq   %rbx,%xmm1
punpckldq 0xeab(%rip),%xmm1
subpd  0xeb3(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
cvttsd2si %xmm2,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xe9f(%rip),%xmm2
cvttsd2si %xmm2,%rax
and    %rdx,%rax
or     %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i64 @TestingAppend(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = load i64, i64* %5
%8 = load i64, i64* %5
%9 = udiv i64 %8, 5
%10 = sub i64 %7, %9
%11 = icmp ugt i64 %6, %10
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = call double (...) @rand()
%14 = fmul double %13, 1.000000e+00
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = load i64, i64* %5
%18 = uitofp i64 %17 to double
%19 = fmul double %16, %18
%20 = fptoui double %19 to i64
store i64 %20, i64* %3
br label %23
21: ; preds = %2
%22 = load i64, i64* %4
store i64 %22, i64* %3
br label %23
23: ; preds = %21, %12
%24 = load i64, i64* %3
ret i64 %24
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i64 @TestingAppend(i64 %0, i64 %1) {
%3 = udiv i64 %1, 5
%4 = sub i64 %1, %3
%5 = icmp ult i64 %4, %0
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = tail call double (...) @rand()
%8 = load double, double* @RAND_MAX
%9 = fdiv double %7, %8
%10 = uitofp i64 %1 to double
%11 = fmul double %9, %10
%12 = fptoui double %11 to i64
br label %13
13: ; preds = %2, %6
%14 = phi i64 [ %12, %6 ], [ %0, %2 ]
ret i64 %14
}