#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__ isprint(char);
scalar_t__ isspace(char);
char *clean_string(char *s0) {
  char *s = s0;
  char *ptr;
  while (isspace(*s))
    s++;
  ptr = s;
  while (isprint(*ptr))
    ptr++;
  *ptr = 0;
  return s;
}


x86 assembly (clang, -O0):
<clean_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     115b <clean_string+0x3b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <clean_string+0x14>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     118a <clean_string+0x6a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1163 <clean_string+0x43>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0xffffffffffffffff,%r14
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%r14),%edi
add    $0x1,%r14
call   1030 <isspace@plt>
test   %rax,%rax
jne    1130 <clean_string+0x10>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isprint@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <clean_string+0x30>
movb   $0x0,-0x1(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @clean_string(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 signext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2, %8
%9 = phi i8* [ %13, %8 ], [ %3, %2 ]
%10 = load i8, i8* %9
%11 = tail call i64 @isprint(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %12, label %14, label %8
14: ; preds = %8
store i8 0, i8* %9
ret i8* %3
}