#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 mychomp(char *s) {
  int k = strlen(s);
  if ((k > 0) && (*(s + k - 1) == '\n'))
    *(s + k - 1) = '\0';
  if ((k > 1) && (*(s + k - 2) == '\r'))
    *(s + k - 2) = '\0';
}


x86 assembly (clang, -O0):
<mychomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1155 <mychomp+0x45>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1155 <mychomp+0x45>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
cmpl   $0x1,-0xc(%rbp)
jle    1182 <mychomp+0x72>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl -0x2(%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1182 <mychomp+0x72>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,-0x2(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mychomp>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    113c <mychomp+0x2c>
mov    %eax,%ecx
cmpb   $0xa,-0x1(%rbx,%rcx,1)
jne    112b <mychomp+0x1b>
movb   $0x0,-0x1(%rbx,%rcx,1)
cmp    $0x2,%eax
jb     113c <mychomp+0x2c>
cmpb   $0xd,-0x2(%rbx,%rcx,1)
jne    113c <mychomp+0x2c>
movb   $0x0,-0x2(%rbx,%rcx,1)
pop    %rbx
ret

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

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