#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 */
int strlen(char *);
char *mvcp_util_chomp(char *input) {
  if (input != NULL) {
    int length = strlen(input);
    if (length && input[length - 1] == '\n')
      input[length - 1] = '\0';
    if (length > 1 && input[length - 2] == '\r')
      input[length - 2] = '\0';
  }
  return input;
}


x86 assembly (clang, -O0):
<mvcp_util_chomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a2 <mvcp_util_chomp+0x92>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1168 <mvcp_util_chomp+0x58>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1168 <mvcp_util_chomp+0x58>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x1,-0xc(%rbp)
jle    119d <mvcp_util_chomp+0x8d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    119d <mvcp_util_chomp+0x8d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a2 <mvcp_util_chomp+0x92>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvcp_util_chomp>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1146 <mvcp_util_chomp+0x36>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1146 <mvcp_util_chomp+0x36>
movslq %eax,%rcx
cmpb   $0xa,-0x1(%rcx,%rbx,1)
jne    1134 <mvcp_util_chomp+0x24>
movb   $0x0,-0x1(%rbx,%rcx,1)
cmp    $0x2,%eax
jl     1146 <mvcp_util_chomp+0x36>
add    $0xfffffffe,%eax
cmpb   $0xd,(%rbx,%rax,1)
jne    1146 <mvcp_util_chomp+0x36>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

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

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