#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(int);
void remove_repeated_whitespace(char *string) {
  char *read = string, *write = string;
  int last_was_white = 0;
  char c;
  while (*read != '\0') {
    c = *read;
    read++;
    if (isspace((int)c)) {
      if (!last_was_white) {
        last_was_white = 1;
        *write = ' ';
        write++;
      }
    } else {
      last_was_white = 0;
      *write = c;
      write++;
    }
  }
  *write = '\0';
}


x86 assembly (clang, -O0):
<remove_repeated_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <remove_repeated_whitespace+0xa5>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x1d(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1194 <remove_repeated_whitespace+0x84>
cmpl   $0x0,-0x1c(%rbp)
jne    118f <remove_repeated_whitespace+0x7f>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <remove_repeated_whitespace+0xa0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1133 <remove_repeated_whitespace+0x23>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_repeated_whitespace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%bl
test   %bl,%bl
je     1164 <remove_repeated_whitespace+0x54>
lea    0x1(%r14),%r15
xor    %ebp,%ebp
jmp    1145 <remove_repeated_whitespace+0x35>
nopl   0x0(%rax,%rax,1)
mov    %bl,(%r14)
add    $0x1,%r14
movzbl (%r15),%ebx
add    $0x1,%r15
mov    %ecx,%ebp
test   %bl,%bl
je     1164 <remove_repeated_whitespace+0x54>
movsbl %bl,%edi
call   1030 <isspace@plt>
mov    $0x0,%ecx
test   %rax,%rax
je     1130 <remove_repeated_whitespace+0x20>
mov    $0x1,%ecx
test   %ebp,%ebp
jne    1137 <remove_repeated_whitespace+0x27>
mov    $0x20,%bl
jmp    1130 <remove_repeated_whitespace+0x20>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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