#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(char *, int, int);
int strlen(char *);
void shift(char *seq, int step) {
  int len;
  len = strlen(seq);
  if ((step %= len) == 0)
    return;
  reverse(seq, 0, step - 1);
  reverse(seq, step, len - 1);
  reverse(seq, 0, len - 1);
}


x86 assembly (clang, -O0):
<shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmp    $0x0,%edx
jne    1155 <shift+0x35>
jmp    1189 <shift+0x69>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shift>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1167 <shift+0x47>
mov    %edx,%ebx
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <reverse@plt>
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <reverse@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <reverse@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @shift(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = srem i32 %9, %8
store i32 %10, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
br label %27
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = call i32 @reverse(i8* %14, i32 0, i32 %16)
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = call i32 @reverse(i8* %18, i32 %19, i32 %21)
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = call i32 @reverse(i8* %23, i32 0, i32 %25)
br label %27
27: ; preds = %13, %12
ret void
}

LLVM IR (-O2):
define void @shift(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = srem i32 %1, %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = add nsw i32 %4, -1
%8 = tail call i32 @reverse(i8* %0, i32 0, i32 %7)
%9 = add nsw i32 %3, -1
%10 = tail call i32 @reverse(i8* %0, i32 %4, i32 %9)
%11 = tail call i32 @reverse(i8* %0, i32 0, i32 %9)
br label %12
12: ; preds = %2, %6
ret void
}