#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(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
bool stringRotation(char s1[], char s2[]) {
  int len1 = strlen(s1);
  if (len1 != strlen(s2)) {
    return false;
  }
  char *twos1 = malloc((2 * len1 + 1) * sizeof(char));
  memcpy(twos1, s1, len1 * sizeof(char));
  memcpy(twos1 + len1 * sizeof(char), s1, (len1 + 1) * sizeof(char));
  bool result = strstr(twos1, s2) != NULL;
  free(twos1);
  return result;
}


x86 assembly (clang, -O0):
<stringRotation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
je     1194 <stringRotation+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1216 <stringRotation+0xc6>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringRotation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    %eax,%ebx
jne    11c0 <stringRotation+0x70>
lea    (%rbx,%rbx,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movslq %ebx,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    %r12,%rbp
add    $0x1,%ebx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @stringRotation(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 %19
6: ; preds = %2
%7 = shl nsw i32 %3, 1
%8 = or i32 %7, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = sext i32 %3 to i64
%11 = tail call i32 @memcpy(i8* %9, i8* %0, i32 %3)
%12 = getelementptr inbounds i8, i8* %9, i64 %10
%13 = add nsw i32 %3, 1
%14 = tail call i32 @memcpy(i8* %12, i8* %0, i32 %13)
%15 = tail call i32* @strstr(i8* dereferenceable(1) %9, i8* dereferenceable(1) %1)
%16 = icmp ne i32* %15, null
%17 = zext i1 %16 to i32
%18 = tail call i32 @free(i8* %9)
br label %19
19: ; preds = %2, %6
%20 = phi i32 [ %17, %6 ], [ 0, %2 ]
ret i32 %20
}