#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 */
size_t strlen(char *);
void castus4public_chomp(char *s) {
  char *orig_s = s;
  size_t l = strlen(s);
  if (l == 0)
    return;
  s += l - 1;
  while (s > orig_s && (*s == '\n' || *s == '\r'))
    *s-- = 0;
}


x86 assembly (clang, -O0):
<castus4public_chomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1141 <castus4public_chomp+0x31>
jmp    11b6 <castus4public_chomp+0xa6>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    118f <castus4public_chomp+0x7f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     1189 <castus4public_chomp+0x79>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119f <castus4public_chomp+0x8f>
jmp    11b6 <castus4public_chomp+0xa6>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
jmp    1151 <castus4public_chomp+0x41>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<castus4public_chomp>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    -0x2(%rax),%rcx
movabs $0x7ffffffffffffffe,%rdx
ff ff 7f
cmp    %rdx,%rcx
ja     1159 <castus4public_chomp+0x49>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    114c <castus4public_chomp+0x3c>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    1159 <castus4public_chomp+0x49>
movzbl (%rax),%ecx
cmp    $0xd,%cl
je     1140 <castus4public_chomp+0x30>
cmp    $0xa,%cl
je     1140 <castus4public_chomp+0x30>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @castus4public_chomp(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, -2
%4 = icmp ult i64 %3, 9223372036854775807
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = add i64 %2, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
br label %8
8: ; preds = %5, %11
%9 = phi i8* [ %12, %11 ], [ %7, %5 ]
%10 = load i8, i8* %9
switch i8 %10, label %14 [
i8 10, label %11
i8 13, label %11
]
11: ; preds = %8, %8
%12 = getelementptr inbounds i8, i8* %9, i64 -1
store i8 0, i8* %9
%13 = icmp ugt i8* %12, %0
br i1 %13, label %8, label %14
14: ; preds = %8, %11, %1
ret void
}