#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*/ gets(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
main() {
  char str[100];
  int i, cnt = 0;
  puts("enter string: ");
  gets(str);
  while (*str == 32)
    memmove(str, str + 1, strlen(str + 1) + 1);
  while (str[strlen(str) - 1] == 0)
    str[strlen(str) - 1] = 0;
  for (i = 0; str[i]; i++) {
    if (str[i] == ' ' && str[i + 1] == ' ') {
      memmove(str + i, str + i + 1, strlen(str + i + 1) + 1);
      i--;
    }
  }
  printf("%s\n", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x78(%rbp)
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x20,%eax
jne    11c9 <main+0x79>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <memmove@plt>
jmp    117e <main+0x2e>
jmp    11ce <main+0x7e>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
jne    1202 <main+0xb2>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
jmp    11ce <main+0x7e>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmpb   $0x0,-0x70(%rbp,%rax,1)
je     12b0 <main+0x160>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    129d <main+0x14d>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    129d <main+0x14d>
lea    -0x70(%rbp),%rax
movslq -0x74(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x98(%rbp)
lea    -0x70(%rbp),%rax
movslq -0x74(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
movslq -0x74(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <memmove@plt>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
jmp    12a2 <main+0x152>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1209 <main+0xb9>
lea    -0x70(%rbp),%rsi
lea    0xd54(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <gets@plt>
cmpb   $0x20,(%rsp)
jne    11b0 <main+0x60>
lea    0x1(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <memmove@plt>
cmpb   $0x20,(%rsp)
je     1180 <main+0x30>
jmp    11b0 <main+0x60>
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x0,-0x1(%rax,%r14,1)
je     11a0 <main+0x50>
xor    %eax,%eax
jmp    11d7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
test   %cl,%cl
je     1211 <main+0xc1>
add    $0x1,%eax
movslq %eax,%rbx
movzbl (%rsp,%rbx,1),%ecx
cmp    $0x20,%cl
jne    11d0 <main+0x80>
cmpb   $0x20,0x1(%rbx,%r14,1)
jne    11d4 <main+0x84>
lea    (%rsp,%rbx,1),%r12
lea    0x1(%r12),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <memmove@plt>
add    $0xffffffff,%ebx
mov    %ebx,%eax
jmp    11d4 <main+0x84>
lea    0xdf7(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"enter string: \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
br label %8
8: ; preds = %13, %0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 32
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = call i32 @memmove(i8* %14, i8* %16, i32 %20)
br label %8
22: ; preds = %8
br label %23
23: ; preds = %32, %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %23
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %36
store i8 0, i8* %37
br label %23
38: ; preds = %23
store i32 0, i32* %3
br label %39
39: ; preds = %81, %38
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %84
45: ; preds = %39
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %80
52: ; preds = %45
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 32
br i1 %59, label %60, label %80
60: ; preds = %52
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%62 = load i32, i32* %3
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%66 = load i32, i32* %3
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = getelementptr inbounds i8, i8* %68, i64 1
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%71 = load i32, i32* %3
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = getelementptr inbounds i8, i8* %73, i64 1
%75 = call i32 @strlen(i8* %74)
%76 = add nsw i32 %75, 1
%77 = call i32 @memmove(i8* %64, i8* %69, i32 %76)
%78 = load i32, i32* %3
%79 = add nsw i32 %78, -1
store i32 %79, i32* %3
br label %80
80: ; preds = %60, %52, %45
br label %81
81: ; preds = %80
%82 = load i32, i32* %3
%83 = add nsw i32 %82, 1
store i32 %83, i32* %3
br label %39
84: ; preds = %39
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%86 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %85)
%87 = load i32, i32* %1
ret i32 %87
}

LLVM IR (-O2):
@.str = [15 x i8] c"enter string: \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 32
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
br label %16
9: ; preds = %16, %0
%10 = call i32 @strlen(i8* %2)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %22, label %33
16: ; preds = %7, %16
%17 = call i32 @strlen(i8* %8)
%18 = add nsw i32 %17, 1
%19 = call i32 @memmove(i8* %2, i8* %8, i32 %18)
%20 = load i8, i8* %2
%21 = icmp eq i8 %20, 32
br i1 %21, label %16, label %9
22: ; preds = %9, %22
%23 = call i32 @strlen(i8* %2)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 @strlen(i8* %2)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %22, label %33
33: ; preds = %22, %9
br label %34
34: ; preds = %33, %51
%35 = phi i32 [ %53, %51 ], [ 0, %33 ]
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
switch i8 %38, label %51 [
i8 0, label %54
i8 32, label %39
]
39: ; preds = %34
%40 = add nsw i32 %35, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 32
br i1 %44, label %45, label %51
45: ; preds = %39
%46 = getelementptr inbounds i8, i8* %37, i64 1
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %47, 1
%49 = call i32 @memmove(i8* %37, i8* %46, i32 %48)
%50 = add nsw i32 %35, -1
br label %51
51: ; preds = %34, %39, %45
%52 = phi i32 [ %50, %45 ], [ %35, %39 ], [ %35, %34 ]
%53 = add nsw i32 %52, 1
br label %34
54: ; preds = %34
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}