#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 strlen(char *);
int find_length_last_word_in_str(char *s) {
  int len;
  int index;
  int last_word_len;
  if (!s || !strlen(s)) {
    return (0);
  }
  len = strlen(s);
  index = len - 1;
  last_word_len = 0;
  while ((index >= 0) && (s[index] == ' ')) {
    --index;
  }
  while ((index >= 0) && (s[index] != ' ')) {
    --index;
    ++last_word_len;
  }
  return (last_word_len);
}


x86 assembly (clang, -O0):
<find_length_last_word_in_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1139 <find_length_last_word_in_str+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1145 <find_length_last_word_in_str+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <find_length_last_word_in_str+0xe9>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jl     1185 <find_length_last_word_in_str+0x75>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1195 <find_length_last_word_in_str+0x85>
jmp    11a3 <find_length_last_word_in_str+0x93>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1161 <find_length_last_word_in_str+0x51>
jmp    11a8 <find_length_last_word_in_str+0x98>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1e(%rbp)
jl     11cc <find_length_last_word_in_str+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    11dc <find_length_last_word_in_str+0xcc>
jmp    11f3 <find_length_last_word_in_str+0xe3>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a8 <find_length_last_word_in_str+0x98>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_length_last_word_in_str>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1185 <find_length_last_word_in_str+0x75>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     1185 <find_length_last_word_in_str+0x75>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0xffffffffffffffff,%rcx
mov    %eax,%edx
add    $0x1,%edx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%esi
test   %esi,%esi
jle    1185 <find_length_last_word_in_str+0x75>
mov    %ecx,%esi
add    $0xffffffffffffffff,%rcx
add    $0xffffffff,%edx
add    $0xffffffff,%eax
cmpb   $0x20,(%r14,%rsi,1)
je     1140 <find_length_last_word_in_str+0x30>
add    $0x1,%ecx
xor    %ebx,%ebx
test   %eax,%eax
cmovns %ebx,%eax
sub    %eax,%edx
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
cmpb   $0x20,(%r14,%rax,1)
je     1185 <find_length_last_word_in_str+0x75>
add    $0xffffffff,%ecx
add    $0x1,%ebx
cmp    %ebx,%edx
jne    1170 <find_length_last_word_in_str+0x60>
mov    %edx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @find_length_last_word_in_str(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %1
store i32 0, i32* %2
br label %56
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %5
store i32 0, i32* %6
br label %19
19: ; preds = %32, %14
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 32
br label %30
30: ; preds = %22, %19
%31 = phi i1 [ false, %19 ], [ %29, %22 ]
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
br label %19
35: ; preds = %30
br label %36
36: ; preds = %49, %35
%37 = load i32, i32* %5
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i8*, i8** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 32
br label %47
47: ; preds = %39, %36
%48 = phi i1 [ false, %36 ], [ %46, %39 ]
br i1 %48, label %49, label %54
49: ; preds = %47
%50 = load i32, i32* %5
%51 = add nsw i32 %50, -1
store i32 %51, i32* %5
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %36
54: ; preds = %47
%55 = load i32, i32* %6
store i32 %55, i32* %2
br label %56
56: ; preds = %54, %13
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @find_length_last_word_in_str(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %35, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %35, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %14, %6
%10 = phi i64 [ %11, %14 ], [ %8, %6 ]
%11 = add nsw i64 %10, -1
%12 = trunc i64 %10 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %9
%15 = and i64 %11, 4294967295
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 32
br i1 %18, label %9, label %19
19: ; preds = %14
%20 = trunc i64 %11 to i32
%21 = add i32 %20, 1
%22 = call i32 @llvm.smin.i32(i32 %20, i32 0)
%23 = sub i32 %21, %22
br label %24
24: ; preds = %19, %31
%25 = phi i32 [ %33, %31 ], [ 0, %19 ]
%26 = phi i32 [ %32, %31 ], [ %20, %19 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 32
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = add nsw i32 %26, -1
%33 = add nuw i32 %25, 1
%34 = icmp eq i32 %33, %23
br i1 %34, label %35, label %24
35: ; preds = %9, %31, %24, %1, %3
%36 = phi i32 [ 0, %3 ], [ 0, %1 ], [ %23, %31 ], [ %25, %24 ], [ 0, %9 ]
ret i32 %36
}