#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 *s, int n) {
  char c;
  int i, j;
  int len = strlen(s);
  for (j = 0; j < n; j++) {
    c = s[0];
    for (i = 1; i < len; i++)
      s[i - 1] = s[i];
    s[i - 1] = c;
  }
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <rotate+0x94>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1183 <rotate+0x73>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <rotate+0x3e>
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <rotate+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %ebx,%ebx
jle    124e <rotate+0x12e>
mov    %eax,%ebp
lea    0x1(%r14),%rax
mov    %rax,0x18(%rsp)
lea    -0x1(%rbp),%eax
mov    %rax,0x10(%rsp)
lea    -0x2(%rbp),%eax
add    $0x2,%rax
mov    %rax,0x20(%rsp)
mov    %ebx,0xc(%rsp)
cmp    $0x1,%ebx
jne    11a0 <rotate+0x80>
testb  $0x1,0xc(%rsp)
je     124e <rotate+0x12e>
mov    (%r14),%bl
cmp    $0x2,%ebp
jl     1248 <rotate+0x128>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1040 <memmove@plt>
mov    0x20(%rsp),%rax
add    $0xffffffff,%eax
cltq
jmp    124a <rotate+0x12a>
movabs $0xffffffff00000000,%rcx
ff ff ff
mov    0xc(%rsp),%r15d
and    $0xfffffffe,%r15d
jmp    11d5 <rotate+0xb5>
cs nopw 0x0(%rax,%rax,1)
nop
shl    $0x20,%r13
add    %rcx,%r13
sar    $0x20,%r13
mov    %bl,(%r14,%r13,1)
add    $0xfffffffe,%r15d
je     1168 <rotate+0x48>
movzbl (%r14),%r12d
mov    $0x1,%r13d
mov    $0x1,%eax
cmp    $0x2,%ebp
jl     120a <rotate+0xea>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1040 <memmove@plt>
movabs $0xffffffff00000000,%rcx
ff ff ff
mov    0x20(%rsp),%rax
shl    $0x20,%rax
add    %rcx,%rax
sar    $0x20,%rax
mov    %r12b,(%r14,%rax,1)
movzbl (%r14),%ebx
cmp    $0x2,%ebp
jl     11c0 <rotate+0xa0>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1040 <memmove@plt>
movabs $0xffffffff00000000,%rcx
ff ff ff
mov    0x20(%rsp),%r13
jmp    11c0 <rotate+0xa0>
xor    %eax,%eax
mov    %bl,(%r14,%rax,1)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @rotate(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %48
5: ; preds = %2
%6 = icmp sgt i32 %3, 1
%7 = getelementptr i8, i8* %0, i64 1
%8 = add i32 %3, -1
%9 = zext i32 %8 to i64
%10 = add i32 %3, -2
%11 = zext i32 %10 to i64
%12 = add nuw nsw i64 %11, 2
%13 = and i32 %1, 1
%14 = icmp eq i32 %1, 1
br i1 %14, label %37, label %15
15: ; preds = %5
%16 = and i32 %1, -2
br label %17
17: ; preds = %29, %15
%18 = phi i32 [ 0, %15 ], [ %35, %29 ]
%19 = load i8, i8* %0
br i1 %6, label %20, label %21
20: ; preds = %17
br label %21
21: ; preds = %20, %17
%22 = phi i64 [ 1, %17 ], [ %12, %20 ]
%23 = shl i64 %22, 32
%24 = add i64 %23, -4294967296
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %19, i8* %26
%27 = load i8, i8* %0
br i1 %6, label %28, label %29
28: ; preds = %21
br label %29
29: ; preds = %28, %21
%30 = phi i64 [ 1, %21 ], [ %12, %28 ]
%31 = shl i64 %30, 32
%32 = add i64 %31, -4294967296
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 %27, i8* %34
%35 = add i32 %18, 2
%36 = icmp eq i32 %35, %16
br i1 %36, label %37, label %17
37: ; preds = %29, %5
%38 = icmp eq i32 %13, 0
br i1 %38, label %48, label %39
39: ; preds = %37
%40 = load i8, i8* %0
br i1 %6, label %41, label %45
41: ; preds = %39
%42 = shl i64 %12, 32
%43 = add i64 %42, -4294967296
%44 = ashr exact i64 %43, 32
br label %45
45: ; preds = %41, %39
%46 = phi i64 [ 0, %39 ], [ %44, %41 ]
%47 = getelementptr inbounds i8, i8* %0, i64 %46
store i8 %40, i8* %47
br label %48
48: ; preds = %45, %37, %2
ret void
}