#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);
long randsubseq(int, int, double, long *);
int /*<<< orphan*/ srand48(int);
char *test_randsubseq() {
  srand48(1234567890);
  long *x = (long *)malloc(1000 * sizeof(long));
  long nsamples = randsubseq(10000, 1000, 0.05, x);
  do {
    if (!(nsamples >= 0))
      return "error, nsamples < 0";
  } while (0);
  do {
    if (!(x[0] >= 0 && x[0] < 10000))
      return "error, x[0] outside";
  } while (0);
  do {
    if (!(x[nsamples - 1] >= 0 && x[nsamples - 1] < 10000))
      return "error, x[end] outside";
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<test_randsubseq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x499602d2,%edi
call   1050 <srand48@plt>
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x2710,%edi
mov    $0x3e8,%esi
movsd  0xe9a(%rip),%xmm0
call   1030 <randsubseq@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    118a <test_randsubseq+0x5a>
lea    0xe87(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    121b <test_randsubseq+0xeb>
jmp    118f <test_randsubseq+0x5f>
jmp    1194 <test_randsubseq+0x64>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jl     11b3 <test_randsubseq+0x83>
mov    -0x10(%rbp),%rax
cmpq   $0x2710,(%rax)
jl     11c3 <test_randsubseq+0x93>
lea    0xe62(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    121b <test_randsubseq+0xeb>
jmp    11c8 <test_randsubseq+0x98>
jmp    11cd <test_randsubseq+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jl     11fe <test_randsubseq+0xce>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmpq   $0x2710,(%rax,%rcx,8)
jl     120e <test_randsubseq+0xde>
lea    0xe2b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    121b <test_randsubseq+0xeb>
jmp    1213 <test_randsubseq+0xe3>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_randsubseq>:
push   %rbx
mov    $0x499602d2,%edi
call   1050 <srand48@plt>
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movsd  0xeb0(%rip),%xmm0
mov    $0x2710,%edi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1030 <randsubseq@plt>
test   %rax,%rax
js     118b <test_randsubseq+0x5b>
cmpq   $0x270f,(%rbx)
ja     1194 <test_randsubseq+0x64>
mov    %rax,%rcx
xor    %eax,%eax
cmpq   $0x2710,-0x8(%rbx,%rcx,8)
lea    0xeab(%rip),%rcx
cmovae %rcx,%rax
pop    %rbx
ret
lea    0xe76(%rip),%rax
pop    %rbx
ret
lea    0xe81(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"error, nsamples < 0\00"
@.str.1 = [20 x i8] c"error, x[0] outside\00"
@.str.2 = [22 x i8] c"error, x[end] outside\00"
define i8* @test_randsubseq() {
%1 = alloca i8*
%2 = alloca i64*
%3 = alloca i64
%4 = call i32 @srand48(i32 1234567890)
%5 = call i64 @malloc(i32 8000)
%6 = inttoptr i64 %5 to i64*
store i64* %6, i64** %2
%7 = load i64*, i64** %2
%8 = call i64 @randsubseq(i32 10000, i32 1000, double 5.000000e-02, i64* %7)
store i64 %8, i64* %3
br label %9
9: ; preds = %0
%10 = load i64, i64* %3
%11 = icmp sge i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %1
br label %45
13: ; preds = %9
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14
%16 = load i64*, i64** %2
%17 = getelementptr inbounds i64, i64* %16, i64 0
%18 = load i64, i64* %17
%19 = icmp sge i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i64*, i64** %2
%22 = getelementptr inbounds i64, i64* %21, i64 0
%23 = load i64, i64* %22
%24 = icmp slt i64 %23, 10000
br i1 %24, label %26, label %25
25: ; preds = %20, %15
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %45
26: ; preds = %20
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
%29 = load i64*, i64** %2
%30 = load i64, i64* %3
%31 = sub nsw i64 %30, 1
%32 = getelementptr inbounds i64, i64* %29, i64 %31
%33 = load i64, i64* %32
%34 = icmp sge i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = load i64*, i64** %2
%37 = load i64, i64* %3
%38 = sub nsw i64 %37, 1
%39 = getelementptr inbounds i64, i64* %36, i64 %38
%40 = load i64, i64* %39
%41 = icmp slt i64 %40, 10000
br i1 %41, label %43, label %42
42: ; preds = %35, %28
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %45
43: ; preds = %35
br label %44
44: ; preds = %43
store i8* null, i8** %1
br label %45
45: ; preds = %44, %42, %25, %12
%46 = load i8*, i8** %1
ret i8* %46
}

LLVM IR (-O2):
@.str = [20 x i8] c"error, nsamples < 0\00"
@.str.1 = [20 x i8] c"error, x[0] outside\00"
@.str.2 = [22 x i8] c"error, x[end] outside\00"
define i8* @test_randsubseq() {
%1 = tail call i32 @srand48(i32 1234567890)
%2 = tail call i64 @malloc(i32 8000)
%3 = inttoptr i64 %2 to i64*
%4 = tail call i64 @randsubseq(i32 10000, i32 1000, double 5.000000e-02, i64* %3)
%5 = icmp sgt i64 %4, -1
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = load i64, i64* %3
%8 = icmp ult i64 %7, 10000
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = add nsw i64 %4, -1
%11 = getelementptr inbounds i64, i64* %3, i64 %10
%12 = load i64, i64* %11
%13 = icmp ult i64 %12, 10000
%14 = select i1 %13, i8* null, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0)
br label %15
15: ; preds = %9, %6, %0
%16 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %6 ], [ %14, %9 ]
ret i8* %16
}