#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*/ reverseAWord(char *, char *);
int strlen(char *);
void reverseASentence(char *string) {
  int strLen = strlen(string);
  char *end = string;
  char *start = string;
  char *traversePtr = string;
  end = end + (strLen - 1);
  reverseAWord(start, end);
  int count = 0;
  int singleWordLen = 0;
  while (count < strLen) {
    if (*(traversePtr + 1) == ' ' || *(traversePtr + 1) == '\0') {
      reverseAWord(traversePtr - singleWordLen, traversePtr);
      traversePtr++;
      singleWordLen = 0;
    } else {
      singleWordLen++;
    }
    count++;
    traversePtr++;
  }
}


x86 assembly (clang, -O0):
<reverseASentence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <reverseAWord@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1201 <reverseASentence+0xe1>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
je     11ad <reverseASentence+0x8d>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11de <reverseASentence+0xbe>
mov    -0x28(%rbp),%rdi
movslq -0x30(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <reverseAWord@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
jmp    11e7 <reverseASentence+0xc7>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <reverseASentence+0x5f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseASentence>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
call   1040 <reverseAWord@plt>
test   %ebp,%ebp
jle    117d <reverseASentence+0x5d>
xor    %eax,%eax
jmp    115c <reverseASentence+0x3c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%eax
add    $0x1,%rbx
add    $0xffffffff,%ebp
je     117d <reverseASentence+0x5d>
testb  $0xdf,0x1(%rbx)
jne    1150 <reverseASentence+0x30>
lea    0x1(%rbx),%r14
cltq
mov    %rbx,%rdi
sub    %rax,%rdi
mov    %rbx,%rsi
call   1040 <reverseAWord@plt>
xor    %eax,%eax
mov    %r14,%rbx
jmp    1153 <reverseASentence+0x33>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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