#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 */
scalar_t__ calloc(int, int);
scalar_t__ isSubstring(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
bool is_rotation(char *s1, char *s2) {
  char *buf;
  if (strlen(s1) != strlen(s2)) {
    return false;
  } else {
    buf = (char *)calloc(strlen(s1) + 1, sizeof(char));
  }
  for (int i = 0; i < strlen(s1); i++) {
    strcpy(buf, s2 + i);
    strncpy(buf + strlen(s2 + i), s2, i);
    if (isSubstring(buf, s1)) {
      return true;
    }
  }
  return false;
}


x86 assembly (clang, -O0):
<is_rotation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
je     118e <is_rotation+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    124b <is_rotation+0xfb>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1244 <is_rotation+0xf4>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <isSubstring@plt>
cmp    $0x0,%rax
je     1231 <is_rotation+0xe1>
movl   $0x1,-0x4(%rbp)
jmp    124b <is_rotation+0xfb>
jmp    1236 <is_rotation+0xe6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b1 <is_rotation+0x61>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_rotation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
xor    %ebx,%ebx
cmp    %eax,%ebp
jne    11f3 <is_rotation+0xa3>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11f3 <is_rotation+0xa3>
xor    %ebx,%ebx
nopl   (%rax)
lea    (%r14,%rbx,1),%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <isSubstring@plt>
test   %rax,%rax
jne    11ee <is_rotation+0x9e>
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <is_rotation+0x50>
xor    %ebx,%ebx
jmp    11f3 <is_rotation+0xa3>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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