#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void crlf_to_lf(char *line, ssize_t linelen, FILE *output_stream) {
  if (linelen >= 2 && line[linelen - 2] == '\r' && line[linelen - 1] == '\n') {
    line[linelen - 2] = '\n';
    line[linelen - 1] = '\0';
  }
  fputs(line, output_stream);
}


x86 assembly (clang, -O0):
<crlf_to_lf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     1183 <crlf_to_lf+0x73>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1183 <crlf_to_lf+0x73>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1183 <crlf_to_lf+0x73>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <fputs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crlf_to_lf>:
cmp    $0x2,%esi
jl     112f <crlf_to_lf+0x1f>
lea    -0x2(%rsi),%eax
cmpb   $0xd,(%rdi,%rax,1)
jne    112f <crlf_to_lf+0x1f>
add    $0xffffffff,%esi
cmpb   $0xa,(%rdi,%rsi,1)
jne    112f <crlf_to_lf+0x1f>
movb   $0xa,(%rdi,%rax,1)
movb   $0x0,(%rdi,%rsi,1)
mov    %rdx,%rsi
jmp    1030 <fputs@plt>

LLVM IR (-O0):
define void @crlf_to_lf(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 2
br i1 %8, label %9, label %38
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 13
br i1 %17, label %18, label %38
18: ; preds = %9
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %38
27: ; preds = %18
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 10, i8* %32
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %27, %18, %9, %3
%39 = load i8*, i8** %4
%40 = load i32*, i32** %6
%41 = call i32 @fputs(i8* %39, i32* %40)
ret void
}

LLVM IR (-O2):
define void @crlf_to_lf(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = add nsw i32 %1, -2
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 13
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = add nsw i32 %1, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %11
store i8 10, i8* %8
store i8 0, i8* %14
br label %18
18: ; preds = %17, %11, %5, %3
%19 = tail call i32 @fputs(i8* %0, i32* %2)
ret void
}