#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 *);
int strlen(char *);
char *reverseWords(char *input) {
  char *start = input;
  int length = strlen(input);
  reverse(start, start + length - 1);
  char *wordEnd = start;
  while (*wordEnd) {
    wordEnd++;
    if ((*wordEnd == ' ') || (*wordEnd == 0)) {
      reverse(start, wordEnd - 1);
      start = wordEnd + 1;
    }
  }
  return input;
}


x86 assembly (clang, -O0):
<reverseWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bb <reverseWords+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1199 <reverseWords+0x79>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b6 <reverseWords+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1160 <reverseWords+0x40>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseWords>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r14,%rdi
call   1030 <reverse@plt>
cmpb   $0x0,(%r14)
je     1172 <reverseWords+0x52>
lea    0x2(%r14),%rbx
mov    %r14,%rdi
jmp    1158 <reverseWords+0x38>
nopl   (%rax)
add    $0x1,%rbx
test   %al,%al
je     1172 <reverseWords+0x52>
movzbl -0x1(%rbx),%eax
test   $0xdf,%al
jne    1150 <reverseWords+0x30>
lea    -0x2(%rbx),%rsi
call   1030 <reverse@plt>
movzbl -0x1(%rbx),%eax
mov    %rbx,%rdi
jmp    1150 <reverseWords+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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