#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 *generate_zero_vector(int);
double *split_negatives(double *QI, int s) {
  int i = 0;
  double *NQ = generate_zero_vector(s + 1);
  for (i = 1; i <= s; i++) {
    if (QI[i] < 0) {
      NQ[i] = -QI[i];
      QI[i] = 0;
    }
  }
  return NQ;
}


x86 assembly (clang, -O0):
<split_negatives>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <generate_zero_vector@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b2 <split_negatives+0xa2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    119f <split_negatives+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11a4 <split_negatives+0x94>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <split_negatives+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_negatives>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x1(%rbp),%r14d
mov    %r14d,%edi
call   1030 <generate_zero_vector@plt>
test   %ebp,%ebp
jle    1164 <split_negatives+0x54>
mov    %r14d,%edx
add    $0xffffffffffffffff,%rdx
mov    $0x1,%ecx
cmp    $0x2,%r14d
jne    1169 <split_negatives+0x59>
test   $0x1,%dl
je     1164 <split_negatives+0x54>
movsd  (%rbx,%rcx,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1164 <split_negatives+0x54>
xorpd  0xea9(%rip),%xmm0
movlpd %xmm0,(%rax,%rcx,8)
movq   $0x0,(%rbx,%rcx,8)
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
neg    %rsi
mov    $0x1,%ecx
xorpd  %xmm0,%xmm0
movapd 0xe7c(%rip),%xmm1
jmp    11a2 <split_negatives+0x92>
cs nopw 0x0(%rax,%rax,1)
lea    (%rsi,%rcx,1),%rdi
add    $0x2,%rdi
add    $0x2,%rcx
cmp    $0x1,%rdi
je     113b <split_negatives+0x2b>
movsd  (%rbx,%rcx,8),%xmm2
ucomisd %xmm2,%xmm0
jbe    11be <split_negatives+0xae>
xorpd  %xmm1,%xmm2
movlpd %xmm2,(%rax,%rcx,8)
movq   $0x0,(%rbx,%rcx,8)
movsd  0x8(%rbx,%rcx,8),%xmm2
ucomisd %xmm2,%xmm0
jbe    1190 <split_negatives+0x80>
xorpd  %xmm1,%xmm2
movlpd %xmm2,0x8(%rax,%rcx,8)
movq   $0x0,0x8(%rbx,%rcx,8)
jmp    1190 <split_negatives+0x80>

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

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