#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 /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void old_find_pattern(char *output, char *input) {
  int j = (int)strlen(input);
  char *q;
  while (j) {
    q = input;
    while (!strncmp(q, input, j)) {
      q += j;
      if (!*q) {
        q -= j;
        strcpy(output, q);
        break;
      }
    }
    j--;
  }
}


x86 assembly (clang, -O0):
<old_find_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11dc <old_find_pattern+0xac>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1183 <old_find_pattern+0x53>
jmp    11ce <old_find_pattern+0x9e>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11c9 <old_find_pattern+0x99>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11ce <old_find_pattern+0x9e>
jmp    115e <old_find_pattern+0x2e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <old_find_pattern+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<old_find_pattern>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     119d <old_find_pattern+0x6d>
movslq %eax,%r12
mov    %r12,%r13
neg    %r13
jmp    116d <old_find_pattern+0x3d>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r12
add    $0x1,%r13
test   %r12d,%r12d
je     119d <old_find_pattern+0x6d>
mov    %r15,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1160 <old_find_pattern+0x30>
lea    (%rbx,%r12,1),%rsi
cmpb   $0x0,(%rbx,%r12,1)
mov    %rsi,%rbx
jne    1170 <old_find_pattern+0x40>
add    %r13,%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
jmp    1160 <old_find_pattern+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @old_find_pattern(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
br label %10
10: ; preds = %40, %2
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %43
13: ; preds = %10
%14 = load i8*, i8** %4
store i8* %14, i8** %6
br label %15
15: ; preds = %39, %13
%16 = load i8*, i8** %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = call i32 @strncmp(i8* %16, i8* %17, i32 %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %40
22: ; preds = %15
%23 = load i32, i32* %5
%24 = load i8*, i8** %6
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %22
%31 = load i32, i32* %5
%32 = load i8*, i8** %6
%33 = sext i32 %31 to i64
%34 = sub i64 0, %33
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8* %35, i8** %6
%36 = load i8*, i8** %3
%37 = load i8*, i8** %6
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %40
39: ; preds = %22
br label %15
40: ; preds = %30, %15
%41 = load i32, i32* %5
%42 = add nsw i32 %41, -1
store i32 %42, i32* %5
br label %10
43: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @old_find_pattern(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = shl i64 %3, 32
%8 = ashr exact i64 %7, 32
br label %9
9: ; preds = %6, %22
%10 = phi i64 [ %8, %6 ], [ %23, %22 ]
%11 = trunc i64 %10 to i32
br label %12
12: ; preds = %9, %16
%13 = phi i8* [ %17, %16 ], [ %1, %9 ]
%14 = tail call i32 @strncmp(i8* %13, i8* %1, i32 %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %13, i64 %10
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %16
%21 = tail call i32 @strcpy(i8* %0, i8* %13)
br label %22
22: ; preds = %12, %20
%23 = add nsw i64 %10, -1
%24 = trunc i64 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %9
26: ; preds = %22, %2
ret void
}