#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 *chomp(char *src) {
  char *plast = src + strlen(src) - 1;
  while (*plast == '\n' || *plast == '\r') {
    *plast-- = '\0';
    if (plast == src) {
      break;
    }
  }
  return src;
}


x86 assembly (clang, -O0):
<chomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     1166 <chomp+0x56>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1176 <chomp+0x66>
jmp    11a0 <chomp+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    119b <chomp+0x8b>
jmp    11a0 <chomp+0x90>
jmp    1141 <chomp+0x31>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chomp>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    $0xffffffffffffffff,%rax
jmp    113a <chomp+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
je     1148 <chomp+0x38>
movzbl (%rbx,%rax,1),%ecx
cmp    $0xd,%cl
je     1130 <chomp+0x20>
cmp    $0xa,%cl
je     1130 <chomp+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @chomp(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
br label %10
10: ; preds = %29, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 13
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ true, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %30
22: ; preds = %20
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %3
store i8 0, i8* %23
%25 = load i8*, i8** %3
%26 = load i8*, i8** %2
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
br label %30
29: ; preds = %22
br label %10
30: ; preds = %28, %20
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
define i8* @chomp(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
br label %6
6: ; preds = %9, %1
%7 = phi i8* [ %5, %1 ], [ %10, %9 ]
%8 = load i8, i8* %7
switch i8 %8, label %12 [
i8 10, label %9
i8 13, label %9
]
9: ; preds = %6, %6
%10 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 0, i8* %7
%11 = icmp eq i8* %10, %0
br i1 %11, label %12, label %6
12: ; preds = %6, %9
ret i8* %0
}