#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*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ strcat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strdup(char *);
size_t strlen(char *);
char *rotate(char *s) {
  char *result = malloc(strlen(s));
  strcpy(result, "");
  strcat(result, strdup(s + 1));
  size_t len = strlen(result);
  result[len++] = s[0];
  result[len] = '\0';
  free(s);
  return result;
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1080 <strdup@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0x1(%r14),%rdi
call   1080 <strdup@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    (%r14),%cl
mov    %cl,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @rotate(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i32 @strdup(i8* %12)
%14 = call i32 @strcat(i8* %10, i32 %13)
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %4
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = add i64 %21, 1
store i64 %22, i64* %4
%23 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 %19, i8* %23
%24 = load i8*, i8** %3
%25 = load i64, i64* %4
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @rotate(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i8* @malloc(i64 %2)
%4 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i32 @strdup(i8* %5)
%7 = tail call i32 @strcat(i8* %3, i32 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%9 = load i8, i8* %0
%10 = add i64 %8, 1
%11 = getelementptr inbounds i8, i8* %3, i64 %8
store i8 %9, i8* %11
%12 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 0, i8* %12
%13 = tail call i32 @free(i8* %0)
ret i8* %3
}