#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 findNextChar(char const *, int, char);
int countLinesToToken(const char *data, int len) {
  int count = 0;
  int next;
  while (*data != '*') {
    next = findNextChar(data, len, '\n');
    if (next < 0)
      return -1;
    count++;
    data += next + 1;
    len -= next + 1;
  }
  return count;
}


x86 assembly (clang, -O0):
<countLinesToToken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     1190 <countLinesToToken+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0xa,%edx
call   1030 <findNextChar@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1160 <countLinesToToken+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <countLinesToToken+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <countLinesToToken+0x16>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLinesToToken>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmpb   $0x2a,(%rdi)
je     1163 <countLinesToToken+0x53>
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0xa,%edx
call   1030 <findNextChar@plt>
test   %eax,%eax
js     115d <countLinesToToken+0x4d>
add    $0x1,%r14d
mov    %eax,%eax
lea    0x1(%rax),%rcx
sub    %ecx,%ebp
cmpb   $0x2a,0x1(%rbx,%rax,1)
lea    0x1(%rbx,%rax,1),%rbx
jne    1130 <countLinesToToken+0x20>
jmp    1163 <countLinesToToken+0x53>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @countLinesToToken(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 42
br i1 %4, label %19, label %5
5: ; preds = %2, %11
%6 = phi i32 [ %12, %11 ], [ 0, %2 ]
%7 = phi i32 [ %16, %11 ], [ %1, %2 ]
%8 = phi i8* [ %15, %11 ], [ %0, %2 ]
%9 = tail call i32 @findNextChar(i8* %8, i32 %7, i8 signext 10)
%10 = icmp slt i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %5
%12 = add nuw nsw i32 %6, 1
%13 = add nuw nsw i32 %9, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = sub nsw i32 %7, %13
%17 = load i8, i8* %15
%18 = icmp eq i8 %17, 42
br i1 %18, label %19, label %5
19: ; preds = %5, %11, %2
%20 = phi i32 [ 0, %2 ], [ %12, %11 ], [ -1, %5 ]
ret i32 %20
}