#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 *FindString(char const *, char const *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char const *, char *);
int GetLineFor(const char *pBuffer, const char *S) {
  int n = 0;
  const char *p = pBuffer;
  const char *end = FindString(pBuffer, S);
  if (!end)
    return 0;
  while ((p = strstr(p, "\n"))) {
    p += strlen("\n");
    n++;
    if (p >= end)
      return n;
  }
  return n;
}


x86 assembly (clang, -O0):
<GetLineFor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <FindString@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1177 <GetLineFor+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <GetLineFor+0xb3>
jmp    117c <GetLineFor+0x4c>
mov    -0x28(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11dd <GetLineFor+0xad>
lea    0xe5f(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jb     11d8 <GetLineFor+0xa8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e3 <GetLineFor+0xb3>
jmp    117c <GetLineFor+0x4c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLineFor>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <FindString@plt>
test   %rax,%rax
je     117c <GetLineFor+0x4c>
mov    %rax,%r14
xor    %ebp,%ebp
lea    0xeb0(%rip),%r15
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117e <GetLineFor+0x4e>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%ebp
cmp    %r14,%rbx
jb     1150 <GetLineFor+0x20>
jmp    117e <GetLineFor+0x4e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @GetLineFor(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %7
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i8* @FindString(i8* %10, i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 0, i32* %3
br label %36
16: ; preds = %2
br label %17
17: ; preds = %33, %16
%18 = load i8*, i8** %7
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %7
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %7
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = load i8*, i8** %7
%29 = load i8*, i8** %8
%30 = icmp uge i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %36
33: ; preds = %21
br label %17
34: ; preds = %17
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %31, %15
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @GetLineFor(i8* %0, i8* %1) {
%3 = tail call i8* @FindString(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2, %10
%6 = phi i32 [ %14, %10 ], [ 0, %2 ]
%7 = phi i8* [ %13, %10 ], [ %0, %2 ]
%8 = tail call i8* @strchr(i8* dereferenceable(1) %7, i32 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = add nuw nsw i32 %6, 1
%15 = icmp ult i8* %13, %3
br i1 %15, label %5, label %16
16: ; preds = %5, %10, %2
%17 = phi i32 [ 0, %2 ], [ %6, %5 ], [ %14, %10 ]
ret i32 %17
}