#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 */
typedef int /*<<< orphan*/ to_index;
typedef size_t ssize_t;
typedef int /*<<< orphan*/ from_index;

/* Variables and functions */
int /*<<< orphan*/ array_copy_at(size_t, size_t, void *, void *, size_t *,
                                 size_t *);
scalar_t__ inc_index(int, size_t, size_t const *, size_t *, int);
int /*<<< orphan*/ memcpy(size_t *, size_t *, int);
int /*<<< orphan*/ memset(size_t *, int /*<<< orphan*/, int);
void array_roll_axis_to(size_t dim, const size_t *size, size_t v_size,
                        void *from, void *to, ssize_t shift, size_t axis) {
  size_t from_index[dim], to_index[dim];
  memset(from_index, 0, sizeof(from_index));
  do {
    memcpy(to_index, from_index, sizeof(to_index));
    to_index[axis] = (from_index[axis] + size[axis] + shift) % size[axis];
    array_copy_at(dim, v_size, from, to, from_index, to_index);
  } while (inc_index(1, dim, size, from_index, -1) == 0);
}


x86 assembly (clang, -O0):
<array_roll_axis_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rcx
mov    %rcx,-0x58(%rbp)
lea    0xf(,%rcx,8),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x48(%rbp)
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x60(%rbp),%r8
mov    -0x50(%rbp),%r9
mov    0x10(%rbp),%rax
mov    (%r8,%rax,8),%rax
mov    -0x10(%rbp),%rcx
mov    0x10(%rbp),%rdx
add    (%rcx,%rdx,8),%rax
add    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x10(%rbp),%rsi
xor    %edx,%edx
divq   (%rcx,%rsi,8)
mov    0x10(%rbp),%rax
mov    %rdx,(%r9,%rax,8)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <array_copy_at@plt>
mov    -0x60(%rbp),%rcx
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
mov    $0xffffffff,%r8d
call   1060 <inc_index@plt>
cmp    $0x0,%rax
je     11be <array_roll_axis_to+0x7e>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_roll_axis_to>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,-0x50(%rbp)
mov    %r8,-0x48(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x10(%rbp),%r13
mov    %rsp,%r15
lea    0xf(,%rdi,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
lea    0x0(,%rdi,8),%edx
mov    %r15,%rdi
xor    %esi,%esi
mov    %edx,-0x2c(%rbp)
call   1030 <memset@plt>
jmp    11e1 <array_roll_axis_to+0xa1>
nop
xor    %edx,%edx
div    %rcx
mov    %rdx,(%r12,%r13,8)
mov    %r14,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %r15,%r8
mov    %r12,%r9
call   1040 <array_copy_at@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    $0xffffffff,%r8d
call   1060 <inc_index@plt>
test   %rax,%rax
jne    1210 <array_roll_axis_to+0xd0>
mov    %r12,%rdi
mov    %r15,%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcpy@plt>
mov    (%rbx,%r13,8),%rcx
mov    (%r15,%r13,8),%rax
add    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
jne    11a0 <array_roll_axis_to+0x60>
xor    %edx,%edx
div    %ecx
jmp    11a5 <array_roll_axis_to+0x65>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @array_roll_axis_to(i64 %0, i64* %1, i64 %2, i8* %3, i8* %4, i64 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
store i64 %0, i64* %8
store i64* %1, i64** %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i64 %5, i64* %13
store i64 %6, i64* %14
%18 = load i64, i64* %8
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %15
%20 = alloca i64, i64 %18
store i64 %18, i64* %16
%21 = load i64, i64* %8
%22 = alloca i64, i64 %21
store i64 %21, i64* %17
%23 = mul nuw i64 8, %18
%24 = trunc i64 %23 to i32
%25 = call i32 @memset(i64* %20, i32 0, i32 %24)
br label %26
26: ; preds = %52, %7
%27 = mul nuw i64 8, %21
%28 = trunc i64 %27 to i32
%29 = call i32 @memcpy(i64* %22, i64* %20, i32 %28)
%30 = load i64, i64* %14
%31 = getelementptr inbounds i64, i64* %20, i64 %30
%32 = load i64, i64* %31
%33 = load i64*, i64** %9
%34 = load i64, i64* %14
%35 = getelementptr inbounds i64, i64* %33, i64 %34
%36 = load i64, i64* %35
%37 = add i64 %32, %36
%38 = load i64, i64* %13
%39 = add i64 %37, %38
%40 = load i64*, i64** %9
%41 = load i64, i64* %14
%42 = getelementptr inbounds i64, i64* %40, i64 %41
%43 = load i64, i64* %42
%44 = urem i64 %39, %43
%45 = load i64, i64* %14
%46 = getelementptr inbounds i64, i64* %22, i64 %45
store i64 %44, i64* %46
%47 = load i64, i64* %8
%48 = load i64, i64* %10
%49 = load i8*, i8** %11
%50 = load i8*, i8** %12
%51 = call i32 @array_copy_at(i64 %47, i64 %48, i8* %49, i8* %50, i64* %20, i64* %22)
br label %52
52: ; preds = %26
%53 = load i64, i64* %8
%54 = load i64*, i64** %9
%55 = call i64 @inc_index(i32 1, i64 %53, i64* %54, i64* %20, i32 -1)
%56 = icmp eq i64 %55, 0
br i1 %56, label %26, label %57
57: ; preds = %52
%58 = load i8*, i8** %15
ret void
}

LLVM IR (-O2):
define void @array_roll_axis_to(i64 %0, i64* %1, i64 %2, i8* %3, i8* %4, i64 %5, i64 %6) {
%8 = alloca i64, i64 %0
%9 = alloca i64, i64 %0
%10 = trunc i64 %0 to i32
%11 = shl i32 %10, 3
%12 = call i32 @memset(i64* %8, i32 0, i32 %11)
%13 = getelementptr inbounds i64, i64* %8, i64 %6
%14 = getelementptr inbounds i64, i64* %1, i64 %6
%15 = getelementptr inbounds i64, i64* %9, i64 %6
br label %16
16: ; preds = %16, %7
%17 = call i32 @memcpy(i64* %9, i64* %8, i32 %11)
%18 = load i64, i64* %13
%19 = load i64, i64* %14
%20 = add i64 %18, %5
%21 = add i64 %20, %19
%22 = urem i64 %21, %19
store i64 %22, i64* %15
%23 = call i32 @array_copy_at(i64 %0, i64 %2, i8* %3, i8* %4, i64* %8, i64* %9)
%24 = call i64 @inc_index(i32 1, i64 %0, i64* %1, i64* %8, i32 -1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %16, label %26
26: ; preds = %16
ret void
}