#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(char *, char *);
void reverse_words(char str[]) {
  char *temp = str;
  char *word_begin = str;
  while (*temp != '\0') {
    temp++;
    if (*temp == ' ') {
      reverse(word_begin, temp - 1);
      word_begin = temp + 1;
    }
    if (*temp == '\0') {
      reverse(word_begin, temp - 1);
    }
  }
  reverse(str, temp - 1);
}


x86 assembly (clang, -O0):
<reverse_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119b <reverse_words+0x8b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1175 <reverse_words+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1196 <reverse_words+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
jmp    112c <reverse_words+0x1c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_words>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
mov    %rdi,%rbx
je     116f <reverse_words+0x5f>
lea    0x2(%r14),%rbx
mov    %r14,%r15
jmp    1138 <reverse_words+0x28>
nopl   0x0(%rax)
add    $0x1,%rbx
test   %al,%al
je     116b <reverse_words+0x5b>
lea    -0x2(%rbx),%r12
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
jne    1156 <reverse_words+0x46>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <reverse@plt>
movzbl -0x1(%rbx),%eax
mov    %rbx,%r15
test   %al,%al
jne    1130 <reverse_words+0x20>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <reverse@plt>
movzbl -0x1(%rbx),%eax
jmp    1130 <reverse_words+0x20>
add    $0xfffffffffffffffe,%rbx
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <reverse@plt>

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

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