#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 */
typedef int uint32_t;

/* Variables and functions */
int half_add(int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
uint32_t multipliser32(uint32_t a, uint32_t b, uint32_t ab) {
  printf("a = %x, b = %x, ab = %x\n", a, b, ab);
  if (b == 0) {
    return ab;
  } else {
    return multipliser32(a, ~-b, half_add(ab, a));
  }
}


x86 assembly (clang, -O0):
<multipliser32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    116b <multipliser32+0x3b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <multipliser32+0x67>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
sub    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <half_add@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
call   1030 <multipliser32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multipliser32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xecb(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
test   %ebp,%ebp
je     1170 <multipliser32+0x50>
add    $0xffffffff,%ebp
lea    0xeb1(%rip),%r15
nop
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <half_add@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jb     1150 <multipliser32+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"a = %x, b = %x, ab = %x\0A\00"
define i32 @multipliser32(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = load i32, i32* %7
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9, i32 %10)
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %7
store i32 %15, i32* %4
br label %25
16: ; preds = %3
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = sub nsw i32 0, %18
%20 = xor i32 %19, -1
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = call i32 @half_add(i32 %21, i32 %22)
%24 = call i32 @multipliser32(i32 %17, i32 %20, i32 %23)
store i32 %24, i32* %4
br label %25
25: ; preds = %16, %14
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [25 x i8] c"a = %x, b = %x, ab = %x\0A\00"
define i32 @multipliser32(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
%5 = icmp eq i32 %1, 0
br i1 %5, label %13, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %10, %6 ], [ %2, %3 ]
%8 = phi i32 [ %9, %6 ], [ %1, %3 ]
%9 = add i32 %8, -1
%10 = tail call i32 @half_add(i32 %7, i32 %0)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %9, i32 %10)
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %6
13: ; preds = %6, %3
%14 = phi i32 [ %2, %3 ], [ %10, %6 ]
ret i32 %14
}