#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);
char *str_trim_cpy(char *dst, char *src) {
  char *top;
  char *last;
  top = dst;
  while (isspace(*src))
    src++;
  last = dst;
  while ((*dst = *src)) {
    dst++;
    if (!isspace(*src))
      last = dst;
    src++;
  }
  *last = '\0';
  return top;
}


x86 assembly (clang, -O0):
<str_trim_cpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     114f <str_trim_cpy+0x3f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1128 <str_trim_cpy+0x18>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     11a6 <str_trim_cpy+0x96>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
jne    1195 <str_trim_cpy+0x85>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1157 <str_trim_cpy+0x47>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_trim_cpy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%r13),%edi
call   1030 <isspace@plt>
add    $0x1,%r13
test   %rax,%rax
jne    1130 <str_trim_cpy+0x20>
mov    -0x1(%r13),%al
mov    %al,(%r14)
mov    %r14,%r15
test   %al,%al
je     1189 <str_trim_cpy+0x79>
lea    0x1(%r14),%r12
xor    %ebx,%ebx
mov    %r14,%r15
nopw   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rbp
movsbl -0x1(%r13,%rbx,1),%edi
call   1030 <isspace@plt>
test   %rax,%rax
cmove  %rbp,%r15
movzbl 0x0(%r13,%rbx,1),%eax
mov    %al,0x1(%r14,%rbx,1)
add    $0x1,%rbx
test   %al,%al
jne    1160 <str_trim_cpy+0x50>
movb   $0x0,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_trim_cpy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
br label %8
8: ; preds = %13, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = call i64 @isspace(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %8
16: ; preds = %8
%17 = load i8*, i8** %3
store i8* %17, i8** %6
br label %18
18: ; preds = %32, %16
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = load i8*, i8** %3
store i8 %20, i8* %21
%22 = icmp ne i8 %20, 0
br i1 %22, label %23, label %35
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = call i64 @isspace(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = load i8*, i8** %3
store i8* %31, i8** %6
br label %32
32: ; preds = %30, %23
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
br label %18
35: ; preds = %18
%36 = load i8*, i8** %6
store i8 0, i8* %36
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
define i8* @str_trim_cpy(i8* returned writeonly %0, i8* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %1, %2 ], [ %8, %3 ]
%5 = load i8, i8* %4
%6 = tail call i64 @isspace(i8 signext %5)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = load i8, i8* %4
store i8 %10, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %9, %12
%13 = phi i8* [ %20, %12 ], [ %0, %9 ]
%14 = phi i8* [ %16, %12 ], [ %0, %9 ]
%15 = phi i8* [ %21, %12 ], [ %4, %9 ]
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = load i8, i8* %15
%18 = tail call i64 @isspace(i8 signext %17)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i8* %16, i8* %13
%21 = getelementptr inbounds i8, i8* %15, i64 1
%22 = load i8, i8* %21
store i8 %22, i8* %16
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %12, %9
%25 = phi i8* [ %0, %9 ], [ %20, %12 ]
store i8 0, i8* %25
ret i8* %0
}