#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*/ reverse_string_inplace(char *, int);
int strlen(char *);
void reverse_words_inplace(char *s) {
  int len = strlen(s);
  reverse_string_inplace(s, len);
  for (int a = 0, b = 0; b <= len; b++) {
    if (b == len || s[b] == ' ') {
      reverse_string_inplace(s + a, b - a);
      a = ++b;
    }
  }
}


x86 assembly (clang, -O0):
<reverse_words_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <reverse_string_inplace@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b4 <reverse_words_inplace+0x94>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     117f <reverse_words_inplace+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11a1 <reverse_words_inplace+0x81>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x10(%rbp),%esi
call   1030 <reverse_string_inplace@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x10(%rbp)
jmp    11a6 <reverse_words_inplace+0x86>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <reverse_words_inplace+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_words_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <reverse_string_inplace@plt>
test   %ebp,%ebp
js     117d <reverse_words_inplace+0x5d>
xor    %ebx,%ebx
xor    %eax,%eax
jmp    116d <reverse_words_inplace+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cltq
lea    (%r14,%rax,1),%rdi
mov    %ebx,%esi
sub    %eax,%esi
call   1030 <reverse_string_inplace@plt>
add    $0x1,%ebx
mov    %ebx,%eax
lea    0x1(%rbx),%ecx
cmp    %ebp,%ebx
mov    %ecx,%ebx
jge    117d <reverse_words_inplace+0x5d>
cmp    %ebp,%ebx
je     1150 <reverse_words_inplace+0x30>
movslq %ebx,%rcx
cmpb   $0x20,(%r14,%rcx,1)
je     1150 <reverse_words_inplace+0x30>
jmp    1164 <reverse_words_inplace+0x44>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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