int iterativeGx(int n) {
  int fnm1, fnm2, fnm3, result = 0;
  if (n == 0)
    return 0;
  else if (n == 1)
    return 1;
  else if (n == 2)
    return 2;
  else
    fnm1 = iterativeGx(n - 1);
  fnm2 = iterativeGx(n - 2);
  fnm3 = iterativeGx(n - 3);
  result = fnm1 + fnm2 + fnm3;
  return (result);
}


x86 assembly (clang, -O0):
<iterativeGx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1138 <iterativeGx+0x28>
movl   $0x0,-0x4(%rbp)
jmp    11aa <iterativeGx+0x9a>
cmpl   $0x1,-0x8(%rbp)
jne    114e <iterativeGx+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    11aa <iterativeGx+0x9a>
cmpl   $0x2,-0x8(%rbp)
jne    1164 <iterativeGx+0x54>
movl   $0x2,-0x4(%rbp)
jmp    11aa <iterativeGx+0x9a>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <iterativeGx@plt>
mov    %eax,-0xc(%rbp)
jmp    1177 <iterativeGx+0x67>
jmp    117c <iterativeGx+0x6c>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1030 <iterativeGx@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x3,%edi
call   1030 <iterativeGx@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterativeGx>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %r14d,%r14d
cmp    $0x3,%ebx
jb     1142 <iterativeGx+0x32>
xchg   %ax,%ax
lea    -0x1(%rbx),%edi
call   1030 <iterativeGx@plt>
mov    %eax,%ebp
lea    -0x2(%rbx),%edi
call   1030 <iterativeGx@plt>
add    %r14d,%ebp
add    %eax,%ebp
add    $0xfffffffd,%ebx
mov    %ebp,%r14d
cmp    $0x3,%ebx
jae    1120 <iterativeGx+0x10>
add    %r14d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @iterativeGx(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %7
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %38
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %2
br label %38
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 2, i32* %2
br label %38
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = call i32 @iterativeGx(i32 %21)
store i32 %22, i32* %4
br label %23
23: ; preds = %19
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 2
%28 = call i32 @iterativeGx(i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 3
%31 = call i32 @iterativeGx(i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %6
%36 = add nsw i32 %34, %35
store i32 %36, i32* %7
%37 = load i32, i32* %7
store i32 %37, i32* %2
br label %38
38: ; preds = %25, %18, %14, %10
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @iterativeGx(i32 %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i32 [ 0, %1 ], [ %13, %6 ]
%4 = phi i32 [ %0, %1 ], [ %11, %6 ]
%5 = icmp ult i32 %4, 3
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = add nsw i32 %4, -1
%8 = tail call i32 @iterativeGx(i32 %7)
%9 = add nsw i32 %4, -2
%10 = tail call i32 @iterativeGx(i32 %9)
%11 = add nsw i32 %4, -3
%12 = add i32 %8, %3
%13 = add i32 %12, %10
br label %2
14: ; preds = %2
%15 = add nsw i32 %4, %3
ret i32 %15
}