char *word(index, str)
char str[];
{
  register char *cp;
  char *secbuf;
  register int c;
  static char retbuf[100];
  char *gword();
  cp = str;
  if ((c = index) > 0) {
    while (c-- > 0)
      cp = gword(cp, retbuf);
    return (retbuf);
  }
  if (c == 0)
    return ("");
  secbuf = (char *)alloca(strlen(str) + 1);
  strcpy(secbuf, str);
  rev(secbuf);
  cp = word(-index, secbuf);
  rev(cp);
  return (cp);
}


x86 assembly (clang, -O0):
<word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    11ba <word+0x6a>
jmp    117b <word+0x2b>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x0,%eax
jle    11aa <word+0x5a>
mov    -0x20(%rbp),%rdi
lea    0x2ec6(%rip),%rsi
mov    $0x0,%al
call   1070 <gword@plt>
mov    %rax,-0x20(%rbp)
jmp    117b <word+0x2b>
lea    0x2eaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1232 <word+0xe2>
cmpl   $0x0,-0x2c(%rbp)
jne    11d4 <word+0x84>
lea    0xe35(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1232 <word+0xe2>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rax
sub    %rcx,%rax
mov    %rax,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1040 <rev@plt>
xor    %edi,%edi
sub    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <word@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <rev@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<word>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
test   %edi,%edi
jle    118a <word+0x3a>
add    $0x1,%ebx
lea    0x2ef3(%rip),%r15
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <gword@plt>
mov    %rax,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <word+0x20>
jmp    11dc <word+0x8c>
je     11d5 <word+0x85>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r15
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <rev@plt>
neg    %ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <word@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <rev@plt>
jmp    11dc <word+0x8c>
lea    0xe24(%rip),%r15
mov    %r15,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@word.retbuf = internal global [100 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @word(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
store i8* %9, i8** %6
%10 = load i32, i32* %4
store i32 %10, i32* %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %2
br label %13
13: ; preds = %17, %12
%14 = load i32, i32* %8
%15 = add nsw i32 %14, -1
store i32 %15, i32* %8
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = call i8* (i8*, i8*, ...) bitcast (i8* (...)* @gword to i8* (i8*, i8*, ...)*)(i8* %18, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @word.retbuf, i64 0, i64 0))
store i8* %19, i8** %6
br label %13
20: ; preds = %13
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @word.retbuf, i64 0, i64 0), i8** %3
br label %42
21: ; preds = %2
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %42
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = add i64 %27, 1
%29 = alloca i8, i64 %28
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = load i8*, i8** %5
%32 = call i8* @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %7
%34 = call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %33)
%35 = load i32, i32* %4
%36 = sub nsw i32 0, %35
%37 = load i8*, i8** %7
%38 = call i8* @word(i32 %36, i8* %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %39)
%41 = load i8*, i8** %6
store i8* %41, i8** %3
br label %42
42: ; preds = %25, %24, %20
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@word.retbuf = internal global [100 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @word(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %10
4: ; preds = %2, %4
%5 = phi i32 [ %7, %4 ], [ %0, %2 ]
%6 = phi i8* [ %8, %4 ], [ %1, %2 ]
%7 = add nsw i32 %5, -1
%8 = tail call i8* (i8*, i8*, ...) bitcast (i8* (...)* @gword to i8* (i8*, i8*, ...)*)(i8* %6, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @word.retbuf, i64 0, i64 0))
%9 = icmp ugt i32 %5, 1
br i1 %9, label %4, label %21
10: ; preds = %2
%11 = icmp eq i32 %0, 0
br i1 %11, label %21, label %12
12: ; preds = %10
%13 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%14 = add i64 %13, 1
%15 = alloca i8, i64 %14
%16 = call i8* @strcpy(i8* %15, i8* dereferenceable(1) %1)
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %15)
%18 = sub nsw i32 0, %0
%19 = call i8* @word(i32 %18, i8* %15)
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %19)
br label %21
21: ; preds = %4, %10, %12
%22 = phi i8* [ %19, %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([100 x i8], [100 x i8]* @word.retbuf, i64 0, i64 0), %4 ]
ret i8* %22
}