#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__ strlen(char *);
scalar_t__ strspn(char *, char *);
char *strtrim(char *str, char *ws) {
  char *s = str;
  str += strspn(str, ws);
  while (*str != '\0' && strspn(str, ws) != strlen(str))
    *(s++) = *(str++);
  *s = '\0';
  return (str);
}


x86 assembly (clang, -O0):
<strtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strspn@plt>
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     118c <strtrim+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119c <strtrim+0x7c>
jmp    11c3 <strtrim+0xa3>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    114d <strtrim+0x2d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtrim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strspn@plt>
mov    %rax,%r15
mov    (%r12,%rax,1),%bpl
test   %bpl,%bpl
je     1191 <strtrim+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r12,%r15,1),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strspn@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r13
je     1197 <strtrim+0x77>
lea    0x1(%r12),%rax
mov    %bpl,(%r12)
movzbl 0x1(%r12,%r15,1),%ebp
mov    %rax,%r12
test   %bpl,%bpl
jne    1150 <strtrim+0x30>
add    %rax,%r15
mov    %r15,%rbx
mov    %rax,%r12
jmp    1197 <strtrim+0x77>
add    %r12,%r15
mov    %r15,%rbx
movb   $0x0,(%r12)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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