#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 *);
int main() {
  char s[] = "the sky is blue";
  printf("%s \n", s);
  reverse(s, 0, strlen(s) - 1);
  int last = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == ' ') {
      reverse(s, last, i - 1);
      last = i + 1;
      continue;
    }
    if (i == strlen(s) - 1) {
      reverse(s, last, i);
    }
  }
  printf("%s \n", s);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <reverse@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1223 <main+0xf3>
movslq -0x28(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    11e2 <main+0xb2>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
sub    $0x1,%edx
call   1030 <reverse@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1215 <main+0xe5>
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1210 <main+0xe0>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1030 <reverse@plt>
jmp    1215 <main+0xe5>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1194 <main+0x64>
lea    -0x20(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps 0xec0(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xec5(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <reverse@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11da <main+0xaa>
mov    %rsp,%r14
xor    %ebx,%ebx
jmp    11b5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <reverse@plt>
lea    0x1(%rbx),%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11da <main+0xaa>
cmpb   $0x20,(%rsp,%rbx,1)
je     1190 <main+0x60>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
cmp    %rax,%rbx
jne    11a2 <main+0x72>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1030 <reverse@plt>
jmp    11a2 <main+0x72>
lea    0xe2f(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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