#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 *, char *);
void reverse_string(char *str) {
  char *temp = str;
  char *end;
  char *beg;
  printf("Input :%s\n", str);
  beg = str;
  while (*temp) {
    temp++;
    if (*temp == '\0') {
      reverse(beg, temp - 1);
    } else if (*temp == ' ') {
      reverse(beg, temp - 1);
      beg = temp + 1;
    }
  }
  reverse(str, temp - 1);
}


x86 assembly (clang, -O0):
<reverse_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c2 <reverse_string+0xa2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118b <reverse_string+0x6b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
jmp    11bd <reverse_string+0x9d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11b8 <reverse_string+0x98>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <reverse_string+0x9d>
jmp    114c <reverse_string+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_string>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xed1(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
cmpb   $0x0,(%r14)
mov    %r14,%rbx
je     1185 <reverse_string+0x65>
lea    0x2(%r14),%rbx
mov    %r14,%r15
jmp    1167 <reverse_string+0x47>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <reverse@plt>
mov    %rbx,%r15
movzbl -0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1181 <reverse_string+0x61>
lea    -0x2(%rbx),%rsi
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
je     1150 <reverse_string+0x30>
test   %al,%al
jne    115f <reverse_string+0x3f>
mov    %r15,%rdi
call   1030 <reverse@plt>
jmp    115b <reverse_string+0x3b>
add    $0xfffffffffffffffe,%rbx
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <reverse@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"Input :%s\0A\00"
define void @reverse_string(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %1, %18
%6 = phi i8* [ %20, %18 ], [ %0, %1 ]
%7 = phi i8* [ %8, %18 ], [ %0, %1 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
switch i8 %9, label %18 [
i8 0, label %10
i8 32, label %12
]
10: ; preds = %5
%11 = tail call i32 @reverse(i8* %6, i8* %7)
br label %15
12: ; preds = %5
%13 = tail call i32 @reverse(i8* %6, i8* %7)
%14 = getelementptr inbounds i8, i8* %7, i64 2
br label %15
15: ; preds = %10, %12
%16 = phi i8* [ %14, %12 ], [ %6, %10 ]
%17 = load i8, i8* %8
br label %18
18: ; preds = %15, %5
%19 = phi i8 [ %17, %15 ], [ %9, %5 ]
%20 = phi i8* [ %16, %15 ], [ %6, %5 ]
%21 = icmp eq i8 %19, 0
br i1 %21, label %22, label %5
22: ; preds = %18, %1
%23 = phi i8* [ %0, %1 ], [ %8, %18 ]
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = tail call i32 @reverse(i8* %0, i8* %24)
ret void
}