#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int i, j;
  char buf[256], res[256];
  printf("input string: ");
  fgets(buf, sizeof(buf), stdin);
  int flag = 0;
  for (i = 0, j = 0; buf[i] != '\0'; ++i) {
    if (buf[i] == ' ') {
      flag++;
      if (flag < 2)
        res[j++] = ' ';
    } else {
      flag = 0;
      res[j++] = buf[i];
    }
  }
  res[j] = '\0';
  printf("result: %s", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1215 <main+0xf5>
movslq -0x14(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    11d9 <main+0xb9>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
cmpl   $0x2,-0x224(%rbp)
jge    11d4 <main+0xb4>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movb   $0x20,-0x220(%rbp,%rax,1)
20
jmp    1202 <main+0xe2>
movl   $0x0,-0x224(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x120(%rbp,%rax,1),%cl
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %cl,-0x220(%rbp,%rax,1)
jmp    1207 <main+0xe7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <main+0x59>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
lea    0xed0(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
xor    %edx,%edx
jmp    1178 <main+0x58>
nopl   0x0(%rax,%rax,1)
mov    $0x0,%eax
test   %cl,%cl
je     118b <main+0x6b>
movslq %ebp,%rdx
add    $0x1,%ebp
mov    %cl,(%rsp,%rdx,1)
add    $0x1,%rbx
mov    %eax,%edx
movzbl (%rbx),%ecx
cmp    $0x20,%cl
jne    1160 <main+0x40>
lea    0x1(%rdx),%eax
test   %edx,%edx
jg     1172 <main+0x52>
mov    $0x20,%cl
jmp    1169 <main+0x49>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0xe76(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"input string: \00"
@stdin = global i32 0
@.str.1 = [11 x i8] c"result: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %5, i32 256, i32 %8)
br label %10
10: ; preds = %25, %2
%11 = phi i64 [ %28, %25 ], [ 0, %2 ]
%12 = phi i32 [ %26, %25 ], [ 0, %2 ]
%13 = phi i32 [ %27, %25 ], [ 0, %2 ]
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %11
%15 = load i8, i8* %14
switch i8 %15, label %19 [
i8 0, label %29
i8 32, label %16
]
16: ; preds = %10
%17 = add nsw i32 %13, 1
%18 = icmp slt i32 %13, 1
br i1 %18, label %19, label %25
19: ; preds = %10, %16
%20 = phi i8 [ 32, %16 ], [ %15, %10 ]
%21 = phi i32 [ %17, %16 ], [ 0, %10 ]
%22 = add nsw i32 %12, 1
%23 = sext i32 %12 to i64
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %19, %16
%26 = phi i32 [ %12, %16 ], [ %22, %19 ]
%27 = phi i32 [ %17, %16 ], [ %21, %19 ]
%28 = add nuw i64 %11, 1
br label %10
29: ; preds = %10
%30 = sext i32 %12 to i64
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i32 0
}