#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);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void trim_whitespace(char *victim) {
  int i, j;
  char new_str[2048];
  j = 0;
  for (i = 0; i < strlen(victim); i++) {
    if (isspace(victim[i]))
      continue;
    new_str[j++] = victim[i];
  }
  new_str[j] = '\0';
  strcpy(victim, new_str);
}


x86 assembly (clang, -O0):
<trim_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x814(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x814(%rbp),%eax
cmp    %ecx,%eax
jge    11bc <trim_whitespace+0x8c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     118f <trim_whitespace+0x5f>
jmp    11ae <trim_whitespace+0x7e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x810(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <trim_whitespace+0x1d>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_whitespace>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    1181 <trim_whitespace+0x51>
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1163 <trim_whitespace+0x33>
xchg   %ax,%ax
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1184 <trim_whitespace+0x54>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1150 <trim_whitespace+0x20>
movzbl (%rbx,%rbp,1),%eax
movslq %r14d,%rcx
add    $0x1,%r14d
mov    %al,(%rsp,%rcx,1)
jmp    1150 <trim_whitespace+0x20>
xor    %r14d,%r14d
movslq %r14d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @trim_whitespace(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %1, %18
%7 = phi i64 [ %20, %18 ], [ 0, %1 ]
%8 = phi i32 [ %19, %18 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @isspace(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = load i8, i8* %9
%15 = add nsw i32 %8, 1
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %16
store i8 %14, i8* %17
br label %18
18: ; preds = %6, %13
%19 = phi i32 [ %8, %6 ], [ %15, %13 ]
%20 = add nuw nsw i64 %7, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %6, label %24
24: ; preds = %18, %1
%25 = phi i32 [ 0, %1 ], [ %19, %18 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @strcpy(i8* %0, i8* %3)
ret void
}