#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 */
scalar_t__ isspace(char);
int strlen(char *);
char *snip(char *string) {
  int i;
  string[12] = '\0';
  while (((i = strlen(string)) > 0) &&
         (isspace(string[i - 1]) || (string[i - 1] == '\n') ||
          (string[i - 1] == '\r'))) {
    string[i - 1] = '\0';
  }
  return string;
}


x86 assembly (clang, -O0):
<snip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0xc(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jle    11b7 <snip+0x97>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xe(%rbp)
jne    11b1 <snip+0x91>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xe(%rbp)
je     11b1 <snip+0x91>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11c7 <snip+0xa7>
jmp    11dd <snip+0xbd>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1134 <snip+0x14>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movb   $0x0,0xc(%rdi)
call   1030 <strlen@plt>
test   %eax,%eax
jle    1172 <snip+0x52>
mov    %eax,%ebx
jmp    1153 <snip+0x33>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1172 <snip+0x52>
add    $0xffffffff,%ebx
movsbl (%r14,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <snip+0x20>
movzbl (%r14,%rbx,1),%eax
cmp    $0xd,%al
je     1140 <snip+0x20>
cmp    $0xa,%al
je     1140 <snip+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @snip(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 12
store i8 0, i8* %5
br label %6
6: ; preds = %41, %1
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = call i64 @isspace(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %10
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %37, label %28
28: ; preds = %19
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 13
br label %37
37: ; preds = %28, %19, %10
%38 = phi i1 [ true, %19 ], [ true, %10 ], [ %36, %28 ]
br label %39
39: ; preds = %37, %6
%40 = phi i1 [ false, %6 ], [ %38, %37 ]
br i1 %40, label %41, label %47
41: ; preds = %39
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
br label %6
47: ; preds = %39
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
define i8* @snip(i8* returned %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 12
store i8 0, i8* %2
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1, %15
%6 = phi i32 [ %16, %15 ], [ %3, %1 ]
%7 = add nsw i32 %6, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @isspace(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = load i8, i8* %9
switch i8 %14, label %18 [
i8 10, label %15
i8 13, label %15
]
15: ; preds = %13, %13, %5
store i8 0, i8* %9
%16 = tail call i32 @strlen(i8* %0)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %15, %13, %1
ret i8* %0
}