#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*/ isspace(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strcrop(char *s, char *l) {
  char *last;
  if ((s == NULL) || (l == NULL))
    return NULL;
  memset(l, 0, 1024 + 1);
  strncpy(l, s, 1024 + 1);
  l[1024] = '\0';
  last = l + strlen(l);
  while (last > l) {
    if (!isspace((int)*(last - 1)))
      break;
    last--;
  }
  *last = (char)0;
  return l;
}


x86 assembly (clang, -O0):
<strcrop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <strcrop+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <strcrop+0x33>
movq   $0x0,-0x8(%rbp)
jmp    120a <strcrop+0xca>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x401,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x400(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11fb <strcrop+0xbb>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%eax
jne    11ea <strcrop+0xaa>
jmp    11fb <strcrop+0xbb>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11c1 <strcrop+0x81>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcrop>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
test   %rdi,%rdi
je     11af <strcrop+0x6f>
mov    %rsi,%r15
test   %rsi,%rsi
je     11af <strcrop+0x6f>
mov    %rdi,%r14
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x401,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x400(%r15)
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
add    %r15,%r14
nopl   0x0(%rax)
mov    %r14,%rbx
cmp    %r15,%r14
jbe    11a9 <strcrop+0x69>
lea    -0x1(%rbx),%r14
movsbl -0x1(%rbx),%edi
call   1060 <isspace@plt>
test   %eax,%eax
jne    1190 <strcrop+0x50>
movb   $0x0,(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strcrop(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = tail call i32 @memset(i8* %1, i32 0, i32 1025)
%8 = tail call i32 @strncpy(i8* %1, i8* %0, i32 1025)
%9 = getelementptr inbounds i8, i8* %1, i64 1024
store i8 0, i8* %9
%10 = tail call i32 @strlen(i8* %1)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 %11
br label %13
13: ; preds = %16, %6
%14 = phi i8* [ %12, %6 ], [ %17, %16 ]
%15 = icmp ugt i8* %14, %1
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 -1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = tail call i32 @isspace(i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %16, %13
store i8 0, i8* %14
br label %23
23: ; preds = %2, %22
%24 = phi i8* [ %1, %22 ], [ null, %2 ]
ret i8* %24
}