#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 drand48();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ srand48(long);
long time(int /*<<< orphan*/ *);
int init_subsamples(int *subvec, int n, int ns, double *y) {
  int i;
  int num1 = 0;
  long seed = time(NULL);
  double prop = (double)ns / n;
  int monoclass = 1;
  int ny1 = 0;
  srand48(seed);
  while (monoclass) {
    num1 = 0;
    ny1 = 0;
    for (i = 0; i < n; i++) {
      subvec[i] = (drand48() < prop);
      num1 += subvec[i];
      ny1 += subvec[i] && y[i];
    }
    monoclass = (ny1 == 0 || ny1 == n);
  }
  printf("Class balance (0/1): %d/%d, total=%d\n", num1 - ny1, ny1, num1);
  return num1;
}


x86 assembly (clang, -O0):
<init_subsamples>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x28(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <srand48@plt>
cmpl   $0x0,-0x34(%rbp)
je     1273 <init_subsamples+0x133>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1248 <init_subsamples+0x108>
mov    $0x0,%al
call   1060 <drand48@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
xor    %eax,%eax
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x39(%rbp)
je     122c <init_subsamples+0xec>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setne  %al
setp   %cl
or     %cl,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <init_subsamples+0x73>
mov    $0x1,%al
cmpl   $0x0,-0x38(%rbp)
mov    %al,-0x3a(%rbp)
je     1263 <init_subsamples+0x123>
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
jmp    1194 <init_subsamples+0x54>
mov    -0x20(%rbp),%esi
sub    -0x38(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xd7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_subsamples>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
call   1040 <time@plt>
cvtsi2sd %ebx,%xmm1
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rax,%rdi
call   1050 <srand48@plt>
mov    %r14d,%r13d
mov    %r14d,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x0,%ebx
mov    $0x0,%ebp
test   %r14d,%r14d
jle    1210 <init_subsamples+0xd0>
xor    %r14d,%r14d
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11c1 <init_subsamples+0x81>
nopl   0x0(%rax,%rax,1)
add    %eax,%ebx
movzbl %r15b,%eax
add    %eax,%ebp
add    $0x1,%r14
cmp    %r14,%r13
je     1210 <init_subsamples+0xd0>
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <drand48@plt>
xor    %eax,%eax
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
ucomisd %xmm0,%xmm1
mov    %eax,(%r12,%r14,4)
jbe    11b0 <init_subsamples+0x70>
mov    0x8(%rsp),%rcx
movsd  (%rcx,%r14,8),%xmm0
cmpneqsd 0xe08(%rip),%xmm0
movq   %xmm0,%r15
and    $0x1,%r15d
jmp    11b0 <init_subsamples+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebp,%ebp
mov    0x4(%rsp),%r14d
je     1190 <init_subsamples+0x50>
cmp    %r14d,%ebp
je     1190 <init_subsamples+0x50>
mov    %ebx,%esi
sub    %ebp,%esi
lea    0xdd7(%rip),%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Class balance (0/1): %d/%d, total=%d\0A\00"
define i32 @init_subsamples(i32* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double* %3, double** %8
store i32 0, i32* %10
%15 = call i64 @time(i32* null)
store i64 %15, i64* %11
%16 = load i32, i32* %7
%17 = sitofp i32 %16 to double
%18 = load i32, i32* %6
%19 = sitofp i32 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %12
store i32 1, i32* %13
store i32 0, i32* %14
%21 = load i64, i64* %11
%22 = call i32 @srand48(i64 %21)
br label %23
23: ; preds = %75, %4
%24 = load i32, i32* %13
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %78
26: ; preds = %23
store i32 0, i32* %10
store i32 0, i32* %14
store i32 0, i32* %9
br label %27
27: ; preds = %65, %26
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %68
31: ; preds = %27
%32 = call double (...) @drand48()
%33 = load double, double* %12
%34 = fcmp olt double %32, %33
%35 = zext i1 %34 to i32
%36 = load i32*, i32** %5
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
store i32 %35, i32* %39
%40 = load i32*, i32** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %10
%46 = add nsw i32 %45, %44
store i32 %46, i32* %10
%47 = load i32*, i32** %5
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %31
%54 = load double*, double** %8
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = fcmp une double %58, 0.000000e+00
br label %60
60: ; preds = %53, %31
%61 = phi i1 [ false, %31 ], [ %59, %53 ]
%62 = zext i1 %61 to i32
%63 = load i32, i32* %14
%64 = add nsw i32 %63, %62
store i32 %64, i32* %14
br label %65
65: ; preds = %60
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %27
68: ; preds = %27
%69 = load i32, i32* %14
%70 = icmp eq i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %68
%72 = load i32, i32* %14
%73 = load i32, i32* %6
%74 = icmp eq i32 %72, %73
br label %75
75: ; preds = %71, %68
%76 = phi i1 [ true, %68 ], [ %74, %71 ]
%77 = zext i1 %76 to i32
store i32 %77, i32* %13
br label %23
78: ; preds = %23
%79 = load i32, i32* %10
%80 = load i32, i32* %14
%81 = sub nsw i32 %79, %80
%82 = load i32, i32* %14
%83 = load i32, i32* %10
%84 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %81, i32 %82, i32 %83)
%85 = load i32, i32* %10
ret i32 %85
}

LLVM IR (-O2):
@.str = [38 x i8] c"Class balance (0/1): %d/%d, total=%d\0A\00"
define i32 @init_subsamples(i32* nocapture writeonly %0, i32 %1, i32 %2, double* nocapture %3) {
%5 = tail call i64 @time(i32* null)
%6 = sitofp i32 %2 to double
%7 = sitofp i32 %1 to double
%8 = fdiv double %6, %7
%9 = tail call i32 @srand48(i64 %5)
%10 = icmp sgt i32 %1, 0
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %4, %32
br i1 %10, label %13, label %32
13: ; preds = %12, %26
%14 = phi i64 [ %30, %26 ], [ 0, %12 ]
%15 = phi i32 [ %29, %26 ], [ 0, %12 ]
%16 = phi i32 [ %21, %26 ], [ 0, %12 ]
%17 = tail call double (...) @drand48()
%18 = fcmp olt double %17, %8
%19 = zext i1 %18 to i32
%20 = getelementptr inbounds i32, i32* %0, i64 %14
store i32 %19, i32* %20
%21 = add nuw nsw i32 %16, %19
br i1 %18, label %22, label %26
22: ; preds = %13
%23 = getelementptr inbounds double, double* %3, i64 %14
%24 = load double, double* %23
%25 = fcmp une double %24, 0.000000e+00
br label %26
26: ; preds = %22, %13
%27 = phi i1 [ false, %13 ], [ %25, %22 ]
%28 = zext i1 %27 to i32
%29 = add nuw nsw i32 %15, %28
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %32, label %13
32: ; preds = %26, %12
%33 = phi i32 [ 0, %12 ], [ %21, %26 ]
%34 = phi i32 [ 0, %12 ], [ %29, %26 ]
%35 = icmp ne i32 %34, 0
%36 = icmp ne i32 %34, %1
%37 = and i1 %35, %36
br i1 %37, label %38, label %12
38: ; preds = %32
%39 = sub nsw i32 %33, %34
%40 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %34, i32 %33)
ret i32 %33
}