#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int preceded_by(char *pattern, char *buf, int offset) {
  int len;
  len = strlen(pattern);
  if (offset < len)
    return 0;
  return strncmp(pattern, (buf + offset + 1) - len, len) == 0;
}


x86 assembly (clang, -O0):
<preceded_by>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1157 <preceded_by+0x37>
movl   $0x0,-0x4(%rbp)
jmp    118d <preceded_by+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
movslq -0x20(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preceded_by>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    %ebp,%eax
jg     115c <preceded_by+0x3c>
movslq %ebp,%rcx
add    %rcx,%rbx
movslq %eax,%rcx
sub    %rcx,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @preceded_by(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %30
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = sub i64 0, %23
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i32, i32* %8
%27 = call i64 @strncmp(i8* %16, i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %4
br label %30
30: ; preds = %15, %14
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @preceded_by(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = sext i32 %4 to i64
%11 = sub nsw i64 0, %10
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i64 @strncmp(i8* %0, i8* %12, i32 %4)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %3, %6
%17 = phi i32 [ %15, %6 ], [ 0, %3 ]
ret i32 %17
}