#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*/ free(void *);
scalar_t__ malloc(scalar_t__);
void *realloc(char *, scalar_t__);
char *skip_string(char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *copy_and_remove_whitespaces(const char *string) {
  char *output_string = (char *)malloc(strlen(string) + 1);
  char *output_string_ptr = output_string;
  const char *string_ptr = string;
  const char *skipped_string = NULL;
  void *reallocated_ptr;
  char current_char;
  if (!output_string) {
    return NULL;
  }
  while (*string_ptr) {
    current_char = *string_ptr;
    switch (current_char) {
    case ' ':
    case '\r':
    case '\n':
    case '\t':
      string_ptr++;
      break;
    case '\"':
      skipped_string = skip_string(string_ptr);
      if (!skipped_string) {
        free((void *)output_string);
        return NULL;
      }
      strncpy(output_string_ptr, string_ptr, skipped_string - string_ptr);
      output_string_ptr = output_string_ptr + (skipped_string - string_ptr);
      string_ptr = skipped_string;
      break;
    default:
      *output_string_ptr = current_char;
      string_ptr++;
      output_string_ptr++;
      break;
    }
  }
  *output_string_ptr = '\0';
  reallocated_ptr = realloc(output_string, strlen(output_string) + 1);
  if (!reallocated_ptr) {
    free((void *)output_string);
    return NULL;
  }
  output_string = (char *)reallocated_ptr;
  return output_string;
}


x86 assembly (clang, -O0):
<copy_and_remove_whitespaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <copy_and_remove_whitespaces+0x55>
movq   $0x0,-0x8(%rbp)
jmp    131a <copy_and_remove_whitespaces+0x1ba>
jmp    11ba <copy_and_remove_whitespaces+0x5a>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     12bd <copy_and_remove_whitespaces+0x15d>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
mov    %eax,-0x40(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     121b <copy_and_remove_whitespaces+0xbb>
jmp    11e8 <copy_and_remove_whitespaces+0x88>
mov    -0x40(%rbp),%eax
sub    $0xd,%eax
je     121b <copy_and_remove_whitespaces+0xbb>
jmp    11f9 <copy_and_remove_whitespaces+0x99>
mov    -0x40(%rbp),%eax
sub    $0x20,%eax
je     121b <copy_and_remove_whitespaces+0xbb>
jmp    120a <copy_and_remove_whitespaces+0xaa>
mov    -0x40(%rbp),%eax
sub    $0x22,%eax
je     122c <copy_and_remove_whitespaces+0xcc>
jmp    1297 <copy_and_remove_whitespaces+0x137>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12b8 <copy_and_remove_whitespaces+0x158>
mov    -0x28(%rbp),%rdi
call   1060 <skip_string@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125a <copy_and_remove_whitespaces+0xfa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    131a <copy_and_remove_whitespaces+0x1ba>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12b8 <copy_and_remove_whitespaces+0x158>
mov    -0x39(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ba <copy_and_remove_whitespaces+0x5a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    130a <copy_and_remove_whitespaces+0x1aa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    131a <copy_and_remove_whitespaces+0x1ba>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_and_remove_whitespaces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1220 <copy_and_remove_whitespaces+0xc0>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     11f8 <copy_and_remove_whitespaces+0x98>
movabs $0x100002600,%rbp
mov    %r14,%r15
jmp    11ab <copy_and_remove_whitespaces+0x4b>
nopl   (%rax)
add    $0x1,%rbx
movzbl (%rbx),%eax
test   %al,%al
je     11fb <copy_and_remove_whitespaces+0x9b>
movsbl %al,%ecx
cmp    $0x22,%ecx
ja     11eb <copy_and_remove_whitespaces+0x8b>
bt     %rcx,%rbp
jb     11a0 <copy_and_remove_whitespaces+0x40>
cmp    $0x22,%rcx
jne    11eb <copy_and_remove_whitespaces+0x8b>
mov    %rbx,%rdi
call   1060 <skip_string@plt>
test   %rax,%rax
je     1218 <copy_and_remove_whitespaces+0xb8>
mov    %rax,%r12
mov    %rax,%r13
sub    %rbx,%r13
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <strncpy@plt>
add    %r13,%r15
mov    %r12,%rbx
jmp    11a4 <copy_and_remove_whitespaces+0x44>
mov    %al,(%r15)
add    $0x1,%rbx
add    $0x1,%r15
jmp    11a4 <copy_and_remove_whitespaces+0x44>
mov    %r14,%r15
movb   $0x0,(%r15)
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   1080 <realloc@plt>
test   %rax,%rax
jne    1222 <copy_and_remove_whitespaces+0xc2>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @copy_and_remove_whitespaces(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
store i8* %15, i8** %5
%16 = load i8*, i8** %3
store i8* %16, i8** %6
store i8* null, i8** %7
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %1
store i8* null, i8** %2
br label %82
20: ; preds = %1
br label %21
21: ; preds = %66, %20
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %67
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
store i8 %27, i8* %9
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
switch i32 %29, label %59 [
i32 32, label %30
i32 13, label %30
i32 10, label %30
i32 9, label %30
i32 34, label %33
]
30: ; preds = %25, %25, %25, %25
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
br label %66
33: ; preds = %25
%34 = load i8*, i8** %6
%35 = call i8* @skip_string(i8* %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = call i32 @free(i8* %39)
store i8* null, i8** %2
br label %82
41: ; preds = %33
%42 = load i8*, i8** %5
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = load i8*, i8** %6
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
%50 = call i32 @strncpy(i8* %42, i8* %43, i32 %49)
%51 = load i8*, i8** %5
%52 = load i8*, i8** %7
%53 = load i8*, i8** %6
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = getelementptr inbounds i8, i8* %51, i64 %56
store i8* %57, i8** %5
%58 = load i8*, i8** %7
store i8* %58, i8** %6
br label %66
59: ; preds = %25
%60 = load i8, i8* %9
%61 = load i8*, i8** %5
store i8 %60, i8* %61
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %6
%64 = load i8*, i8** %5
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %5
br label %66
66: ; preds = %59, %41, %30
br label %21
67: ; preds = %21
%68 = load i8*, i8** %5
store i8 0, i8* %68
%69 = load i8*, i8** %4
%70 = load i8*, i8** %4
%71 = call i64 @strlen(i8* %70)
%72 = add nsw i64 %71, 1
%73 = call i8* @realloc(i8* %69, i64 %72)
store i8* %73, i8** %8
%74 = load i8*, i8** %8
%75 = icmp ne i8* %74, null
br i1 %75, label %79, label %76
76: ; preds = %67
%77 = load i8*, i8** %4
%78 = call i32 @free(i8* %77)
store i8* null, i8** %2
br label %82
79: ; preds = %67
%80 = load i8*, i8** %8
store i8* %80, i8** %4
%81 = load i8*, i8** %4
store i8* %81, i8** %2
br label %82
82: ; preds = %79, %76, %38, %19
%83 = load i8*, i8** %2
ret i8* %83
}

LLVM IR (-O2):
define noalias i8* @copy_and_remove_whitespaces(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %43, label %7
7: ; preds = %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %7, %30
%11 = phi i8 [ %33, %30 ], [ %8, %7 ]
%12 = phi i8* [ %32, %30 ], [ %0, %7 ]
%13 = phi i8* [ %31, %30 ], [ %5, %7 ]
%14 = sext i8 %11 to i32
switch i32 %14, label %27 [
i32 32, label %15
i32 13, label %15
i32 10, label %15
i32 9, label %15
i32 34, label %17
]
15: ; preds = %10, %10, %10, %10
%16 = getelementptr inbounds i8, i8* %12, i64 1
br label %30
17: ; preds = %10
%18 = tail call i8* @skip_string(i8* %12)
%19 = icmp eq i8* %18, null
br i1 %19, label %41, label %20
20: ; preds = %17
%21 = ptrtoint i8* %18 to i64
%22 = ptrtoint i8* %12 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = tail call i32 @strncpy(i8* %13, i8* %12, i32 %24)
%26 = getelementptr inbounds i8, i8* %13, i64 %23
br label %30
27: ; preds = %10
store i8 %11, i8* %13
%28 = getelementptr inbounds i8, i8* %12, i64 1
%29 = getelementptr inbounds i8, i8* %13, i64 1
br label %30
30: ; preds = %27, %20, %15
%31 = phi i8* [ %29, %27 ], [ %26, %20 ], [ %13, %15 ]
%32 = phi i8* [ %28, %27 ], [ %18, %20 ], [ %16, %15 ]
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %10
35: ; preds = %30, %7
%36 = phi i8* [ %5, %7 ], [ %31, %30 ]
store i8 0, i8* %36
%37 = tail call i64 @strlen(i8* %5)
%38 = add nsw i64 %37, 1
%39 = tail call i8* @realloc(i8* %5, i64 %38)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %17, %35
%42 = tail call i32 @free(i8* %5)
br label %43
43: ; preds = %41, %35, %1
%44 = phi i8* [ null, %1 ], [ %39, %35 ], [ null, %41 ]
ret i8* %44
}