#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 */
int /*<<< orphan*/ isWhite(unsigned char const);
scalar_t__ malloc(unsigned int);
unsigned char *stringCleanse(const unsigned char *inbuf, unsigned inlen,
                             unsigned *outlen) {
  unsigned char *news;
  unsigned newsDex;
  unsigned i;
  news = (unsigned char *)malloc(inlen);
  newsDex = 0;
  for (i = 0; i < inlen; i++) {
    if (!isWhite(inbuf[i])) {
      news[newsDex++] = inbuf[i];
    }
  }
  *outlen = newsDex;
  return news;
}


x86 assembly (clang, -O0):
<stringCleanse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a3 <stringCleanse+0x83>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
movzbl (%rax,%rcx,1),%edi
call   1040 <isWhite@plt>
cmp    $0x0,%eax
jne    1190 <stringCleanse+0x70>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1195 <stringCleanse+0x75>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114d <stringCleanse+0x2d>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringCleanse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     1177 <stringCleanse+0x57>
mov    %ebp,%r12d
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    1159 <stringCleanse+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     117a <stringCleanse+0x5a>
movzbl (%rbx,%rbp,1),%edi
call   1040 <isWhite@plt>
test   %eax,%eax
jne    1150 <stringCleanse+0x30>
movzbl (%rbx,%rbp,1),%eax
mov    %r13d,%ecx
add    $0x1,%r13d
mov    %al,(%r15,%rcx,1)
jmp    1150 <stringCleanse+0x30>
xor    %r13d,%r13d
mov    %r13d,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @stringCleanse(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i32, i32* %5
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %37, %3
%14 = load i32, i32* %9
%15 = load i32, i32* %5
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i32, i32* %9
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @isWhite(i8 zeroext %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i32, i32* %9
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = add i32 %32, 1
store i32 %33, i32* %8
%34 = zext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 %30, i8* %35
br label %36
36: ; preds = %25, %17
br label %37
37: ; preds = %36
%38 = load i32, i32* %9
%39 = add i32 %38, 1
store i32 %39, i32* %9
br label %13
40: ; preds = %13
%41 = load i32, i32* %8
%42 = load i32*, i32** %6
store i32 %41, i32* %42
%43 = load i8*, i8** %7
ret i8* %43
}

LLVM IR (-O2):
define i8* @stringCleanse(i8* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @malloc(i32 %1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i32 %1, 0
br i1 %6, label %25, label %7
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %21
%10 = phi i64 [ 0, %7 ], [ %23, %21 ]
%11 = phi i32 [ 0, %7 ], [ %22, %21 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = tail call i32 @isWhite(i8 zeroext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i8, i8* %12
%18 = add i32 %11, 1
%19 = zext i32 %11 to i64
%20 = getelementptr inbounds i8, i8* %5, i64 %19
store i8 %17, i8* %20
br label %21
21: ; preds = %9, %16
%22 = phi i32 [ %11, %9 ], [ %18, %16 ]
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %9
25: ; preds = %21, %3
%26 = phi i32 [ 0, %3 ], [ %22, %21 ]
store i32 %26, i32* %2
ret i8* %5
}