#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 strlen(char *);
void rotate(char str[]) {
  int len;
  int k;
  int tmp;
  len = strlen(str);
  tmp = str[0];
  for (k = 0; k < len - 1; k++)
    str[k] = str[k + 1];
  str[len - 1] = tmp;
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1173 <rotate+0x63>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1139 <rotate+0x29>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    (%rbx),%r14b
lea    -0x1(%rax),%ebp
cmp    $0x2,%eax
jl     1145 <rotate+0x25>
lea    0x1(%rbx),%rsi
mov    %ebp,%edx
mov    %rbx,%rdi
call   1040 <memmove@plt>
movslq %ebp,%rax
mov    %r14b,(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @rotate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
store i32 %11, i32* %5
store i32 0, i32* %4
br label %12
12: ; preds = %28, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %31
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %17
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %12
31: ; preds = %12
%32 = load i32, i32* %5
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
ret void
}

LLVM IR (-O2):
define void @rotate(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = add i32 %2, -1
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = getelementptr i8, i8* %0, i64 1
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %6, %1
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %3, i8* %11
ret void
}