#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 lengthOfLastWord(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int main(void) {
  char *s1 = "Hello world";
  char *s2 = "    ";
  char *s3 = "a   ";
  char *s4 = "a";
  printf("%s: %d\n", s1, lengthOfLastWord(s1));
  printf("%s: %d\n", s2, lengthOfLastWord(s2));
  printf("%s: %d\n", s3, lengthOfLastWord(s3));
  printf("%s: %d\n", s4, lengthOfLastWord(s4));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
lea    0xede(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xebe(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xea7(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xe90(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [5 x i8] c" \00"
@.str.2 = [5 x i8] c"a \00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [8 x i8] c"%s: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @lengthOfLastWord(i8* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32 %8)
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @lengthOfLastWord(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 %12)
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @lengthOfLastWord(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %14, i32 %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @lengthOfLastWord(i8* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %18, i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [5 x i8] c" \00"
@.str.2 = [5 x i8] c"a \00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [8 x i8] c"%s: %d\0A\00"
define i32 @main() {
%1 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %7)
ret i32 0
}