#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*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *ptReplaceStr(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int chopStr(char *s) {
  if (!s) {
    errno = EINVAL;
    return -1;
  }
  char *t = ptReplaceStr(s, "\n", "");
  if (!t) {
    return -1;
  }
  char *t2 = ptReplaceStr(t, "\r", "");
  if (!t2) {
    free(t);
    return -1;
  }
  strcpy(s, t2);
  free(t2);
  free(t);
  return 0;
}


x86 assembly (clang, -O0):
<chopStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <chopStr+0x35>
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e89(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <chopStr+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
lea    0xe8a(%rip),%rdx
call   1050 <ptReplaceStr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <chopStr+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <chopStr+0xc8>
mov    -0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    0xe58(%rip),%rdx
call   1050 <ptReplaceStr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <chopStr+0xa2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <chopStr+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chopStr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     119c <chopStr+0x6c>
mov    %rdi,%rbx
lea    0xeba(%rip),%rsi
lea    0xeb4(%rip),%rdx
call   1050 <ptReplaceStr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11bd <chopStr+0x8d>
mov    %rax,%r14
lea    0xe9c(%rip),%rsi
lea    0xe94(%rip),%rdx
mov    %rax,%rdi
call   1050 <ptReplaceStr@plt>
test   %rax,%rax
je     11b5 <chopStr+0x85>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    11bd <chopStr+0x8d>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    0x2e34(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
jmp    11bd <chopStr+0x8d>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0D\00"
define i32 @chopStr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
store i32 -1, i32* %2
br label %32
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @ptReplaceStr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i32 -1, i32* %2
br label %32
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = call i8* @ptReplaceStr(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
store i32 -1, i32* %2
br label %32
24: ; preds = %16
%25 = load i8*, i8** %3
%26 = load i8*, i8** %5
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
store i32 0, i32* %2
br label %32
32: ; preds = %24, %21, %15, %8
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0D\00"
define i32 @chopStr(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load i32, i32* @EINVAL
store i32 %4, i32* @errno
br label %17
5: ; preds = %1
%6 = tail call i8* @ptReplaceStr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i8* @ptReplaceStr(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @free(i8* %6)
br label %17
13: ; preds = %8
%14 = tail call i32 @strcpy(i8* %0, i8* %9)
%15 = tail call i32 @free(i8* %9)
%16 = tail call i32 @free(i8* %6)
br label %17
17: ; preds = %5, %13, %11, %3
%18 = phi i32 [ -1, %3 ], [ -1, %5 ], [ 0, %13 ], [ -1, %11 ]
ret i32 %18
}