#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*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ Repeats(char *);
scalar_t__ SameNecklace(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char const *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  const char *prog = argv[argc - argc];
  char input[256];
  char srcStr[256];
  char shiftedStr[256];
  FILE *snFile;
  FILE *repFile;
  snFile = fopen("./same_necklace.txt", "r");
  repFile = fopen("./repeats.txt", "r");
  while (fgets(input, 256, snFile)) {
    strcpy(srcStr, "\0");
    strcpy(shiftedStr, "\0");
    sscanf(input, "\"%[^\"]\", \"%[^\"]", srcStr, shiftedStr);
    printf("%s: %s\n", prog,
           SameNecklace(srcStr, shiftedStr) ? "true" : "false");
  }
  strcpy(input, "\0");
  while (fgets(input, 256, repFile)) {
    strcpy(srcStr, "\0");
    sscanf(input, "\"%[^\"]\"", srcStr);
    printf("%s: \"%s\" repeats: %lu\n", prog, srcStr, Repeats(srcStr));
  }
  fclose(snFile);
  fclose(repFile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x328(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x330(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x328(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     129e <main+0x11e>
lea    -0x220(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x320(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    -0x320(%rbp),%rcx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x338(%rbp)
lea    -0x220(%rbp),%rdi
lea    -0x320(%rbp),%rsi
call   10a0 <SameNecklace@plt>
mov    -0x338(%rbp),%rsi
mov    %rax,%rcx
lea    0xdc5(%rip),%rdx
lea    0xdb9(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e2 <main+0x62>
lea    -0x120(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x330(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     134a <main+0x1ca>
lea    -0x220(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x348(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x340(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <Repeats@plt>
mov    -0x348(%rbp),%rsi
mov    -0x340(%rbp),%rdx
mov    %eax,%ecx
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b1 <main+0x131>
mov    -0x328(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x330(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    (%rsi),%r12
lea    0xe65(%rip),%rdi
lea    0xe72(%rip),%rbx
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1273 <main+0xf3>
lea    0xe84(%rip),%r13
lea    0x110(%rsp),%rbx
lea    0x210(%rsp),%rbp
lea    0x10(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
lea    0xe04(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <sscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <SameNecklace@plt>
test   %rax,%rax
lea    0xdfa(%rip),%rdx
lea    0xdf8(%rip),%rax
cmove  %rax,%rdx
lea    0xde0(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1200 <main+0x80>
mov    %r15,0x8(%rsp)
lea    0xde7(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    (%rsp),%r14
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     130e <main+0x18e>
lea    0x110(%rsp),%rbp
lea    0xd93(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xd8f(%rip),%r13
mov    %rbp,%rdi
lea    0xd9c(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <sscanf@plt>
mov    %rbp,%rdi
call   1070 <Repeats@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    12c0 <main+0x140>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"./same_necklace.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"./repeats.txt\00"
@.str.3 = [2 x i8] zeroinitializer
@.str.4 = [16 x i8] c"\22%[^\22]\22, \22%[^\22]\00"
@.str.5 = [8 x i8] c"%s: %s\0A\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [6 x i8] c"false\00"
@.str.8 = [8 x i8] c"\22%[^\22]\22\00"
@.str.9 = [23 x i8] c"%s: \22%s\22 repeats: %lu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = load i32, i32* %4
%14 = load i32, i32* %4
%15 = sub nsw i32 %13, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %12, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %10
%20 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %11
br label %21
21: ; preds = %26, %2
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = load i32*, i32** %10
%24 = call i64 @fgets(i8* %22, i32 256, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%34 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %32, i8* %33)
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%38 = call i64 @SameNecklace(i8* %36, i8* %37)
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%42 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %35, i8* %41)
br label %21
43: ; preds = %21
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %51, %43
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%48 = load i32*, i32** %11
%49 = call i64 @fgets(i8* %47, i32 256, i32* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %62
51: ; preds = %46
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%53 = call i32 @strcpy(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%56 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %6
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%60 = call i32 @Repeats(i8* %59)
%61 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %57, i8* %58, i32 %60)
br label %46
62: ; preds = %46
%63 = load i32*, i32** %10
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
}

LLVM IR (-O2):
@.str = [20 x i8] c"./same_necklace.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"./repeats.txt\00"
@.str.3 = [2 x i8] zeroinitializer
@.str.4 = [16 x i8] c"\22%[^\22]\22, \22%[^\22]\00"
@.str.5 = [8 x i8] c"%s: %s\0A\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [6 x i8] c"false\00"
@.str.8 = [8 x i8] c"\22%[^\22]\22\00"
@.str.9 = [23 x i8] c"%s: \22%s\22 repeats: %lu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = load i8*, i8** %1
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i64 @fgets(i8* %7, i32 256, i32* %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %2, %14
%15 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %8, i8* %9)
%18 = call i64 @SameNecklace(i8* %8, i8* %9)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
%21 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %20)
%22 = call i64 @fgets(i8* %7, i32 256, i32* %10)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %14
24: ; preds = %14, %2
%25 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = call i64 @fgets(i8* %7, i32 256, i32* %11)
%27 = icmp eq i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %24, %28
%29 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%31 = call i32 @Repeats(i8* %8)
%32 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %6, i8* %8, i32 %31)
%33 = call i64 @fgets(i8* %7, i32 256, i32* %11)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %28
35: ; preds = %28, %24
%36 = call i32 @fclose(i32* %10)
%37 = call i32 @fclose(i32* %11)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}