#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*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int, int);
int strlen(char *);
rev(char *s) {
  reverse(s, 0, strlen(s) - 1);
  int j = 0, i = 0;
  for (; i < strlen(s); i++) {
    if (s[i] == ' ') {
      reverse(s, j, i - 1);
      j = i + 1;
    }
  }
  reverse(s, j, i - 1);
  printf("%s", s);
}


x86 assembly (clang, -O0):
<rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11ca <rev+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11b7 <rev+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <rev+0x8c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <rev+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rsi
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rev>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <reverse@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1195 <rev+0x65>
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1184 <rev+0x54>
nop
lea    -0x1(%rbp),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <reverse@plt>
add    $0x1,%rbp
mov    %ebp,%r14d
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1190 <rev+0x60>
cmpb   $0x20,(%rbx,%rbp,1)
je     1160 <rev+0x30>
add    $0x1,%rbp
jmp    1175 <rev+0x45>
add    $0xffffffff,%ebp
jmp    119a <rev+0x6a>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <reverse@plt>
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @rev(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = tail call i32 @reverse(i8* %0, i32 0, i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %1, %21
%8 = phi i64 [ %22, %21 ], [ 0, %1 ]
%9 = phi i32 [ %23, %21 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 32
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = add nuw nsw i64 %8, 1
br label %21
15: ; preds = %7
%16 = trunc i64 %8 to i32
%17 = add i32 %16, -1
%18 = tail call i32 @reverse(i8* %0, i32 %9, i32 %17)
%19 = add nuw nsw i64 %8, 1
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %13, %15
%22 = phi i64 [ %14, %13 ], [ %19, %15 ]
%23 = phi i32 [ %9, %13 ], [ %20, %15 ]
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %22, %25
br i1 %26, label %7, label %27
27: ; preds = %21
%28 = trunc i64 %22 to i32
%29 = add i32 %28, -1
br label %30
30: ; preds = %27, %1
%31 = phi i32 [ 0, %1 ], [ %23, %27 ]
%32 = phi i32 [ -1, %1 ], [ %29, %27 ]
%33 = tail call i32 @reverse(i8* %0, i32 %31, i32 %32)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
ret i32 undef
}