#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 *strdup(char const *);
int strlen(char *);
char *trim(const char *in_string) {
  char *string = strdup(in_string);
  int i;
  for (i = strlen(string) - 1; i >= 0; --i) {
    if ('\n' == string[i] || '\r' == string[i])
      string[i] = 0;
  }
  return string;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11a3 <trim+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
je     1184 <trim+0x64>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xd,%eax
cmp    %ecx,%eax
jne    1190 <trim+0x70>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1195 <trim+0x75>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <trim+0x28>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbx
call   1040 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1158 <trim+0x38>
mov    %eax,%ecx
test   $0x1,%cl
je     1153 <trim+0x33>
add    $0xffffffffffffffff,%rcx
mov    %ecx,%esi
mov    (%rbx,%rsi,1),%dl
cmp    $0xd,%dl
je     114f <trim+0x2f>
cmp    $0xa,%dl
jne    1153 <trim+0x33>
movb   $0x0,(%rbx,%rsi,1)
cmp    $0x1,%eax
jne    115d <trim+0x3d>
mov    %rbx,%rax
pop    %rbx
ret
add    $0xfffffffffffffffe,%rcx
jmp    1185 <trim+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,(%rbx,%rax,1)
lea    -0x2(%rcx),%rax
add    $0x1,%rcx
cmp    $0x1,%rcx
mov    %rax,%rcx
jbe    1158 <trim+0x38>
lea    0x1(%rcx),%eax
movzbl (%rbx,%rax,1),%edx
cmp    $0xd,%dl
je     1196 <trim+0x76>
cmp    $0xa,%dl
jne    119a <trim+0x7a>
movb   $0x0,(%rbx,%rax,1)
mov    %ecx,%eax
movzbl (%rbx,%rax,1),%edx
cmp    $0xd,%dl
je     1170 <trim+0x50>
cmp    $0xa,%dl
je     1170 <trim+0x50>
jmp    1174 <trim+0x54>

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

LLVM IR (-O2):
define i8* @trim(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %33
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = add nsw i64 %6, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %15 [
i8 10, label %14
i8 13, label %14
]
14: ; preds = %9, %9
store i8 0, i8* %12
br label %15
15: ; preds = %9, %14, %5
%16 = phi i64 [ %6, %5 ], [ %10, %14 ], [ %10, %9 ]
%17 = icmp eq i32 %3, 1
br i1 %17, label %33, label %18
18: ; preds = %15, %31
%19 = phi i64 [ %26, %31 ], [ %16, %15 ]
%20 = add nsw i64 %19, -1
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds i8, i8* %2, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %25 [
i8 10, label %24
i8 13, label %24
]
24: ; preds = %18, %18
store i8 0, i8* %22
br label %25
25: ; preds = %18, %24
%26 = add nsw i64 %19, -2
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds i8, i8* %2, i64 %27
%29 = load i8, i8* %28
switch i8 %29, label %31 [
i8 10, label %30
i8 13, label %30
]
30: ; preds = %25, %25
store i8 0, i8* %28
br label %31
31: ; preds = %30, %25
%32 = icmp ugt i64 %20, 1
br i1 %32, label %18, label %33
33: ; preds = %15, %31, %1
ret i8* %2
}