#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 */
scalar_t__ strchr(char *, char);
int strlen(char *);
char *cut_crlf(char *st) {
  while (*st && strchr("\r\n", st[strlen(st) - 1]))
    st[strlen(st) - 1] = 0;
  return st;
}


x86 assembly (clang, -O0):
<cut_crlf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
je     1178 <cut_crlf+0x58>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe9b(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1188 <cut_crlf+0x68>
jmp    11ae <cut_crlf+0x8e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    112c <cut_crlf+0xc>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_crlf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1170 <cut_crlf+0x50>
lea    0xecd(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <cut_crlf+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
cmpb   $0x0,(%rbx)
jne    1140 <cut_crlf+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
define i8* @cut_crlf(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %20, %1
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %8, %3
%19 = phi i1 [ false, %3 ], [ %17, %8 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i8*, i8** %2
%22 = load i8*, i8** %2
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
store i8 0, i8* %26
br label %3
27: ; preds = %18
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i8* @cut_crlf(i8* returned %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %12
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %4
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %4, %12, %1
ret i8* %0
}