#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*/ printf(char *);
int /*<<< orphan*/ reverse(char *, int, int);
int right_shift(char *str, int len, int k) {
  if (!str || len <= 0 || k < 0 || k > len) {
    printf("params are error\n");
    return 1;
  }
  reverse(str, 0, len - k - 1);
  reverse(str, len - k, len - 1);
  reverse(str, 0, len - 1);
  return 0;
}


x86 assembly (clang, -O0):
<right_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115d <right_shift+0x3d>
cmpl   $0x0,-0x14(%rbp)
jle    115d <right_shift+0x3d>
cmpl   $0x0,-0x18(%rbp)
jl     115d <right_shift+0x3d>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1175 <right_shift+0x55>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <right_shift+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<right_shift>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
sub    %edx,%r15d
jl     116f <right_shift+0x4f>
mov    %rdi,%r14
test   %rdi,%rdi
je     116f <right_shift+0x4f>
mov    %esi,%ebx
test   %esi,%esi
jle    116f <right_shift+0x4f>
test   %edx,%edx
js     116f <right_shift+0x4f>
lea    -0x1(%r15),%edx
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <reverse@plt>
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1030 <reverse@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <reverse@plt>
jmp    1180 <right_shift+0x60>
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"params are error\0A\00"
define i32 @right_shift(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = load i32, i32* %6
%12 = icmp sle i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16, %13, %10, %3
%21 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %40
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = call i32 @reverse(i8* %23, i32 0, i32 %27)
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = sub nsw i32 %30, %31
%33 = load i32, i32* %6
%34 = sub nsw i32 %33, 1
%35 = call i32 @reverse(i8* %29, i32 %32, i32 %34)
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, 1
%39 = call i32 @reverse(i8* %36, i32 0, i32 %38)
store i32 0, i32* %4
br label %40
40: ; preds = %22, %20
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@str = [17 x i8] c"params are error\00"
define i32 @right_shift(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp slt i32 %1, 1
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 0
%8 = or i1 %6, %7
%9 = icmp slt i32 %1, %2
%10 = or i1 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %20
13: ; preds = %3
%14 = sub nsw i32 %1, %2
%15 = add nsw i32 %14, -1
%16 = tail call i32 @reverse(i8* %0, i32 0, i32 %15)
%17 = add nsw i32 %1, -1
%18 = tail call i32 @reverse(i8* %0, i32 %14, i32 %17)
%19 = tail call i32 @reverse(i8* %0, i32 0, i32 %17)
br label %20
20: ; preds = %13, %11
%21 = phi i32 [ 1, %11 ], [ 0, %13 ]
ret i32 %21
}