#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(char *, int, int);
int strlen(char *);
void reverse_order_words(char *phrase) {
  reverse_string(phrase, 0, strlen(phrase) - 1);
  for (int i = 0, j = 0; i < strlen(phrase); i = j + 1) {
    for (j = i; j < strlen(phrase) && phrase[j] != ' '; j++)
      ;
    reverse_string(phrase, i, j - 1);
  }
}


x86 assembly (clang, -O0):
<reverse_order_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse_string@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11f6 <reverse_order_words+0xd6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jge    11b3 <reverse_order_words+0x93>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11c3 <reverse_order_words+0xa3>
jmp    11d6 <reverse_order_words+0xb6>
jmp    11c8 <reverse_order_words+0xa8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <reverse_order_words+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse_string@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <reverse_order_words+0x3b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_order_words>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <reverse_string@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jg     1170 <reverse_order_words+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret
nopl   (%rax)
lea    -0x1(%rbp),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <reverse_string@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%r14d
cmp    %eax,%ebp
jge    1148 <reverse_order_words+0x28>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%ebp
cmp    %eax,%r14d
jge    1150 <reverse_order_words+0x30>
movslq %r14d,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x20,(%rbx,%rbp,1)
je     1150 <reverse_order_words+0x30>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1190 <reverse_order_words+0x70>
jmp    1150 <reverse_order_words+0x30>

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

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