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 *)malloc(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    11ca <word+0x6a>
jmp    118b <word+0x2b>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x0,%eax
jle    11ba <word+0x5a>
mov    -0x20(%rbp),%rdi
lea    0x2eb6(%rip),%rsi
mov    $0x0,%al
call   1080 <gword@plt>
mov    %rax,-0x20(%rbp)
jmp    118b <word+0x2b>
lea    0x2e9f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123a <word+0xda>
cmpl   $0x0,-0x2c(%rbp)
jne    11e4 <word+0x84>
lea    0xe25(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123a <word+0xda>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
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   1070 <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
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<word>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
test   %edi,%edi
jle    119a <word+0x3a>
add    $0x1,%ebx
lea    0x2ee8(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <gword@plt>
mov    %rax,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1180 <word+0x20>
jmp    11e7 <word+0x87>
je     11e0 <word+0x80>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%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   1070 <word@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <rev@plt>
jmp    11e7 <word+0x87>
lea    0xe19(%rip),%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
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 = call i8* @malloc(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 %12
10: ; preds = %2
%11 = icmp eq i32 %0, 0
br i1 %11, label %12, label %14
12: ; preds = %4, %10, %14
%13 = phi i8* [ %21, %14 ], [ 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* %13
14: ; preds = %10
%15 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%16 = add i64 %15, 1
%17 = tail call i8* @malloc(i64 %16)
%18 = tail call i8* @strcpy(i8* dereferenceable(1) %17, i8* dereferenceable(1) %1)
%19 = tail call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %17)
%20 = sub nsw i32 0, %0
%21 = tail call i8* @word(i32 %20, i8* %17)
%22 = tail call i32 (i8*, ...) bitcast (i32 (...)* @rev to i32 (i8*, ...)*)(i8* %21)
br label %12
}