#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 uint;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
void dodiv2p1(uint logd, uint logmsb) {
  printf("\tSUB     a1, a1, a1, lsr #%d\n", logd);
  while (logd < 16) {
    logd <<= 1;
    printf("\tADD     a1, a1, a1, lsr #%d\n", logd);
  }
  printf("\tMOV     a1, a1, lsr #%d\n", logmsb);
}


x86 assembly (clang, -O0):
<dodiv2p1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xed8(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x10,-0x4(%rbp)
jge    1154 <dodiv2p1+0x44>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xed4(%rip),%rdi
call   1030 <printf@plt>
jmp    112d <dodiv2p1+0x1d>
mov    -0x8(%rbp),%esi
lea    0xede(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dodiv2p1>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xee0(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
cmp    $0xf,%ebp
jg     1151 <dodiv2p1+0x41>
lea    0xeeb(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
cmp    $0x10,%ebp
jl     1140 <dodiv2p1+0x30>
lea    0xee4(%rip),%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"\09SUB a1, a1, a1, lsr #%d\0A\00"
@.str.1 = [30 x i8] c"\09ADD a1, a1, a1, lsr #%d\0A\00"
@.str.2 = [26 x i8] c"\09MOV a1, a1, lsr #%d\0A\00"
define void @dodiv2p1(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %10, %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 16
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* %3
%12 = shl i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %7
15: ; preds = %7
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"\09SUB a1, a1, a1, lsr #%d\0A\00"
@.str.1 = [30 x i8] c"\09ADD a1, a1, a1, lsr #%d\0A\00"
@.str.2 = [26 x i8] c"\09MOV a1, a1, lsr #%d\0A\00"
define void @dodiv2p1(i32 %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp slt i32 %0, 16
br i1 %4, label %5, label %10
5: ; preds = %2, %5
%6 = phi i32 [ %7, %5 ], [ %0, %2 ]
%7 = shl i32 %6, 1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %7, 16
br i1 %9, label %5, label %10
10: ; preds = %5, %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %1)
ret void
}