#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 mfm_cut_1310(char *str) {
  int l = strlen(str);
  for (int i = l - 1; i >= l - 2; i--) {
    if (str[i] == '\n' || str[i] == '\r') {
      str[i] = '\0';
    }
  }
}


x86 assembly (clang, -O0):
<mfm_cut_1310>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jl     118b <mfm_cut_1310+0x7b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     116c <mfm_cut_1310+0x5c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1178 <mfm_cut_1310+0x68>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    117d <mfm_cut_1310+0x6d>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <mfm_cut_1310+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfm_cut_1310>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
mov    -0x1(%rax,%rbx,1),%cl
cmp    $0xd,%cl
je     1129 <mfm_cut_1310+0x19>
cmp    $0xa,%cl
jne    112e <mfm_cut_1310+0x1e>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    -0x2(%rax,%rbx,1),%cl
cmp    $0xd,%cl
je     113c <mfm_cut_1310+0x2c>
cmp    $0xa,%cl
jne    1141 <mfm_cut_1310+0x31>
movb   $0x0,-0x2(%rbx,%rax,1)
pop    %rbx
ret

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

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