#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*/ reverse_array_section(int *, int, int);
void reverse_array_in_groups_of_k(int *array, int len, int k) {
  int index, low, high;
  if (!array || (len <= 0) || (k <= 0)) {
    return;
  }
  index = 0;
  while (index < len) {
    low = index;
    high = ((low + k - 1) >= len) ? (len - 1) : (low + k - 1);
    reverse_array_section(array, low, high);
    index += k;
  }
}


x86 assembly (clang, -O0):
<reverse_array_in_groups_of_k>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1141 <reverse_array_in_groups_of_k+0x31>
cmpl   $0x0,-0xc(%rbp)
jle    1141 <reverse_array_in_groups_of_k+0x31>
cmpl   $0x0,-0x10(%rbp)
jg     1146 <reverse_array_in_groups_of_k+0x36>
jmp    11ae <reverse_array_in_groups_of_k+0x9e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ae <reverse_array_in_groups_of_k+0x9e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    -0xc(%rbp),%eax
jl     117f <reverse_array_in_groups_of_k+0x6f>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118b <reverse_array_in_groups_of_k+0x7b>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <reverse_array_section@plt>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    114d <reverse_array_in_groups_of_k+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_array_in_groups_of_k>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     114c <reverse_array_in_groups_of_k+0x3c>
mov    %esi,%ebp
test   %esi,%esi
jle    114c <reverse_array_in_groups_of_k+0x3c>
mov    %edx,%r14d
test   %edx,%edx
jle    114c <reverse_array_in_groups_of_k+0x3c>
mov    %rdi,%r15
xor    %esi,%esi
xchg   %ax,%ax
lea    (%rsi,%r14,1),%ebx
cmp    %ebp,%ebx
mov    %ebx,%edx
cmovg  %ebp,%edx
add    $0xffffffff,%edx
mov    %r15,%rdi
call   1030 <reverse_array_section@plt>
mov    %ebx,%esi
cmp    %ebp,%ebx
jl     1130 <reverse_array_in_groups_of_k+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @reverse_array_in_groups_of_k(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp slt i32 %1, 1
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 1
%8 = or i1 %6, %7
br i1 %8, label %17, label %9
9: ; preds = %3, %9
%10 = phi i32 [ %11, %9 ], [ 0, %3 ]
%11 = add nsw i32 %10, %2
%12 = icmp sgt i32 %11, %1
%13 = select i1 %12, i32 %1, i32 %11
%14 = add nsw i32 %13, -1
%15 = tail call i32 @reverse_array_section(i32* %0, i32 %10, i32 %14)
%16 = icmp slt i32 %11, %1
br i1 %16, label %9, label %17
17: ; preds = %9, %3
ret void
}