#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 */
typedef int /*<<< orphan*/ temp;

/* Variables and functions */
int /*<<< orphan*/ isspace(char);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *trimall(char *s) {
  char *temp = malloc(255);
  memset(temp, 0, sizeof(temp));
  int i = 0, j = 0;
  char c;
  while ((c = *(s + i)) != 0) {
    if (!isspace(c)) {
      *(temp + j) = c;
      j++;
    }
    i++;
  }
  return temp;
}


x86 assembly (clang, -O0):
<trimall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11b9 <trimall+0x89>
movsbl -0x19(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11ab <trimall+0x7b>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <trimall+0x38>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimall>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    (%r12),%bl
test   %bl,%bl
je     1196 <trimall+0x66>
add    $0x1,%r12
jmp    117d <trimall+0x4d>
nopl   0x0(%rax,%rax,1)
movzbl (%r12),%ebx
add    $0x1,%r12
test   %bl,%bl
je     1196 <trimall+0x66>
movsbl %bl,%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    1170 <trimall+0x40>
movslq %r15d,%r15
mov    %bl,(%r14,%r15,1)
add    $0x1,%r15d
jmp    1170 <trimall+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @trimall(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(255) i8* @malloc(i32 255)
%3 = tail call i32 @memset(i8* %2, i32 0, i32 8)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %1, %16
%7 = phi i64 [ %18, %16 ], [ 0, %1 ]
%8 = phi i8 [ %20, %16 ], [ %4, %1 ]
%9 = phi i32 [ %17, %16 ], [ 0, %1 ]
%10 = tail call i32 @isspace(i8 signext %8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 %8, i8* %14
%15 = add nsw i32 %9, 1
br label %16
16: ; preds = %12, %6
%17 = phi i32 [ %9, %6 ], [ %15, %12 ]
%18 = add nuw i64 %7, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %6
22: ; preds = %16, %1
ret i8* %2
}