#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 */
char *malloc(scalar_t__);
scalar_t__ strlen(char const *);
char *strip_copy(const char *s) {
  char *p = malloc(strlen(s) + 1);
  if (p) {
    char *p2 = p;
    while (*s != '\0') {
      if (*s != '\r' && *s != '\n') {
        *p2++ = *s++;
      } else {
        ++s;
      }
    }
    *p2 = '\0';
  }
  return p;
}


x86 assembly (clang, -O0):
<strip_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c7 <strip_copy+0xa7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c0 <strip_copy+0xa0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     11af <strip_copy+0x8f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11af <strip_copy+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11bb <strip_copy+0x9b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1158 <strip_copy+0x38>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_copy>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1160 <strip_copy+0x40>
mov    %rax,%rcx
jmp    1144 <strip_copy+0x24>
nopl   0x0(%rax)
add    $0x1,%rbx
movzbl (%rbx),%edx
cmp    $0xa,%dl
je     1140 <strip_copy+0x20>
cmp    $0xd,%dl
je     1140 <strip_copy+0x20>
test   %dl,%dl
je     115d <strip_copy+0x3d>
mov    %dl,(%rcx)
add    $0x1,%rcx
jmp    1140 <strip_copy+0x20>
movb   $0x0,(%rcx)
pop    %rbx
ret

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

LLVM IR (-O2):
define noalias i8* @strip_copy(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %1, %12
%7 = phi i8* [ %14, %12 ], [ %0, %1 ]
%8 = phi i8* [ %13, %12 ], [ %4, %1 ]
%9 = load i8, i8* %7
switch i8 %9, label %10 [
i8 0, label %15
i8 13, label %12
i8 10, label %12
]
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %9, i8* %8
br label %12
12: ; preds = %6, %6, %10
%13 = phi i8* [ %11, %10 ], [ %8, %6 ], [ %8, %6 ]
%14 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
15: ; preds = %6
store i8 0, i8* %8
br label %16
16: ; preds = %15, %1
ret i8* %4
}