#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 /*<<< orphan*/ printf(char *, int, int, int, int);
int multiply_recursive(int x, int y) {
  if (y == 0) {
    return 0;
  } else {
    int prev = multiply_recursive(x, y >> 1);
    int v = (prev << 1) + ((y & 1) ? x : 0);
    printf("(%d << 1) + ((%d & 1) ? %d : 0) = %d\n", prev, y, x, v);
    return v;
  }
}


x86 assembly (clang, -O0):
<multiply_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1144 <multiply_recursive+0x24>
movl   $0x0,-0x4(%rbp)
jmp    11ac <multiply_recursive+0x8c>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
sar    $0x1,%esi
call   1040 <multiply_recursive@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1178 <multiply_recursive+0x58>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <multiply_recursive+0x62>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <multiply_recursive+0x62>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_recursive>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
je     1159 <multiply_recursive+0x39>
mov    %esi,%ebp
mov    %edi,%r14d
sar    %esi
call   1040 <multiply_recursive@plt>
mov    %ebp,%ecx
and    $0x1,%ecx
neg    %ecx
and    %r14d,%ecx
lea    (%rcx,%rax,2),%ebx
lea    0xeb8(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %ebx,%r8d
call   1030 <printf@plt>
jmp    115b <multiply_recursive+0x3b>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"(%d << 1) + ((%d & 1) ? %d : 0) = %d\0A\00"
define i32 @multiply_recursive(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = ashr i32 %13, 1
%15 = call i32 @multiply_recursive(i32 %12, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = shl i32 %16, 1
%18 = load i32, i32* %5
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = load i32, i32* %4
br label %24
23: ; preds = %11
br label %24
24: ; preds = %23, %21
%25 = phi i32 [ %22, %21 ], [ 0, %23 ]
%26 = add nsw i32 %17, %25
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = load i32, i32* %7
%31 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %7
store i32 %32, i32* %3
br label %33
33: ; preds = %24, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [38 x i8] c"(%d << 1) + ((%d & 1) ? %d : 0) = %d\0A\00"
define i32 @multiply_recursive(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2, %6
%5 = phi i32 [ %13, %6 ], [ 0, %2 ]
ret i32 %5
6: ; preds = %2
%7 = ashr i32 %1, 1
%8 = tail call i32 @multiply_recursive(i32 %0, i32 %7)
%9 = shl i32 %8, 1
%10 = and i32 %1, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 0, i32 %0
%13 = add nsw i32 %9, %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %1, i32 %0, i32 %13)
br label %4
}