#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 *);
void chomp(char *str) {
  int modified;
  do {
    const int len = strlen(str);
    modified = 0;
    if (len > 0) {
      char *cp = str + (len - 1);
      if (*cp == '\n' || *cp == '\r') {
        *cp = '\0';
        modified = 1;
      }
    }
  } while (modified);
}


x86 assembly (clang, -O0):
<chomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1180 <chomp+0x70>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     116d <chomp+0x5d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    117b <chomp+0x6b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0xc(%rbp)
jmp    1180 <chomp+0x70>
jmp    1185 <chomp+0x75>
cmpl   $0x0,-0xc(%rbp)
jne    111c <chomp+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chomp>:
push   %rbx
mov    %rdi,%rbx
jmp    1127 <chomp+0x17>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1141 <chomp+0x31>
add    $0xffffffff,%eax
movzbl (%rbx,%rax,1),%ecx
cmp    $0xd,%cl
je     1120 <chomp+0x10>
cmp    $0xa,%cl
je     1120 <chomp+0x10>
pop    %rbx
ret

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

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