#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*/ my_strrev_with_bounds(char *const, int, int);
int strlen(char *const);
void str_rotate_right(char *const buf, int k) {
  int n = strlen(buf);
  k = k % n;
  if (k == 0)
    return;
  my_strrev_with_bounds(buf, 0, n - 1);
  my_strrev_with_bounds(buf, 0, k - 1);
  my_strrev_with_bounds(buf, k, n - 1);
}


x86 assembly (clang, -O0):
<str_rotate_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1154 <str_rotate_right+0x34>
jmp    1188 <str_rotate_right+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <my_strrev_with_bounds@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <my_strrev_with_bounds@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1040 <my_strrev_with_bounds@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_rotate_right>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     116e <str_rotate_right+0x4e>
mov    %edx,%r14d
add    $0xffffffff,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <my_strrev_with_bounds@plt>
mov    %r14d,%edx
add    $0xffffffff,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <my_strrev_with_bounds@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <my_strrev_with_bounds@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @str_rotate_right(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* %4
%9 = load i32, i32* %5
%10 = srem i32 %8, %9
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %28
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = call i32 @my_strrev_with_bounds(i8* %15, i32 0, i32 %17)
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = call i32 @my_strrev_with_bounds(i8* %19, i32 0, i32 %21)
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = call i32 @my_strrev_with_bounds(i8* %23, i32 %24, i32 %26)
br label %28
28: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
define void @str_rotate_right(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 %3, -1
%8 = tail call i32 @my_strrev_with_bounds(i8* %0, i32 0, i32 %7)
%9 = add nsw i32 %4, -1
%10 = tail call i32 @my_strrev_with_bounds(i8* %0, i32 0, i32 %9)
%11 = tail call i32 @my_strrev_with_bounds(i8* %0, i32 %4, i32 %7)
br label %12
12: ; preds = %2, %6
ret void
}