#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 *, ...);
void dodiv2m1(uint logd, uint logmsb) {
  printf("\tMOV     a1, a1, lsr #1\n");
  while (logd < 32) {
    printf("\tADD     a1, a1, a1, lsr #%d\n", logd);
    logd <<= 1;
  }
  printf("\tMOV     a1, a1, lsr #%d\n", logmsb - 1);
}


x86 assembly (clang, -O0):
<dodiv2m1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x20,-0x4(%rbp)
jge    1155 <dodiv2m1+0x45>
mov    -0x4(%rbp),%esi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112c <dodiv2m1+0x1c>
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dodiv2m1>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1f,%ebp
jg     1163 <dodiv2m1+0x43>
lea    0xebf(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebp,%ebp
cmp    $0x20,%ebp
jl     1150 <dodiv2m1+0x30>
add    $0xffffffff,%r14d
lea    0xeb0(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"\09MOV a1, a1, lsr\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 @dodiv2m1(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %9, %2
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = shl i32 %12, 1
store i32 %13, i32* %3
br label %6
14: ; preds = %6
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}

LLVM IR (-O2):
@.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"
@str = [24 x i8] c"\09MOV a1, a1, lsr\00"
define void @dodiv2m1(i32 %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = icmp slt i32 %0, 32
br i1 %4, label %5, label %10
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ %0, %2 ]
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = shl i32 %6, 1
%9 = icmp slt i32 %8, 32
br i1 %9, label %5, label %10
10: ; preds = %5, %2
%11 = add nsw i32 %1, -1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %11)
ret void
}