#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 */
size_t strcspn(char const *, char *);
size_t count_lines(const char msg[], size_t *max_len) {
  size_t nlines = 0U;
  *max_len = 0U;
  while (*msg != '\0') {
    const size_t len = strcspn(msg, "\n");
    if (len > *max_len) {
      *max_len = len;
    }
    ++nlines;
    msg += len + (msg[len] == '\n' ? 1U : 0U);
  }
  return nlines;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ae <count_lines+0x9e>
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <strcspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jbe    1173 <count_lines+0x63>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%esi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0xa,%esi
cmove  %edx,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1133 <count_lines+0x23>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movq   $0x0,(%rsi)
cmpb   $0x0,(%rdi)
je     1172 <count_lines+0x62>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r13d,%r13d
lea    0xecb(%rip),%r12
xor    %r15d,%r15d
jmp    115a <count_lines+0x4a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
xor    %ecx,%ecx
cmpb   $0xa,(%rbx,%rax,1)
sete   %cl
add    %rcx,%rax
cmpb   $0x0,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rbx
je     1175 <count_lines+0x65>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcspn@plt>
cmp    %r13,%rax
jbe    1140 <count_lines+0x30>
mov    %rax,(%r14)
mov    %rax,%r13
jmp    1140 <count_lines+0x30>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i64 @count_lines(i8* nocapture %0, i64* nocapture %1) {
store i64 0, i64* %1
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %12
%6 = phi i64 [ %13, %12 ], [ 0, %2 ]
%7 = phi i8* [ %20, %12 ], [ %0, %2 ]
%8 = phi i64 [ %14, %12 ], [ 0, %2 ]
%9 = tail call i64 @strcspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp ugt i64 %9, %6
br i1 %10, label %11, label %12
11: ; preds = %5
store i64 %9, i64* %1
br label %12
12: ; preds = %11, %5
%13 = phi i64 [ %9, %11 ], [ %6, %5 ]
%14 = add i64 %8, 1
%15 = getelementptr inbounds i8, i8* %7, i64 %9
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = zext i1 %17 to i64
%19 = add i64 %9, %18
%20 = getelementptr inbounds i8, i8* %7, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %12, %2
%24 = phi i64 [ 0, %2 ], [ %14, %12 ]
ret i64 %24
}