#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 *strstr(char *, char *);
char *getLineEnding(char *s) {
  char *e = NULL;
  if ((e = strstr(s, "\r\n"))) {
    e += 2;
  } else if ((e = strstr(s, "\n"))) {
    e += 1;
  }
  return e;
}


x86 assembly (clang, -O0):
<getLineEnding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1153 <getLineEnding+0x43>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    1182 <getLineEnding+0x72>
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     117d <getLineEnding+0x6d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1182 <getLineEnding+0x72>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLineEnding>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     113b <getLineEnding+0x1b>
add    $0x2,%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
add    $0x1,%rax
test   %rcx,%rcx
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @getLineEnding(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = call i8* @strstr(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 2
store i8* %9, i8** %3
br label %18
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %3
br label %17
17: ; preds = %14, %10
br label %18
18: ; preds = %17, %7
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i8* @getLineEnding(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 2
br label %11
6: ; preds = %1
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 10)
%8 = icmp eq i8* %7, null
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = select i1 %8, i8* null, i8* %9
br label %11
11: ; preds = %6, %4
%12 = phi i8* [ %5, %4 ], [ %10, %6 ]
ret i8* %12
}