#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*/ btp_location_add_ext(int *, int *, int, int);
int /*<<< orphan*/ btp_location_eat_char_ext(int *, int *, char const);
char *btp_strchr_location(char const *, char const, int *, int *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
char *btp_strstr_location(const char *haystack, const char *needle, int *line,
                          int *column) {
  *line = 1;
  *column = 0;
  size_t needlelen;
  if (*needle == '\0')
    return (char *)haystack;
  needlelen = strlen(needle);
  int chrline, chrcolumn;
  for (; (haystack = btp_strchr_location(haystack, *needle, &chrline,
                                         &chrcolumn)) != NULL;
       ++haystack) {
    btp_location_add_ext(line, column, chrline, chrcolumn);
    if (strncmp(haystack, needle, needlelen) == 0)
      return (char *)haystack;
    btp_location_eat_char_ext(line, column, *haystack);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<btp_strstr_location>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1199 <btp_strstr_location+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1234 <btp_strstr_location+0xe4>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
movsbl (%rax),%esi
call   1050 <btp_strchr_location@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     122c <btp_strstr_location+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
call   1060 <btp_location_add_ext@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1207 <btp_strstr_location+0xb7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1234 <btp_strstr_location+0xe4>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
call   1070 <btp_location_eat_char_ext@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a6 <btp_strstr_location+0x56>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btp_strstr_location>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x1,(%rdx)
movl   $0x0,(%rcx)
mov    (%rsi),%bpl
test   %bpl,%bpl
je     1206 <btp_strstr_location+0xb6>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
movsbl %bpl,%esi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
call   1050 <btp_strchr_location@plt>
test   %rax,%rax
je     1204 <btp_strstr_location+0xb4>
mov    %rax,%rbx
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <btp_location_add_ext@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1206 <btp_strstr_location+0xb6>
movsbl (%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <btp_location_eat_char_ext@plt>
add    $0x1,%rbx
movsbl (%r12),%esi
mov    %rbx,%rdi
lea    0x4(%rsp),%rdx
mov    %rbp,%rcx
call   1050 <btp_strchr_location@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b0 <btp_strstr_location+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @btp_strstr_location(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
store i32 1, i32* %2
store i32 0, i32* %3
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %31, label %9
9: ; preds = %4
%10 = tail call i64 @strlen(i8* %1)
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = call i8* @btp_strchr_location(i8* %0, i8 signext %7, i32* %5, i32* %6)
%14 = icmp eq i8* %13, null
br i1 %14, label %29, label %15
15: ; preds = %9, %22
%16 = phi i8* [ %27, %22 ], [ %13, %9 ]
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @btp_location_add_ext(i32* %2, i32* %3, i32 %17, i32 %18)
%20 = call i64 @strncmp(i8* %16, i8* %1, i64 %10)
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = load i8, i8* %16
%24 = call i32 @btp_location_eat_char_ext(i32* %2, i32* %3, i8 signext %23)
%25 = getelementptr inbounds i8, i8* %16, i64 1
%26 = load i8, i8* %1
%27 = call i8* @btp_strchr_location(i8* %25, i8 signext %26, i32* %5, i32* %6)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %15
29: ; preds = %15, %22, %9
%30 = phi i8* [ null, %9 ], [ null, %22 ], [ %16, %15 ]
br label %31
31: ; preds = %4, %29
%32 = phi i8* [ %30, %29 ], [ %0, %4 ]
ret i8* %32
}