#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*/ printb(int);
int moltiplication(int a, int b) {
  printb(a);
  printb(b);
  int c = 0;
  while (b != 0) {
    if ((b & 1) != 0)
      c += a;
    a = a << 1;
    printb(a);
    b = b >> 1;
    printb(b);
  }
  printb(c);
  return c;
}


x86 assembly (clang, -O0):
<moltiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <printb@plt>
mov    -0x8(%rbp),%edi
call   1030 <printb@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     117e <moltiplication+0x6e>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1157 <moltiplication+0x47>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <printb@plt>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <printb@plt>
jmp    1135 <moltiplication+0x25>
mov    -0xc(%rbp),%edi
call   1030 <printb@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moltiplication>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
call   1030 <printb@plt>
mov    %r14d,%edi
call   1030 <printb@plt>
xor    %r15d,%r15d
test   %r14d,%r14d
je     1168 <moltiplication+0x58>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%eax
and    $0x1,%eax
neg    %eax
and    %ebx,%eax
add    %eax,%r15d
add    %ebx,%ebx
mov    %ebx,%edi
call   1030 <printb@plt>
sar    %ebp
mov    %ebp,%edi
call   1030 <printb@plt>
cmp    $0x1,%r14d
mov    %ebp,%r14d
ja     1140 <moltiplication+0x30>
mov    %r15d,%edi
call   1030 <printb@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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