#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 /*<<< orphan*/ bzero(char *, size_t);
scalar_t__ calloc(int, size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ str_replace_char(char *, char *, char, char);
int /*<<< orphan*/ str_trim_doubles(char *, char *, char);
size_t strlen(char *);
void res_clear(char *dst, char *src) {
  size_t ln;
  char *tmp;
  ln = strlen(src);
  bzero(dst, ln);
  tmp = (char *)calloc(sizeof(char), ln + 1);
  str_replace_char(tmp, src, '\r', '\n');
  str_trim_doubles(dst, tmp, '\n');
  free(tmp);
}


x86 assembly (clang, -O0):
<res_clear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <bzero@plt>
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
call   1070 <str_replace_char@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <str_trim_doubles@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<res_clear>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1080 <bzero@plt>
add    $0x1,%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xd,%edx
mov    $0xa,%ecx
call   1070 <str_replace_char@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1050 <str_trim_doubles@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @res_clear(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
%9 = load i8*, i8** %3
%10 = load i64, i64* %5
%11 = call i32 @bzero(i8* %9, i64 %10)
%12 = load i64, i64* %5
%13 = add i64 %12, 1
%14 = call i64 @calloc(i32 1, i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8*, i8** %4
%18 = call i32 @str_replace_char(i8* %16, i8* %17, i8 signext 13, i8 signext 10)
%19 = load i8*, i8** %3
%20 = load i8*, i8** %6
%21 = call i32 @str_trim_doubles(i8* %19, i8* %20, i8 signext 10)
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
ret void
}

LLVM IR (-O2):
define void @res_clear(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i32 @bzero(i8* %0, i64 %3)
%5 = add i64 %3, 1
%6 = tail call i64 @calloc(i32 1, i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @str_replace_char(i8* %7, i8* %1, i8 signext 13, i8 signext 10)
%9 = tail call i32 @str_trim_doubles(i8* %0, i8* %7, i8 signext 10)
%10 = tail call i32 @free(i8* %7)
ret void
}