#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 */
int /*<<< orphan*/ normalize_vector(double *, int);
double *split_negatives(double *, int);
int split_negative_clusters(double **Q, int n, int s, int k) {
  int i = 0, j = 0, in = k + 1;
  for (i = 1; i <= k; i++) {
    double *QI = Q[i];
    for (j = 1; j <= s; j++) {
      if (QI[j] < 0) {
        Q[in] = split_negatives(QI, s);
        normalize_vector(Q[in], s);
        normalize_vector(QI, s);
        in++;
      }
    }
  }
  return in - 1;
}


x86 assembly (clang, -O0):
<split_negative_clusters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1202 <split_negative_clusters+0xe2>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ef <split_negative_clusters+0xcf>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    11dc <split_negative_clusters+0xbc>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <split_negatives@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%esi
call   1040 <normalize_vector@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <normalize_vector@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e1 <split_negative_clusters+0xc1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <split_negative_clusters+0x56>
jmp    11f4 <split_negative_clusters+0xd4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <split_negative_clusters+0x33>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_negative_clusters>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x1(%rcx),%r12d
test   %ecx,%ecx
jle    11d2 <split_negative_clusters+0xb2>
mov    %edx,%r14d
mov    %rdi,%r15
lea    0x1(%r14),%r13d
mov    %r12d,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%eax
xorpd  %xmm0,%xmm0
jmp    1170 <split_negative_clusters+0x50>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
add    $0x1,%rax
cmp    0x8(%rsp),%rax
je     11d2 <split_negative_clusters+0xb2>
test   %r14d,%r14d
mov    %rax,0x10(%rsp)
jle    1160 <split_negative_clusters+0x40>
mov    (%r15,%rax,8),%rbx
mov    $0x1,%ebp
jmp    1199 <split_negative_clusters+0x79>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    %rbp,%r13
je     1160 <split_negative_clusters+0x40>
ucomisd (%rbx,%rbp,8),%xmm0
jbe    1190 <split_negative_clusters+0x70>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <split_negatives@plt>
movslq %r12d,%r12
mov    %rax,(%r15,%r12,8)
mov    %rax,%rdi
mov    %r14d,%esi
call   1040 <normalize_vector@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <normalize_vector@plt>
xorpd  %xmm0,%xmm0
add    $0x1,%r12d
jmp    1190 <split_negative_clusters+0x70>
add    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_negative_clusters(double** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = load i32, i32* %8
%14 = add nsw i32 %13, 1
store i32 %14, i32* %11
store i32 1, i32* %9
br label %15
15: ; preds = %61, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %64
19: ; preds = %15
%20 = load double**, double*** %5
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
%24 = load double*, double** %23
store double* %24, double** %12
store i32 1, i32* %10
br label %25
25: ; preds = %57, %19
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = icmp sle i32 %26, %27
br i1 %28, label %29, label %60
29: ; preds = %25
%30 = load double*, double** %12
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fcmp olt double %34, 0.000000e+00
br i1 %35, label %36, label %56
36: ; preds = %29
%37 = load double*, double** %12
%38 = load i32, i32* %7
%39 = call double* @split_negatives(double* %37, i32 %38)
%40 = load double**, double*** %5
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double*, double** %40, i64 %42
store double* %39, double** %43
%44 = load double**, double*** %5
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double*, double** %44, i64 %46
%48 = load double*, double** %47
%49 = load i32, i32* %7
%50 = call i32 @normalize_vector(double* %48, i32 %49)
%51 = load double*, double** %12
%52 = load i32, i32* %7
%53 = call i32 @normalize_vector(double* %51, i32 %52)
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %56
56: ; preds = %36, %29
br label %57
57: ; preds = %56
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %25
60: ; preds = %25
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %15
64: ; preds = %15
%65 = load i32, i32* %11
%66 = sub nsw i32 %65, 1
ret i32 %66
}

LLVM IR (-O2):
define i32 @split_negative_clusters(double** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = add i32 %3, 1
%6 = icmp slt i32 %3, 1
br i1 %6, label %38, label %7
7: ; preds = %4
%8 = icmp slt i32 %2, 1
%9 = add i32 %2, 1
%10 = zext i32 %5 to i64
%11 = zext i32 %9 to i64
br label %12
12: ; preds = %7, %34
%13 = phi i64 [ 1, %7 ], [ %36, %34 ]
%14 = phi i32 [ %5, %7 ], [ %35, %34 ]
%15 = getelementptr inbounds double*, double** %0, i64 %13
%16 = load double*, double** %15
br i1 %8, label %34, label %17
17: ; preds = %12, %30
%18 = phi i64 [ %32, %30 ], [ 1, %12 ]
%19 = phi i32 [ %31, %30 ], [ %14, %12 ]
%20 = getelementptr inbounds double, double* %16, i64 %18
%21 = load double, double* %20
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = tail call double* @split_negatives(double* %16, i32 %2)
%25 = sext i32 %19 to i64
%26 = getelementptr inbounds double*, double** %0, i64 %25
store double* %24, double** %26
%27 = tail call i32 @normalize_vector(double* %24, i32 %2)
%28 = tail call i32 @normalize_vector(double* %16, i32 %2)
%29 = add nsw i32 %19, 1
br label %30
30: ; preds = %17, %23
%31 = phi i32 [ %29, %23 ], [ %19, %17 ]
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %34, label %17
34: ; preds = %30, %12
%35 = phi i32 [ %14, %12 ], [ %31, %30 ]
%36 = add nuw nsw i64 %13, 1
%37 = icmp eq i64 %36, %10
br i1 %37, label %38, label %12
38: ; preds = %34, %4
%39 = phi i32 [ %5, %4 ], [ %35, %34 ]
%40 = add nsw i32 %39, -1
ret i32 %40
}