#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 */
scalar_t__ IsWhitespace(char);
int /*<<< orphan*/ ReverseSegment(char *, char *);
int /*<<< orphan*/ ReverseString(char *);
void reverse_words2(char string[]) {
  char *cp;
  ReverseString(string);
  while (*string) {
    while (IsWhitespace(*string)) {
      string++;
    }
    if (!*string) {
      return;
    }
    cp = string;
    while (*string && !IsWhitespace(*string)) {
      string++;
    }
    ReverseSegment(cp, string - 1);
  }
}


x86 assembly (clang, -O0):
<reverse_words2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ReverseString@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11fc <reverse_words2+0xcc>
jmp    1157 <reverse_words2+0x27>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <IsWhitespace@plt>
cmp    $0x0,%rax
je     117e <reverse_words2+0x4e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1157 <reverse_words2+0x27>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1190 <reverse_words2+0x60>
jmp    11fc <reverse_words2+0xcc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     11c5 <reverse_words2+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <IsWhitespace@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11d5 <reverse_words2+0xa5>
jmp    11e6 <reverse_words2+0xb6>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <reverse_words2+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <ReverseSegment@plt>
jmp    1145 <reverse_words2+0x15>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_words2>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <ReverseString@plt>
mov    (%r14),%al
jmp    1161 <reverse_words2+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%rsi
mov    %r14,%rdi
call   1030 <ReverseSegment@plt>
mov    (%rbx),%al
mov    %rbx,%r14
test   %al,%al
je     11bb <reverse_words2+0x8b>
movsbl %al,%edi
nopl   0x0(%rax,%rax,1)
call   1050 <IsWhitespace@plt>
test   %rax,%rax
je     1190 <reverse_words2+0x60>
movsbl 0x1(%r14),%edi
add    $0x1,%r14
jmp    1170 <reverse_words2+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14),%al
test   %al,%al
je     11bb <reverse_words2+0x8b>
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <IsWhitespace@plt>
test   %rax,%rax
jne    1150 <reverse_words2+0x20>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <reverse_words2+0x70>
jmp    1150 <reverse_words2+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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