#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 */
size_t strlen(unsigned char const *);
int /*<<< orphan*/ swerr(char *, int, char *, char *);
unsigned char *xmalloc(size_t);
unsigned char *dos2unix_str(const unsigned char *s) {
  unsigned char *out, *pout;
  const unsigned char *pin;
  size_t len;
  do {
    if (!(s))
      swerr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/"
            "master/dos2unix_str.c",
            33, "assertion failed: %s", "s");
  } while (0);
  len = strlen(s);
  out = xmalloc(len + 1);
  for (pout = out, pin = s; *pin; pin++)
    if (*pin != '\r')
      *pout++ = *pin;
  *pout = 0;
  return out;
}


x86 assembly (clang, -O0):
<dos2unix_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1166 <dos2unix_str+0x36>
lea    0xeb2(%rip),%rdi
mov    $0x21,%esi
lea    0xf3c(%rip),%rdx
lea    0xf48(%rip),%rcx
call   1050 <swerr@plt>
jmp    116b <dos2unix_str+0x3b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e3 <dos2unix_str+0xb3>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xd,%eax
je     11cd <dos2unix_str+0x9d>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11d2 <dos2unix_str+0xa2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <dos2unix_str+0x69>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos2unix_str>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1158 <dos2unix_str+0x28>
lea    0xec0(%rip),%rdi
lea    0xf4f(%rip),%rdx
lea    0xf5b(%rip),%rcx
mov    $0x21,%esi
call   1050 <swerr@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <xmalloc@plt>
mov    %rax,%rcx
jmp    117a <dos2unix_str+0x4a>
xchg   %ax,%ax
mov    %dl,(%rcx)
add    $0x1,%rcx
add    $0x1,%rbx
movzbl (%rbx),%edx
cmp    $0xd,%dl
je     1176 <dos2unix_str+0x46>
test   %dl,%dl
jne    1170 <dos2unix_str+0x40>
movb   $0x0,(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/master/dos2unix_str.c\00"
@.str.1 = [21 x i8] c"assertion failed: %s\00"
@.str.2 = [2 x i8] c"s\00"
define i8* @dos2unix_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
br label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @swerr(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
br label %13
13: ; preds = %12
%14 = load i8*, i8** %2
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = add i64 %16, 1
%18 = call i8* @xmalloc(i64 %17)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
store i8* %19, i8** %4
%20 = load i8*, i8** %2
store i8* %20, i8** %5
br label %21
21: ; preds = %36, %13
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %28, 13
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
store i8 %32, i8* %33
br label %35
35: ; preds = %30, %25
br label %36
36: ; preds = %35
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
br label %21
39: ; preds = %21
%40 = load i8*, i8** %4
store i8 0, i8* %40
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@.str = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/master/dos2unix_str.c\00"
@.str.1 = [21 x i8] c"assertion failed: %s\00"
@.str.2 = [2 x i8] c"s\00"
define i8* @dos2unix_str(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @swerr(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %3, %1
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add i64 %6, 1
%8 = tail call i8* @xmalloc(i64 %7)
br label %9
9: ; preds = %15, %5
%10 = phi i8* [ %0, %5 ], [ %17, %15 ]
%11 = phi i8* [ %8, %5 ], [ %16, %15 ]
%12 = load i8, i8* %10
switch i8 %12, label %13 [
i8 0, label %18
i8 13, label %15
]
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %12, i8* %11
br label %15
15: ; preds = %9, %13
%16 = phi i8* [ %14, %13 ], [ %11, %9 ]
%17 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
18: ; preds = %9
store i8 0, i8* %11
ret i8* %8
}