#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 containsString(char *buf, char *thing) {
  int i = strlen(buf) - strlen(thing);
  while (i >= 0) {
    if (strncmp(buf + i, thing, strlen(thing)) == 0) {
      return (1);
    }
    i--;
  }
  return (0);
}


x86 assembly (clang, -O0):
<containsString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11ac <containsString+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119e <containsString+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <containsString+0x93>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <containsString+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<containsString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %r15d,%r15d
sub    %eax,%ebp
js     117d <containsString+0x5d>
mov    %ebp,%eax
add    $0x1,%ebp
add    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1177 <containsString+0x57>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %ebp,%ebp
jg     1150 <containsString+0x30>
jmp    117d <containsString+0x5d>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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