#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 strlen(char *);
int advance_to_next_line(char *rules_string, size_t *begin, size_t *end) {
  size_t rules_string_len = strlen(rules_string);
  if (!*end && (*end >= strlen(rules_string)))
    return -1;
  *begin = *end + 1;
  (*end)++;
  if (*end >= rules_string_len)
    return -1;
  while (rules_string[*end] && rules_string[*end] != '\n') {
    *end += 1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<advance_to_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116f <advance_to_next_line+0x5f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jb     116f <advance_to_next_line+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <advance_to_next_line+0x100>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jb     11ac <advance_to_next_line+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <advance_to_next_line+0x100>
jmp    11b1 <advance_to_next_line+0xa1>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11e6 <advance_to_next_line+0xd6>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11f6 <advance_to_next_line+0xe6>
jmp    1209 <advance_to_next_line+0xf9>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11b1 <advance_to_next_line+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<advance_to_next_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    (%rbx),%rdx
mov    $0xffffffff,%eax
mov    %rdx,%rsi
or     %rcx,%rsi
je     1169 <advance_to_next_line+0x59>
add    $0x1,%rdx
mov    %rdx,(%r15)
mov    (%rbx),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rbx)
cmp    %rcx,%rsi
jae    1169 <advance_to_next_line+0x59>
add    $0x2,%rdx
movzbl -0x1(%r14,%rdx,1),%eax
test   %al,%al
je     1167 <advance_to_next_line+0x57>
cmp    $0xa,%al
je     1167 <advance_to_next_line+0x57>
mov    %rdx,(%rbx)
add    $0x1,%rdx
jmp    1150 <advance_to_next_line+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @advance_to_next_line(i8* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i64*, i64** %7
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %3
%15 = load i64*, i64** %7
%16 = load i64, i64* %15
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = icmp uge i64 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %4
br label %58
21: ; preds = %14, %3
%22 = load i64*, i64** %7
%23 = load i64, i64* %22
%24 = add i64 %23, 1
%25 = load i64*, i64** %6
store i64 %24, i64* %25
%26 = load i64*, i64** %7
%27 = load i64, i64* %26
%28 = add i64 %27, 1
store i64 %28, i64* %26
%29 = load i64*, i64** %7
%30 = load i64, i64* %29
%31 = load i64, i64* %8
%32 = icmp uge i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %21
store i32 -1, i32* %4
br label %58
34: ; preds = %21
br label %35
35: ; preds = %53, %34
%36 = load i8*, i8** %5
%37 = load i64*, i64** %7
%38 = load i64, i64* %37
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %35
%44 = load i8*, i8** %5
%45 = load i64*, i64** %7
%46 = load i64, i64* %45
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 10
br label %51
51: ; preds = %43, %35
%52 = phi i1 [ false, %35 ], [ %50, %43 ]
br i1 %52, label %53, label %57
53: ; preds = %51
%54 = load i64*, i64** %7
%55 = load i64, i64* %54
%56 = add i64 %55, 1
store i64 %56, i64* %54
br label %35
57: ; preds = %51
store i32 0, i32* %4
br label %58
58: ; preds = %57, %33, %20
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
define i32 @advance_to_next_line(i8* nocapture %0, i64* nocapture writeonly %1, i64* nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
%7 = icmp eq i64 %4, 0
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %20, label %9
9: ; preds = %3
%10 = add i64 %5, 1
store i64 %10, i64* %1
%11 = load i64, i64* %2
%12 = add i64 %11, 1
store i64 %12, i64* %2
%13 = icmp ult i64 %12, %4
br i1 %13, label %14, label %20
14: ; preds = %9, %18
%15 = phi i64 [ %19, %18 ], [ %12, %9 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
switch i8 %17, label %18 [
i8 0, label %20
i8 10, label %20
]
18: ; preds = %14
%19 = add i64 %15, 1
store i64 %19, i64* %2
br label %14
20: ; preds = %14, %14, %9, %3
%21 = phi i32 [ -1, %3 ], [ -1, %9 ], [ 0, %14 ], [ 0, %14 ]
ret i32 %21
}