#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 const *);
int /*<<< orphan*/ printf(char *, char const *, int);
int main(int argc, char **argv) {
  const char *p;
  p = "hello world";
  printf("%s, %d\n", p, lengthOfLastWord(p));
  p = "a";
  printf("%s, %d\n", p, lengthOfLastWord(p));
  p = "              ";
  printf("%s, %d\n", p, lengthOfLastWord(p));
  if (argc > 1) {
    p = argv[1];
    printf("%s, %d\n", p, lengthOfLastWord(p));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
lea    0xea9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11f9 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lengthOfLastWord@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xecc(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
lea    0xec9(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xebd(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xea3(%rip),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
cmp    $0x2,%r15d
jl     11ab <main+0x8b>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1030 <lengthOfLastWord@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [8 x i8] c"%s, %d\0A\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [15 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = load i8*, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @lengthOfLastWord(i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %9)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @lengthOfLastWord(i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %13)
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %6
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = call i32 @lengthOfLastWord(i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %17)
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %29
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = load i8*, i8** %6
%27 = call i32 @lengthOfLastWord(i8* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %27)
br label %29
29: ; preds = %21, %2
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [8 x i8] c"%s, %d\0A\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [15 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @lengthOfLastWord(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @lengthOfLastWord(i8* %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13)
br label %15
15: ; preds = %10, %2
ret i32 0
}