#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 anagram(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char str1[100];
  char str2[100];
  int ret, s1len, s2len;
  printf("Input a sentence and a strings, to test if sentence has anagrams of "
         "string:\n");
  scanf("%s", str1);
  printf("\n");
  scanf("%s", str2);
  s1len = strlen(str1);
  s2len = strlen(str2);
  for (int i = 0; i < s1len; i++) {
    ret = anagram(&str1[i], str2, strlen(str2));
    if (ret) {
      printf("str1=%s has anagram of str2=%s, at location %d\n", str1, str2,
             i + 1);
    }
    if ((s1len - i) <= s2len)
      break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xedb(%rip),%rdi
call   1060 <scanf@plt>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rsi
lea    0xeba(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xfc(%rbp)
movl   $0x0,-0x100(%rbp)
mov    -0x100(%rbp),%eax
cmp    -0xf8(%rbp),%eax
jge    1284 <main+0x144>
movslq -0x100(%rbp),%rcx
lea    -0x80(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x110(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0xf0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x110(%rbp),%rdi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1050 <anagram@plt>
mov    %eax,-0xf4(%rbp)
cmpl   $0x0,-0xf4(%rbp)
je     124e <main+0x10e>
lea    -0x80(%rbp),%rsi
lea    -0xf0(%rbp),%rdx
mov    -0x100(%rbp),%ecx
add    $0x1,%ecx
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xf8(%rbp),%eax
sub    -0x100(%rbp),%eax
cmp    -0xfc(%rbp),%eax
jg     126b <main+0x12b>
jmp    1284 <main+0x144>
jmp    1270 <main+0x130>
mov    -0x100(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100(%rbp)
jmp    11c3 <main+0x83>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7c(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x70(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %ebx,%ebx
jle    122c <main+0xcc>
mov    %ebx,%r12d
movslq %eax,%r14
mov    $0x1,%ebx
lea    0x70(%rsp),%r15
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rsp,%rbx,1),%r13
add    $0xffffffffffffffff,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <anagram@plt>
test   %eax,%eax
je     1217 <main+0xb7>
lea    0xdfb(%rip),%rdi
mov    %rsp,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r14,%rbp
jle    122c <main+0xcc>
lea    0x1(%rbx),%rax
add    $0xffffffffffffffff,%rbp
cmp    %r12,%rbx
mov    %rax,%rbx
jb     11e0 <main+0x80>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [77 x i8] c"Input a sentence and a strings, to test if sentence has anagrams of string:\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [48 x i8] c"str1=%s has anagram of str2=%s, at location %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %9
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %10
store i32 0, i32* %11
br label %22
22: ; preds = %50, %2
%23 = load i32, i32* %11
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %53
26: ; preds = %22
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %28
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @anagram(i8* %29, i8* %30, i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %26
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %38, i32 %40)
br label %42
42: ; preds = %36, %26
%43 = load i32, i32* %9
%44 = load i32, i32* %11
%45 = sub nsw i32 %43, %44
%46 = load i32, i32* %10
%47 = icmp sle i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %53
49: ; preds = %42
br label %50
50: ; preds = %49
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %22
53: ; preds = %48, %22
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [48 x i8] c"str1=%s has anagram of str2=%s, at location %d\0A\00"
@str = [76 x i8] c"Input a sentence and a strings, to test if sentence has anagrams of string:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 @putchar(i32 10)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @strlen(i8* %6)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %32
14: ; preds = %2
%15 = zext i32 %11 to i64
%16 = sext i32 %12 to i64
br label %17
17: ; preds = %27, %14
%18 = phi i64 [ %23, %27 ], [ 0, %14 ]
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %18
%20 = call i32 @strlen(i8* %6)
%21 = call i32 @anagram(i8* %19, i8* %6, i32 %20)
%22 = icmp eq i32 %21, 0
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %27, label %24
24: ; preds = %17
%25 = trunc i64 %23 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %6, i32 %25)
br label %27
27: ; preds = %17, %24
%28 = sub nsw i64 %15, %18
%29 = icmp sgt i64 %28, %16
%30 = icmp ult i64 %23, %15
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %17, label %32
32: ; preds = %27, %2
ret i32 0
}