#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*/ printf(char *, ...);
int strlen(char *);
main() {
  char input[1000], str[1000];
  int l, i, j = 0;
  printf("Enter string with spaces\n");
  gets(input);
  l = strlen(input);
  for (i = 0; i < l; i++) {
    if (input[i] != ' ')
      str[j++] = input[i];
    else {
      if (j != 0)
        str[j++] = ' ';
      while (input[++i] == ' ' && i < l)
        ;
      i--;
    }
  }
  str[j++] = '\0';
  printf("String after removing spaces is\n%s", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7ec(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x3f0(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x3f0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x7e4(%rbp)
movl   $0x0,-0x7e8(%rbp)
mov    -0x7e8(%rbp),%eax
cmp    -0x7e4(%rbp),%eax
jge    1285 <main+0x155>
movslq -0x7e8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
je     11d9 <main+0xa9>
movslq -0x7e8(%rbp),%rax
mov    -0x3f0(%rbp,%rax,1),%cl
mov    -0x7ec(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x7ec(%rbp)
cltq
mov    %cl,-0x7e0(%rbp,%rax,1)
jmp    126c <main+0x13c>
cmpl   $0x0,-0x7ec(%rbp)
je     1201 <main+0xd1>
mov    -0x7ec(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7ec(%rbp)
cltq
movb   $0x20,-0x7e0(%rbp,%rax,1)
jmp    1206 <main+0xd6>
mov    -0x7e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
cltq
movsbl -0x3f0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x7ed(%rbp)
jne    1245 <main+0x115>
mov    -0x7e8(%rbp),%eax
cmp    -0x7e4(%rbp),%eax
setl   %al
mov    %al,-0x7ed(%rbp)
mov    -0x7ed(%rbp),%al
test   $0x1,%al
jne    1258 <main+0x128>
jmp    125d <main+0x12d>
jmp    1206 <main+0xd6>
mov    -0x7e8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7e8(%rbp)
jmp    1271 <main+0x141>
mov    -0x7e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
jmp    1182 <main+0x52>
mov    -0x7ec(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7ec(%rbp)
cltq
movb   $0x0,-0x7e0(%rbp,%rax,1)
lea    -0x7e0(%rbp),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x7e0,%rsp
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0x3f0(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11db <main+0x9b>
mov    %eax,%edx
xor    %ecx,%ecx
xor    %esi,%esi
jmp    1190 <main+0x50>
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rdi
add    $0x1,%ecx
mov    %bl,(%rsp,%rdi,1)
add    $0x1,%esi
cmp    %eax,%esi
jge    11dd <main+0x9d>
movslq %esi,%rdi
mov    0x3f0(%rsp,%rdi,1),%bl
cmp    $0x20,%bl
jne    1180 <main+0x40>
test   %ecx,%ecx
je     11af <main+0x6f>
movslq %ecx,%rsi
add    $0x1,%ecx
movb   $0x20,(%rsp,%rsi,1)
jmp    11b1 <main+0x71>
xor    %ecx,%ecx
lea    -0x1(%rdi),%esi
add    $0x1,%rdi
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
cmpb   $0x20,0x3f0(%rsp,%rdi,1)
20
jne    1189 <main+0x49>
lea    0x1(%rdi),%rbx
cmp    %rdx,%rdi
mov    %rbx,%rdi
jl     11c0 <main+0x80>
jmp    1189 <main+0x49>
xor    %ecx,%ecx
movslq %ecx,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0xe15(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x7e0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter string with spaces\0A\00"
@.str.1 = [35 x i8] c"String after removing spaces is\0A%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
store i32 0, i32* %5
br label %12
12: ; preds = %60, %0
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %63
16: ; preds = %12
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 32
br i1 %22, label %23, label %32
23: ; preds = %16
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %30
store i8 %27, i8* %31
br label %59
32: ; preds = %16
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %38
store i8 32, i8* %39
br label %40
40: ; preds = %35, %32
br label %41
41: ; preds = %55, %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 32
br i1 %48, label %49, label %53
49: ; preds = %41
%50 = load i32, i32* %5
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br label %53
53: ; preds = %49, %41
%54 = phi i1 [ false, %41 ], [ %52, %49 ]
br i1 %54, label %55, label %56
55: ; preds = %53
br label %41
56: ; preds = %53
%57 = load i32, i32* %5
%58 = add nsw i32 %57, -1
store i32 %58, i32* %5
br label %59
59: ; preds = %56, %23
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %12
63: ; preds = %12
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %66
store i8 0, i8* %67
%68 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %68)
%70 = load i32, i32* %1
ret i32 %70
}

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