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


x86 assembly (clang, -O0):
<strcrop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <strcrop+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <strcrop+0xb3>
lea    0x2ee5(%rip),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rsi
lea    0x2ece(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ec2(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2eb3(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    0x2ea5(%rip),%rax
cmp    %rax,-0x18(%rbp)
jbe    11e1 <strcrop+0xa1>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%eax
jne    11d0 <strcrop+0x90>
jmp    11e1 <strcrop+0xa1>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a4 <strcrop+0x64>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e61(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcrop>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     119e <strcrop+0x5e>
mov    %rdi,%r14
lea    0x2efc(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
add    %r15,%r14
nopl   0x0(%rax)
mov    %r14,%rbx
cmp    %r15,%r14
jbe    1199 <strcrop+0x59>
lea    -0x1(%rbx),%r14
movsbl -0x1(%rbx),%edi
call   1060 <isspace@plt>
test   %eax,%eax
jne    1180 <strcrop+0x40>
movb   $0x0,(%rbx)
jmp    11a1 <strcrop+0x61>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@strcrop.l = internal global [1025 x i8] zeroinitializer
define i8* @strcrop(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %30
8: ; preds = %1
%9 = call i32 @memset(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0), i32 0, i32 1025)
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0), i8* %10)
%12 = call i32 @strlen(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0), i64 %13
store i8* %14, i8** %4
br label %15
15: ; preds = %25, %8
%16 = load i8*, i8** %4
%17 = icmp ugt i8* %16, getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0)
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = load i8, i8* %20
%22 = call i32 @isspace(i8 signext %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %18
br label %28
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %4
br label %15
28: ; preds = %24, %15
%29 = load i8*, i8** %4
store i8 0, i8* %29
store i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @strcrop.l, i64 0, i64 0), i8** %2
br label %30
30: ; preds = %28, %7
%31 = load i8*, i8** %2
ret i8* %31
}

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