long long int russian_recursive(long long int a, long long int b) {
  if (a == 0)
    return 0;
  if (a % 2 == 0)
    return 2 * russian_recursive(a / 2, b);
  return b + 2 * russian_recursive((a - 1) / 2, b);
}


x86 assembly (clang, -O0):
<russian_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <russian_recursive+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11af <russian_recursive+0x9f>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1177 <russian_recursive+0x67>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <russian_recursive@plt>
shl    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <russian_recursive+0x9f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <russian_recursive@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<russian_recursive>:
push   %rbx
test   %rdi,%rdi
je     113c <russian_recursive+0x2c>
mov    %rsi,%rbx
test   $0x1,%dil
jne    1140 <russian_recursive+0x30>
mov    %rdi,%rax
shr    $0x3f,%rax
add    %rdi,%rax
sar    %rax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <russian_recursive@plt>
add    %rax,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
lea    -0x1(%rdi),%rax
shr    $0x3f,%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
sar    %rdi
mov    %rbx,%rsi
call   1030 <russian_recursive@plt>
lea    (%rbx,%rax,2),%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @russian_recursive(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i64 0, i64* %3
br label %28
9: ; preds = %2
%10 = load i64, i64* %4
%11 = srem i64 %10, 2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i64, i64* %4
%15 = sdiv i64 %14, 2
%16 = load i64, i64* %5
%17 = call i64 @russian_recursive(i64 %15, i64 %16)
%18 = mul nsw i64 2, %17
store i64 %18, i64* %3
br label %28
19: ; preds = %9
%20 = load i64, i64* %5
%21 = load i64, i64* %4
%22 = sub nsw i64 %21, 1
%23 = sdiv i64 %22, 2
%24 = load i64, i64* %5
%25 = call i64 @russian_recursive(i64 %23, i64 %24)
%26 = mul nsw i64 2, %25
%27 = add nsw i64 %20, %26
store i64 %27, i64* %3
br label %28
28: ; preds = %19, %13, %8
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
define i64 @russian_recursive(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = and i64 %0, 1
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %13
7: ; preds = %2, %13, %9
%8 = phi i64 [ %12, %9 ], [ %18, %13 ], [ 0, %2 ]
ret i64 %8
9: ; preds = %4
%10 = sdiv i64 %0, 2
%11 = tail call i64 @russian_recursive(i64 %10, i64 %1)
%12 = shl nsw i64 %11, 1
br label %7
13: ; preds = %4
%14 = add nsw i64 %0, -1
%15 = sdiv i64 %14, 2
%16 = tail call i64 @russian_recursive(i64 %15, i64 %1)
%17 = shl nsw i64 %16, 1
%18 = add nsw i64 %17, %1
br label %7
}