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


x86 assembly (clang, -O0):
<CountLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1183 <CountLine+0x63>
lea    0xea0(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <CountLine+0x1b>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountLine>:
push   %r15
push   %r14
push   %rbx
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1165 <CountLine+0x45>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xec0(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
add    $0x1,%ebx
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1140 <CountLine+0x20>
jmp    1167 <CountLine+0x47>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @CountLine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %10, %1
%7 = load i8*, i8** %4
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %4
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %4
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %6
17: ; preds = %6
%18 = load i32, i32* %3
ret i32 %18
}

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