#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 *);
int /*<<< orphan*/ reverse(char *, char *);
int strlen(char *);
void reverse_sentence(char *string) {
  int len;
  int i, j;
  int start, end;
  char *start_c, *end_c;
  char c;
  if (string == NULL) {
    printf("string is null!\n");
    return;
  }
  len = strlen(string);
  if (len <= 1) {
    printf("this string only has one character!\n");
    return;
  }
  start_c = string;
  end_c = string + len - 1;
  reverse(start_c, end_c);
  i = 0;
  while (1) {
    while (string[i] == ' ') {
      i++;
    }
    start = i;
    while (string[i] != ' ' && string[i] != '\0') {
      i++;
    }
    end = i;
    start_c = string + start;
    end_c = string + end - 1;
    reverse(start_c, end_c);
    if (string[i] == '\0') {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<reverse_sentence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1158 <reverse_sentence+0x28>
lea    0xeb2(%rip),%rdi
call   1050 <printf@plt>
jmp    127d <reverse_sentence+0x14d>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     117f <reverse_sentence+0x4f>
lea    0xe9c(%rip),%rdi
call   1050 <printf@plt>
jmp    127d <reverse_sentence+0x14d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <reverse@plt>
movl   $0x0,-0x10(%rbp)
jmp    11b3 <reverse_sentence+0x83>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11d6 <reverse_sentence+0xa6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b3 <reverse_sentence+0x83>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x32(%rbp)
je     120b <reverse_sentence+0xdb>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    121b <reverse_sentence+0xeb>
jmp    1229 <reverse_sentence+0xf9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dc <reverse_sentence+0xac>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <reverse@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1278 <reverse_sentence+0x148>
jmp    127d <reverse_sentence+0x14d>
jmp    11ae <reverse_sentence+0x7e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_sentence>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1154 <reverse_sentence+0x24>
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0x2,%eax
jge    1169 <reverse_sentence+0x39>
lea    0xeae(%rip),%rdi
jmp    115b <reverse_sentence+0x2b>
lea    0xec9(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <puts@plt>
mov    %eax,%eax
lea    (%r14,%rax,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r14,%rdi
call   1030 <reverse@plt>
add    $0xffffffffffffffff,%r14
xor    %ebx,%ebx
movabs $0xffffffff00000000,%r15
ff ff ff
movabs $0x100000000,%r12
jmp    11af <reverse_sentence+0x7f>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   1030 <reverse@plt>
cmpb   $0x0,0x1(%r13)
je     1201 <reverse_sentence+0xd1>
mov    %rbx,%rax
shl    $0x20,%rax
add    %r15,%rax
movslq %ebx,%rdi
add    %r14,%rdi
nop
mov    %ebx,%ecx
add    %r12,%rax
cmpb   $0x20,0x1(%rdi)
lea    0x1(%rdi),%rdi
lea    0x1(%rcx),%ebx
je     11c0 <reverse_sentence+0x90>
sar    $0x20,%rax
movslq %ecx,%r13
add    %r14,%r13
mov    %rax,%rbx
testb  $0xdf,0x1(%r13)
je     11a0 <reverse_sentence+0x70>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0x1,%r13
testb  $0xdf,0x1(%r13)
jne    11f0 <reverse_sentence+0xc0>
jmp    11a0 <reverse_sentence+0x70>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"string is null!\0A\00"
@.str.1 = [37 x i8] c"this string only has one character!\0A\00"
define void @reverse_sentence(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %90
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp sle i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %90
22: ; preds = %15
%23 = load i8*, i8** %2
store i8* %23, i8** %8
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -1
store i8* %28, i8** %9
%29 = load i8*, i8** %8
%30 = load i8*, i8** %9
%31 = call i32 @reverse(i8* %29, i8* %30)
store i32 0, i32* %4
br label %32
32: ; preds = %22, %89
br label %33
33: ; preds = %41, %32
%34 = load i8*, i8** %2
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 32
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %33
44: ; preds = %33
%45 = load i32, i32* %4
store i32 %45, i32* %6
br label %46
46: ; preds = %64, %44
%47 = load i8*, i8** %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 32
br i1 %53, label %54, label %62
54: ; preds = %46
%55 = load i8*, i8** %2
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br label %62
62: ; preds = %54, %46
%63 = phi i1 [ false, %46 ], [ %61, %54 ]
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %46
67: ; preds = %62
%68 = load i32, i32* %4
store i32 %68, i32* %7
%69 = load i8*, i8** %2
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8* %72, i8** %8
%73 = load i8*, i8** %2
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = getelementptr inbounds i8, i8* %76, i64 -1
store i8* %77, i8** %9
%78 = load i8*, i8** %8
%79 = load i8*, i8** %9
%80 = call i32 @reverse(i8* %78, i8* %79)
%81 = load i8*, i8** %2
%82 = load i32, i32* %4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %67
br label %90
89: ; preds = %67
br label %32
90: ; preds = %13, %20, %88
ret void
}

LLVM IR (-O2):
@str = [36 x i8] c"this string only has one character!\00"
@str.2 = [16 x i8] c"string is null!\00"
define void @reverse_sentence(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %37, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 2
br i1 %5, label %37, label %6
6: ; preds = %3
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = tail call i32 @reverse(i8* %0, i8* %9)
br label %11
11: ; preds = %31, %6
%12 = phi i64 [ 0, %6 ], [ %26, %31 ]
%13 = shl i64 %12, 32
%14 = ashr exact i64 %13, 32
br label %15
15: ; preds = %15, %11
%16 = phi i64 [ %20, %15 ], [ %14, %11 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 32
%20 = add i64 %16, 1
br i1 %19, label %15, label %21
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %0, i64 %16
%23 = shl i64 %16, 32
%24 = ashr exact i64 %23, 32
br label %25
25: ; preds = %21, %29
%26 = phi i64 [ %24, %21 ], [ %30, %29 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
switch i8 %28, label %29 [
i8 32, label %31
i8 0, label %31
]
29: ; preds = %25
%30 = add i64 %26, 1
br label %25
31: ; preds = %25, %25
%32 = getelementptr inbounds i8, i8* %0, i64 %26
%33 = getelementptr inbounds i8, i8* %32, i64 -1
%34 = tail call i32 @reverse(i8* %22, i8* %33)
%35 = load i8, i8* %32
%36 = icmp eq i8 %35, 0
br i1 %36, label %40, label %11
37: ; preds = %3, %1
%38 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0), %3 ]
%39 = tail call i32 @puts(i8* dereferenceable(1) %38)
br label %40
40: ; preds = %31, %37
ret void
}