#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 */
scalar_t__ emalloc(int);
int /*<<< orphan*/ free(char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char const *);
int str_similar_str(const char *str1, const char *str2) {
  int len;
  char *s;
  char *temp1;
  if (strstr(str1, str2))
    return 1;
  len = strlen(str2);
  if (strstr(str1, str2 + len / 5))
    return 1;
  len = (4 * len) / 5;
  temp1 = (char *)emalloc(len + 1);
  strncpy(temp1, str2, len);
  temp1[len] = 0;
  s = strstr(str1, temp1);
  free(temp1);
  if (s)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<str_similar_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1183 <str_similar_str+0x33>
movl   $0x1,-0x4(%rbp)
jmp    1236 <str_similar_str+0xe6>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11c2 <str_similar_str+0x72>
movl   $0x1,-0x4(%rbp)
jmp    1236 <str_similar_str+0xe6>
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1060 <emalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     122f <str_similar_str+0xdf>
movl   $0x1,-0x4(%rbp)
jmp    1236 <str_similar_str+0xe6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_similar_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1070 <strstr@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1204 <str_similar_str+0xb4>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %r14,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
jne    1204 <str_similar_str+0xb4>
shl    $0x2,%r15d
movslq %r15d,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
lea    (%rax,%rcx,1),%r15d
lea    (%rax,%rcx,1),%edi
add    $0x1,%edi
call   1060 <emalloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1070 <strstr@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @str_similar_str(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = sdiv i32 %6, 5
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %25
12: ; preds = %5
%13 = shl nsw i32 %6, 2
%14 = sdiv i32 %13, 5
%15 = add nsw i32 %14, 1
%16 = tail call i64 @emalloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @strncpy(i8* %17, i8* %1, i32 %14)
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
%21 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %17)
%22 = tail call i32 @free(i8* %17)
%23 = icmp ne i8* %21, null
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %12, %5, %2
%26 = phi i32 [ 1, %2 ], [ 1, %5 ], [ %24, %12 ]
ret i32 %26
}