#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 *, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *nlsindex(char *s1, char *s2) {
  register int s2len = strlen(s2);
  char *curline = s1;
  if (strncmp(curline, s2, s2len) == 0)
    return (curline);
  while ((curline = strchr(curline, (int)'\n')) != 0) {
    curline++;
    if (strncmp(curline, s2, s2len) == 0)
      return (curline);
  }
  return (0);
}


x86 assembly (clang, -O0):
<nlsindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    117b <nlsindex+0x4b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <nlsindex+0xac>
jmp    1180 <nlsindex+0x50>
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d4 <nlsindex+0xa4>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cf <nlsindex+0x9f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <nlsindex+0xac>
jmp    1180 <nlsindex+0x50>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nlsindex>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
nopl   0x0(%rax)
call   1030 <strncmp@plt>
test   %rax,%rax
je     117f <nlsindex+0x4f>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     117d <nlsindex+0x4d>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
jmp    1150 <nlsindex+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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