#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 */
char *strchr(char const *, char);
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, size_t);
const char *find_str_at_start_of_line(const char *haystack,
                                      const char *needle) {
  size_t needle_len = strlen(needle);
  do {
    if (!strncmp(haystack, needle, needle_len))
      return haystack;
    haystack = strchr(haystack, '\n');
    if (!haystack)
      return NULL;
    else
      ++haystack;
  } while (*haystack);
  return NULL;
}


x86 assembly (clang, -O0):
<find_str_at_start_of_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1174 <find_str_at_start_of_line+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <find_str_at_start_of_line+0x94>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <find_str_at_start_of_line+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <find_str_at_start_of_line+0x94>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11af <find_str_at_start_of_line+0x7f>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    114d <find_str_at_start_of_line+0x1d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_str_at_start_of_line>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1183 <find_str_at_start_of_line+0x53>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1181 <find_str_at_start_of_line+0x51>
mov    %rax,%rbx
add    $0x1,%rbx
cmpb   $0x0,0x1(%rax)
jne    1150 <find_str_at_start_of_line+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @find_str_at_start_of_line(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
br label %4
4: ; preds = %11, %2
%5 = phi i8* [ %0, %2 ], [ %12, %11 ]
%6 = tail call i32 @strncmp(i8* %5, i8* %1, i64 %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %11, %8, %4
%16 = phi i8* [ %5, %4 ], [ null, %8 ], [ null, %11 ]
ret i8* %16
}