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


x86 assembly (clang, -O0):
<strstrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     117a <strstrip+0x3a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118a <strstrip+0x4a>
jmp    119b <strstrip+0x5b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114c <strstrip+0xc>
lea    0x2eae(%rip),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0x2e97(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e8b(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2e7c(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
lea    0x2e6e(%rip),%rax
cmp    %rax,-0x10(%rbp)
jbe    1219 <strstrip+0xd9>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
jne    1208 <strstrip+0xc8>
jmp    1219 <strstrip+0xd9>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11db <strstrip+0x9b>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e29(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrip>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
nopl   0x0(%rax,%rax,1)
call   1060 <isspace@plt>
test   %rax,%rax
je     1169 <strstrip+0x29>
cmpb   $0x0,(%rbx)
je     1169 <strstrip+0x29>
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
jmp    1150 <strstrip+0x10>
lea    0x2ee0(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%r15
add    %r14,%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rbx
cmp    %r14,%r15
jbe    11ba <strstrip+0x7a>
lea    -0x1(%rbx),%r15
movsbl -0x1(%rbx),%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    11a0 <strstrip+0x60>
movb   $0x0,(%rbx)
lea    0x2e8c(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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