#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 getweight(char *, int *, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
void findAnagram(char *tp, char *pp, int *alphap) {
  int tlen = strlen(tp);
  int plen = strlen(pp);
  int index = 0;
  int i;
  int pweight = getweight(pp, alphap, plen);
  int tweight = 0;
  for (i = 0; i < tlen - plen + 1; i++) {
    tweight = getweight(tp, alphap, plen);
    if (tweight == pweight) {
      printf("anagram found at index %d\n", index);
    }
    index++;
    tp++;
  }
}


x86 assembly (clang, -O0):
<findAnagram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <getweight@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11e9 <findAnagram+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <getweight@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11c6 <findAnagram+0x96>
mov    -0x24(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1184 <findAnagram+0x54>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findAnagram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <getweight@plt>
sub    %ebp,%r13d
jge    1177 <findAnagram+0x47>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
add    $0x1,%r13d
xor    %ebx,%ebx
jmp    1199 <findAnagram+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %ebx,%r13d
je     1168 <findAnagram+0x38>
lea    (%r15,%rbx,1),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <getweight@plt>
cmp    %r12d,%eax
jne    1190 <findAnagram+0x60>
lea    0xe4d(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
jmp    1190 <findAnagram+0x60>

LLVM IR (-O0):
@.str = [27 x i8] c"anagram found at index %d\0A\00"
define void @findAnagram(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %8
store i32 0, i32* %9
%17 = load i8*, i8** %5
%18 = load i32*, i32** %6
%19 = load i32, i32* %8
%20 = call i32 @getweight(i8* %17, i32* %18, i32 %19)
store i32 %20, i32* %11
store i32 0, i32* %12
store i32 0, i32* %10
br label %21
21: ; preds = %44, %3
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = sub nsw i32 %23, %24
%26 = add nsw i32 %25, 1
%27 = icmp slt i32 %22, %26
br i1 %27, label %28, label %47
28: ; preds = %21
%29 = load i8*, i8** %4
%30 = load i32*, i32** %6
%31 = load i32, i32* %8
%32 = call i32 @getweight(i8* %29, i32* %30, i32 %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = load i32, i32* %11
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* %9
%38 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %28
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
br label %44
44: ; preds = %39
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %21
47: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"anagram found at index %d\0A\00"
define void @findAnagram(i8* %0, i8* %1, i32* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @getweight(i8* %1, i32* %2, i32 %5)
%7 = icmp slt i32 %4, %5
br i1 %7, label %22, label %8
8: ; preds = %3
%9 = add i32 %4, 1
%10 = sub i32 %9, %5
br label %11
11: ; preds = %8, %18
%12 = phi i8* [ %20, %18 ], [ %0, %8 ]
%13 = phi i32 [ %19, %18 ], [ 0, %8 ]
%14 = tail call i32 @getweight(i8* %12, i32* %2, i32 %5)
%15 = icmp eq i32 %14, %6
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %18
18: ; preds = %16, %11
%19 = add nuw i32 %13, 1
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = icmp eq i32 %19, %10
br i1 %21, label %22, label %11
22: ; preds = %18, %3
ret void
}