#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*/ swap_ints(int *, int *);
void place_negatives_first(int *arr, unsigned int length) {
  int *current_left = arr;
  int *current_right = arr + length - 1;
  while (current_left < current_right) {
    while (current_left < current_right && *current_left < 0)
      current_left++;
    while (current_left<current_right && * current_right> 0)
      current_right--;
    swap_ints(current_left, current_right);
  }
}


x86 assembly (clang, -O0):
<place_negatives_first>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e9 <place_negatives_first+0xd9>
jmp    1150 <place_negatives_first+0x40>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    1170 <place_negatives_first+0x60>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1180 <place_negatives_first+0x70>
jmp    1191 <place_negatives_first+0x81>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1150 <place_negatives_first+0x40>
jmp    1196 <place_negatives_first+0x86>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x22(%rbp)
jae    11b6 <place_negatives_first+0xa6>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
setg   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11c6 <place_negatives_first+0xb6>
jmp    11d7 <place_negatives_first+0xc7>
mov    -0x20(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
jmp    1196 <place_negatives_first+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <swap_ints@plt>
jmp    113d <place_negatives_first+0x2d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<place_negatives_first>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
lea    (%rdi,%rax,4),%rbx
add    $0xfffffffffffffffc,%rbx
cmp    %rdi,%rbx
jbe    1170 <place_negatives_first+0x60>
mov    %rdi,%r14
cmp    %rbx,%r14
jb     1145 <place_negatives_first+0x35>
jmp    1164 <place_negatives_first+0x54>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <swap_ints@plt>
cmp    %rbx,%r14
jae    1170 <place_negatives_first+0x60>
nopl   (%rax)
cmp    %rbx,%r14
jae    1164 <place_negatives_first+0x54>
cmpl   $0x0,(%r14)
jns    1164 <place_negatives_first+0x54>
add    $0x4,%r14
cmp    %rbx,%r14
jb     1145 <place_negatives_first+0x35>
jmp    1164 <place_negatives_first+0x54>
cs nopw 0x0(%rax,%rax,1)
add    $0xfffffffffffffffc,%rbx
cmp    %rbx,%r14
jae    112d <place_negatives_first+0x1d>
cmpl   $0x0,(%rbx)
jg     1160 <place_negatives_first+0x50>
jmp    112d <place_negatives_first+0x1d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @place_negatives_first(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
store i32* %7, i32** %5
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
%12 = getelementptr inbounds i32, i32* %11, i64 -1
store i32* %12, i32** %6
br label %13
13: ; preds = %45, %2
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = icmp ult i32* %14, %15
br i1 %16, label %17, label %49
17: ; preds = %13
br label %18
18: ; preds = %28, %17
%19 = load i32*, i32** %5
%20 = load i32*, i32** %6
%21 = icmp ult i32* %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, 0
br label %26
26: ; preds = %22, %18
%27 = phi i1 [ false, %18 ], [ %25, %22 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32*, i32** %5
%30 = getelementptr inbounds i32, i32* %29, i32 1
store i32* %30, i32** %5
br label %18
31: ; preds = %26
br label %32
32: ; preds = %42, %31
%33 = load i32*, i32** %5
%34 = load i32*, i32** %6
%35 = icmp ult i32* %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = load i32, i32* %37
%39 = icmp sgt i32 %38, 0
br label %40
40: ; preds = %36, %32
%41 = phi i1 [ false, %32 ], [ %39, %36 ]
br i1 %41, label %42, label %45
42: ; preds = %40
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i32 -1
store i32* %44, i32** %6
br label %32
45: ; preds = %40
%46 = load i32*, i32** %5
%47 = load i32*, i32** %6
%48 = call i32 @swap_ints(i32* %46, i32* %47)
br label %13
49: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @place_negatives_first(i32* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = getelementptr inbounds i32, i32* %4, i64 -1
%6 = icmp ugt i32* %5, %0
br i1 %6, label %7, label %32
7: ; preds = %2, %28
%8 = phi i32* [ %29, %28 ], [ %5, %2 ]
%9 = phi i32* [ %19, %28 ], [ %0, %2 ]
%10 = icmp ult i32* %9, %8
br i1 %10, label %11, label %18
11: ; preds = %7, %15
%12 = phi i32* [ %16, %15 ], [ %9, %7 ]
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = getelementptr inbounds i32, i32* %12, i64 1
%17 = icmp ult i32* %16, %8
br i1 %17, label %11, label %18
18: ; preds = %11, %15, %7
%19 = phi i32* [ %9, %7 ], [ %16, %15 ], [ %12, %11 ]
%20 = icmp ult i32* %19, %8
br i1 %20, label %21, label %28
21: ; preds = %18, %25
%22 = phi i32* [ %26, %25 ], [ %8, %18 ]
%23 = load i32, i32* %22
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = getelementptr inbounds i32, i32* %22, i64 -1
%27 = icmp ult i32* %19, %26
br i1 %27, label %21, label %28
28: ; preds = %21, %25, %18
%29 = phi i32* [ %8, %18 ], [ %26, %25 ], [ %22, %21 ]
%30 = tail call i32 @swap_ints(i32* %19, i32* %29)
%31 = icmp ult i32* %19, %29
br i1 %31, label %7, label %32
32: ; preds = %28, %2
ret void
}