#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*/ reverseString(char *, int, int);
int strlen(char *);
char *reverseWords(char *s) {
  int p = 0, q;
  int l = strlen(s);
  for (int i = 0; i <= l; i++) {
    if (s[i] == ' ') {
      q = i - 1;
      reverseString(s, p, q);
      p = i + 1;
    }
    if (i == strlen(s)) {
      reverseString(s, p, l - 1);
    }
  }
  return s;
}


x86 assembly (clang, -O0):
<reverseWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11c9 <reverseWords+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1188 <reverseWords+0x68>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <reverseString@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    11b6 <reverseWords+0x96>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <reverseString@plt>
jmp    11bb <reverseWords+0x9b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1146 <reverseWords+0x26>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseWords>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
js     1190 <reverseWords+0x70>
mov    %eax,%r14d
lea    -0x1(%r14),%r15d
add    $0x1,%r14d
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1159 <reverseWords+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r14
je     1190 <reverseWords+0x70>
cmpb   $0x20,(%rbx,%rbp,1)
jne    1171 <reverseWords+0x51>
lea    -0x1(%rbp),%edx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <reverseString@plt>
lea    0x1(%rbp),%r12d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jne    1150 <reverseWords+0x30>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1040 <reverseString@plt>
jmp    1150 <reverseWords+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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