#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 */
const char *find_line_start(const char *buffer, const size_t length) {
  const char *ptr = buffer + (length - 1);
  while (ptr >= buffer) {
    if (*ptr == '\n')
      return ptr + 1;
    ptr--;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<find_line_start>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     115f <find_line_start+0x5f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    114e <find_line_start+0x4e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1167 <find_line_start+0x67>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    111f <find_line_start+0x1f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_line_start>:
mov    %rdi,%rax
add    $0xffffffffffffffff,%rsi
js     111e <find_line_start+0x1e>
add    %rax,%rsi
nopl   0x0(%rax)
cmpb   $0xa,(%rsi)
je     111f <find_line_start+0x1f>
add    $0xffffffffffffffff,%rsi
cmp    %rax,%rsi
jae    1110 <find_line_start+0x10>
ret
add    $0x1,%rsi
mov    %rsi,%rax
ret

LLVM IR (-O0):
define i8* @find_line_start(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = load i64, i64* %5
%9 = sub i64 %8, 1
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8* %10, i8** %6
br label %11
11: ; preds = %23, %2
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = icmp uge i8* %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %3
br label %28
23: ; preds = %15
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %6
br label %11
26: ; preds = %11
%27 = load i8*, i8** %4
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %20
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @find_line_start(i8* %0, i64 %1) {
%3 = add i64 %1, -1
%4 = icmp slt i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 %3
br label %7
7: ; preds = %5, %13
%8 = phi i8* [ %14, %13 ], [ %6, %5 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %8, i64 1
br label %16
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %8, i64 -1
%15 = icmp ult i8* %14, %0
br i1 %15, label %16, label %7
16: ; preds = %13, %2, %11
%17 = phi i8* [ %12, %11 ], [ %0, %2 ], [ %0, %13 ]
ret i8* %17
}