#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 */
char *cr_findnl(char *buf, int len) {
  while (--len >= 0) {
    if (*(buf++) == '\r')
      if (*buf == '\n')
        return --buf;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<cr_findnl>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1167 <cr_findnl+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    1162 <cr_findnl+0x62>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    115d <cr_findnl+0x5d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x8(%rbp)
jmp    116f <cr_findnl+0x6f>
jmp    1162 <cr_findnl+0x62>
jmp    110b <cr_findnl+0xb>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cr_findnl>:
test   %esi,%esi
jle    1128 <cr_findnl+0x28>
mov    %rdi,%rax
add    $0x1,%esi
jmp    111c <cr_findnl+0x1c>
nopl   0x0(%rax)
add    $0x1,%rax
add    $0xffffffff,%esi
cmp    $0x1,%esi
jbe    1128 <cr_findnl+0x28>
cmpb   $0xd,(%rax)
jne    1110 <cr_findnl+0x10>
cmpb   $0xa,0x1(%rax)
jne    1110 <cr_findnl+0x10>
ret
xor    %eax,%eax
ret

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

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