#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 */
char *calloc(int, int);
int strlen(char *);
char *circulate(char *buff) {
  char *returnString = calloc(7, sizeof(char));
  char first = *buff;
  buff++;
  int i, count = 0;
  for (i = 0; i < strlen(buff); i++) {
    *returnString = buff[i];
    returnString++;
    count++;
    if (i == strlen(buff) - 1) {
      *returnString = first;
    }
  }
  returnString -= count;
  return returnString;
}


x86 assembly (clang, -O0):
<circulate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x7,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11df <circulate+0xbf>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11cc <circulate+0xac>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    11d1 <circulate+0xb1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <circulate+0x42>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circulate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    $0x7,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    (%r12),%r15b
add    $0x1,%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    119b <circulate+0x7b>
xor    %ebp,%ebp
jmp    1172 <circulate+0x52>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
mov    %rbx,%rbp
cmp    %rax,%rbx
jge    1196 <circulate+0x76>
movzbl (%r12,%rbp,1),%eax
mov    %al,(%r14,%rbp,1)
lea    0x1(%rbp),%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cmp    %rax,%rbp
jne    1160 <circulate+0x40>
mov    %r15b,0x1(%r14,%rbp,1)
jmp    1160 <circulate+0x40>
add    %rbx,%r14
jmp    119d <circulate+0x7d>
xor    %ebx,%ebx
sub    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @circulate(i8* %0) {
%2 = tail call dereferenceable_or_null(7) i8* @calloc(i32 7, i32 1)
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %1, %19
%8 = phi i64 [ %13, %19 ], [ 0, %1 ]
%9 = phi i8* [ %12, %19 ], [ %2, %1 ]
%10 = getelementptr inbounds i8, i8* %4, i64 %8
%11 = load i8, i8* %10
store i8 %11, i8* %9
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = add nuw nsw i64 %8, 1
%14 = tail call i32 @strlen(i8* %4)
%15 = add nsw i32 %14, -1
%16 = zext i32 %15 to i64
%17 = icmp eq i64 %8, %16
br i1 %17, label %18, label %19
18: ; preds = %7
store i8 %3, i8* %12
br label %19
19: ; preds = %7, %18
%20 = tail call i32 @strlen(i8* %4)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %13, %21
br i1 %22, label %7, label %23
23: ; preds = %19
%24 = and i64 %13, 4294967295
br label %25
25: ; preds = %23, %1
%26 = phi i8* [ %2, %1 ], [ %12, %23 ]
%27 = phi i64 [ 0, %1 ], [ %24, %23 ]
%28 = sub nsw i64 0, %27
%29 = getelementptr inbounds i8, i8* %26, i64 %28
ret i8* %29
}