#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 const);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
char *stripspace(const char *src) {
  static char buff[512];
  if (src) {
    char *dst;
    while (*src && isspace(*src))
      src++;
    strcpy(buff, src);
    dst = buff + strlen(buff);
    while (dst >= buff && isspace(*--dst))
      *dst = '\0';
    return buff;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<stripspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1229 <stripspace+0xf9>
jmp    114c <stripspace+0x1c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1177 <stripspace+0x47>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1187 <stripspace+0x57>
jmp    1198 <stripspace+0x68>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <stripspace+0x1c>
mov    -0x10(%rbp),%rsi
lea    0x2ead(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ea1(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2e92(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
lea    0x2e82(%rip),%rcx
cmp    %rcx,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
jb     11fd <stripspace+0xcd>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movsbl -0x1(%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    120d <stripspace+0xdd>
jmp    1219 <stripspace+0xe9>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c5 <stripspace+0x95>
lea    0x2e30(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1231 <stripspace+0x101>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripspace>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11bd <stripspace+0x8d>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1169 <stripspace+0x39>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     1169 <stripspace+0x39>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <stripspace+0x20>
lea    0x2ee0(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     11c0 <stripspace+0x90>
mov    %eax,%ebx
lea    0x2ec0(%rip),%r14
add    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl -0x1(%rbx),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     11c0 <stripspace+0x90>
movb   $0x0,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    11a0 <stripspace+0x70>
jmp    11c0 <stripspace+0x90>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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