#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 */
typedef int /*<<< orphan*/ searchStr;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
scalar_t__ strnstr(char *, char *, size_t);
size_t Repeats(char *str) {
  if (!str) {
    return 0;
  }
  if (strlen(str) == 0) {
    return 1;
  }
  char searchStr[256 * 2];
  size_t strLen;
  size_t count;
  strLen = strlen(str);
  count = 0;
  memset(searchStr, '\0', sizeof(searchStr));
  strcpy(searchStr, str);
  strcat(searchStr, str);
  for (size_t i = 0; i < strLen; i++) {
    count += strnstr(searchStr + i, str, strLen) ? 1 : 0;
  }
  return count;
}


x86 assembly (clang, -O0):
<Repeats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <Repeats+0x27>
movq   $0x0,-0x8(%rbp)
jmp    1265 <Repeats+0x115>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1197 <Repeats+0x47>
movq   $0x1,-0x8(%rbp)
jmp    1265 <Repeats+0x115>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x218(%rbp)
movq   $0x0,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
movq   $0x0,-0x228(%rbp)
mov    -0x228(%rbp),%rax
cmp    -0x218(%rbp),%rax
jae    125a <Repeats+0x10a>
lea    -0x210(%rbp),%rdi
add    -0x228(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x218(%rbp),%rdx
call   1060 <strnstr@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
cltq
add    -0x220(%rbp),%rax
mov    %rax,-0x220(%rbp)
mov    -0x228(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
jmp    11f0 <Repeats+0xa0>
mov    -0x220(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Repeats>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
test   %rdi,%rdi
je     11d2 <Repeats+0x82>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     11d7 <Repeats+0x87>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rsp,%r12
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
test   %r15,%r15
je     11dd <Repeats+0x8d>
xor    %ebx,%ebx
xor    %r13d,%r13d
nopl   (%rax)
lea    (%rsp,%rbx,1),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <strnstr@plt>
cmp    $0x1,%rax
sbb    $0xffffffffffffffff,%r13
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <Repeats+0x60>
jmp    11dd <Repeats+0x8d>
xor    %r13d,%r13d
jmp    11dd <Repeats+0x8d>
mov    $0x1,%r13d
mov    %r13,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @Repeats(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i64 0, i64* %2
br label %49
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i64 1, i64* %2
br label %49
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %5
store i64 0, i64* %6
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i8 signext 0, i32 512)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 @strcat(i8* %24, i8* %25)
store i64 0, i64* %7
br label %27
27: ; preds = %44, %16
%28 = load i64, i64* %7
%29 = load i64, i64* %5
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%33 = load i64, i64* %7
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8*, i8** %3
%36 = load i64, i64* %5
%37 = call i64 @strnstr(i8* %34, i8* %35, i64 %36)
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 1, i32 0
%41 = sext i32 %40 to i64
%42 = load i64, i64* %6
%43 = add i64 %42, %41
store i64 %43, i64* %6
br label %44
44: ; preds = %31
%45 = load i64, i64* %7
%46 = add i64 %45, 1
store i64 %46, i64* %7
br label %27
47: ; preds = %27
%48 = load i64, i64* %6
store i64 %48, i64* %2
br label %49
49: ; preds = %47, %15, %10
%50 = load i64, i64* %2
ret i64 %50
}

LLVM IR (-O2):
define i64 @Repeats(i8* %0) {
%2 = alloca [512 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%9 = tail call i64 @strlen(i8* %0)
%10 = call i32 @memset(i8* %8, i8 signext 0, i32 512)
%11 = call i32 @strcpy(i8* %8, i8* %0)
%12 = call i32 @strcat(i8* %8, i8* %0)
%13 = icmp eq i64 %9, 0
br i1 %13, label %14, label %16
14: ; preds = %16, %7
%15 = phi i64 [ 0, %7 ], [ %23, %16 ]
br label %26
16: ; preds = %7, %16
%17 = phi i64 [ %24, %16 ], [ 0, %7 ]
%18 = phi i64 [ %23, %16 ], [ 0, %7 ]
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %17
%20 = call i64 @strnstr(i8* %19, i8* %0, i64 %9)
%21 = icmp ne i64 %20, 0
%22 = zext i1 %21 to i64
%23 = add i64 %18, %22
%24 = add nuw i64 %17, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %14, label %16
26: ; preds = %4, %1, %14
%27 = phi i64 [ %15, %14 ], [ 0, %1 ], [ 1, %4 ]
ret i64 %27
}