#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*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ array_reverse_s32(int /*<<< orphan*/ *, unsigned int,
                                     unsigned int, unsigned int);
void array_shift_s32(int32_t *a, unsigned len, unsigned m) {
  m = 0 == m ? 0 : m % len;
  if (0 == m) {
    goto out;
  }
  array_reverse_s32(a, len, 0, len - 1);
  array_reverse_s32(a, len, 0, m - 1);
  array_reverse_s32(a, len, m, len - 1);
out:
  return;
}


x86 assembly (clang, -O0):
<array_shift_s32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
jne    1137 <array_shift_s32+0x27>
xor    %edx,%edx
mov    %edx,-0x14(%rbp)
jmp    1142 <array_shift_s32+0x32>
mov    -0x10(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
jne    1158 <array_shift_s32+0x48>
jmp    1195 <array_shift_s32+0x85>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1030 <array_reverse_s32@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
call   1030 <array_reverse_s32@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <array_reverse_s32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_shift_s32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     1166 <array_shift_s32+0x56>
mov    %esi,%ebx
mov    %edx,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     1166 <array_shift_s32+0x56>
mov    %rdi,%r14
mov    %edx,%ebp
lea    -0x1(%rbx),%r15d
mov    %ebx,%esi
xor    %edx,%edx
mov    %r15d,%ecx
call   1030 <array_reverse_s32@plt>
mov    %ebp,%ecx
add    $0xffffffff,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <array_reverse_s32@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <array_reverse_s32@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @array_shift_s32(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp eq i32 0, %7
br i1 %8, label %9, label %10
9: ; preds = %3
br label %14
10: ; preds = %3
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = urem i32 %11, %12
br label %14
14: ; preds = %10, %9
%15 = phi i32 [ 0, %9 ], [ %13, %10 ]
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 0, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %36
19: ; preds = %14
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = sub i32 %22, 1
%24 = call i32 @array_reverse_s32(i32* %20, i32 %21, i32 0, i32 %23)
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = sub i32 %27, 1
%29 = call i32 @array_reverse_s32(i32* %25, i32 %26, i32 0, i32 %28)
%30 = load i32*, i32** %4
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub i32 %33, 1
%35 = call i32 @array_reverse_s32(i32* %30, i32 %31, i32 %32, i32 %34)
br label %36
36: ; preds = %19, %18
ret void
}

LLVM IR (-O2):
define void @array_shift_s32(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = urem i32 %2, %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = add i32 %1, -1
%10 = tail call i32 @array_reverse_s32(i32* %0, i32 %1, i32 0, i32 %9)
%11 = add i32 %6, -1
%12 = tail call i32 @array_reverse_s32(i32* %0, i32 %1, i32 0, i32 %11)
%13 = tail call i32 @array_reverse_s32(i32* %0, i32 %1, i32 %6, i32 %9)
br label %14
14: ; preds = %3, %5, %8
ret void
}