#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__ is_line_sep(char const);
int strlen(char const *);
char *strstr(char const *, char const *);
char *find_line(const char *str, const char *line) {
  if (str) {
    const char *p;
    int len = strlen(line);
    for (p = str; (p = strstr(p, line)) != NULL; p += len + 1) {
      if ((p == str || is_line_sep(p[-1])) && is_line_sep(p[len]))
        return (char *)p;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ea <find_line+0xba>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e5 <find_line+0xb5>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     119f <find_line+0x6f>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <is_line_sep@plt>
cmp    $0x0,%rax
je     11c7 <find_line+0x97>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <is_line_sep@plt>
cmp    $0x0,%rax
je     11c7 <find_line+0x97>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <find_line+0xc2>
jmp    11cc <find_line+0x9c>
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <find_line+0x2f>
jmp    11ea <find_line+0xba>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     11aa <find_line+0x7a>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11aa <find_line+0x7a>
mov    %rax,%rbx
movslq %ebp,%r12
lea    0x1(%r12),%eax
movslq %eax,%rbp
jmp    1195 <find_line+0x65>
nopl   (%rax)
movsbl (%rbx,%r12,1),%edi
call   1040 <is_line_sep@plt>
test   %rax,%rax
jne    11ac <find_line+0x7c>
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11aa <find_line+0x7a>
cmp    %r15,%rbx
je     1170 <find_line+0x40>
movsbl -0x1(%rbx),%edi
call   1040 <is_line_sep@plt>
test   %rax,%rax
jne    1170 <find_line+0x40>
jmp    117f <find_line+0x4f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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