#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 right_rotate_array_k_times_v4(int *array, int len, int k) {
  int index, index_k, j, prev, temp;
  int *copy;
  if (!array || (len <= 0) || (k <= 0)) {
    return;
  }
  k = k % len;
  if (!k) {
    return;
  }
  reverse_array_section(array, 0, len - 1);
  reverse_array_section(array, 0, k - 1);
  reverse_array_section(array, k, len - 1);
}


x86 assembly (clang, -O0):
<right_rotate_array_k_times_v4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1141 <right_rotate_array_k_times_v4+0x31>
cmpl   $0x0,-0xc(%rbp)
jle    1141 <right_rotate_array_k_times_v4+0x31>
cmpl   $0x0,-0x10(%rbp)
jg     1146 <right_rotate_array_k_times_v4+0x36>
jmp    1193 <right_rotate_array_k_times_v4+0x83>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    115f <right_rotate_array_k_times_v4+0x4f>
jmp    1193 <right_rotate_array_k_times_v4+0x83>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse_array_section@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse_array_section@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse_array_section@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<right_rotate_array_k_times_v4>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     115d <right_rotate_array_k_times_v4+0x4d>
mov    %esi,%ebx
test   %esi,%esi
jle    115d <right_rotate_array_k_times_v4+0x4d>
test   %edx,%edx
jle    115d <right_rotate_array_k_times_v4+0x4d>
mov    %edx,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
je     115d <right_rotate_array_k_times_v4+0x4d>
mov    %rdi,%r14
mov    %edx,%ebp
add    $0xffffffff,%ebx
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <reverse_array_section@plt>
mov    %ebp,%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <reverse_array_section@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <reverse_array_section@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @right_rotate_array_k_times_v4(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 %18, label %9
9: ; preds = %3
%10 = urem i32 %2, %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = add nsw i32 %1, -1
%14 = tail call i32 @reverse_array_section(i32* %0, i32 0, i32 %13)
%15 = add nsw i32 %10, -1
%16 = tail call i32 @reverse_array_section(i32* %0, i32 0, i32 %15)
%17 = tail call i32 @reverse_array_section(i32* %0, i32 %10, i32 %13)
br label %18
18: ; preds = %9, %3, %12
ret void
}