#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char sentence[100] = {' '}, ch = ' ';
  int start_space = 0, end_index = 0, index = 1;
  printf("enter a sentence\n");
  while ((ch = getchar()) != '\n') {
    sentence[index] = ch;
    index += 1;
  }
  end_index = index - 1;
  sentence[index] = sentence[end_index];
  sentence[end_index] = ' ';
  for (int i = end_index; i >= 0; i--) {
    if (sentence[i] == ' ') {
      start_space = i;
      for (int j = start_space + 1; j < end_index + 1; j++) {
        printf("%c", sentence[j]);
      }
      end_index = start_space;
    }
  }
  printf("%c\n", sentence[index]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movb   $0x20,-0x70(%rbp)
movb   $0x20,-0x71(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x1,-0x80(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11ac <main+0x7c>
mov    -0x71(%rbp),%cl
movslq -0x80(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    117d <main+0x4d>
mov    -0x80(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x80(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
movslq -0x7c(%rbp),%rax
movb   $0x20,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jl     126f <main+0x13f>
movslq -0x84(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    1256 <main+0x126>
mov    -0x84(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    -0x7c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1250 <main+0x120>
movslq -0x88(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    120e <main+0xde>
mov    -0x78(%rbp),%eax
mov    %eax,-0x7c(%rbp)
jmp    125b <main+0x12b>
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
jmp    11d7 <main+0xa7>
movslq -0x80(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%esi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x70(%rsp)
movb   $0x20,0x10(%rsp)
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0x1,%ebx
cmp    $0xa,%al
je     11b3 <main+0x73>
mov    $0x1,%ebx
nopl   (%rax)
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <main+0x60>
movslq %ebx,%r14
lea    -0x1(%r14),%rax
mov    0xf(%rsp,%r14,1),%cl
mov    %r14d,%edx
mov    %rdx,0x8(%rsp)
mov    %cl,0x10(%rsp,%rdx,1)
movb   $0x20,0xf(%rsp,%r14,1)
mov    %eax,%r13d
mov    $0x1,%r12d
lea    0x10(%rsp),%rbx
jmp    120b <main+0xcb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
mov    %r13,%rdx
add    $0xffffffffffffffff,%rdx
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
mov    %ecx,%eax
test   %r13d,%r13d
mov    %rdx,%r13
jle    1248 <main+0x108>
cmpb   $0x20,0x10(%rsp,%r13,1)
jne    11f0 <main+0xb0>
mov    %r13d,%ecx
cmp    %r13d,%eax
jle    11f2 <main+0xb2>
movslq %eax,%rbp
add    %r12,%rbp
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rbx,%r15,1),%edi
call   1030 <putchar@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1230 <main+0xf0>
mov    %r13d,%ecx
jmp    11f2 <main+0xb2>
mov    0x8(%rsp),%rax
movsbl 0x10(%rsp,%rax,1),%esi
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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