#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 */
struct buddy {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buddy_check_alloc(struct buddy *, unsigned int);
unsigned int buddy_map_size(struct buddy *);
void buddy_check_alloc_down(struct buddy *b, unsigned int node) {
  unsigned int i, count = 1;
  while (node < buddy_map_size(b)) {
    for (i = 0; i < count; i++)
      buddy_check_alloc(b, node + i);
    node <<= 1;
    count <<= 1;
  }
}


x86 assembly (clang, -O0):
<buddy_check_alloc_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <buddy_map_size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    1199 <buddy_check_alloc_down+0x79>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1182 <buddy_check_alloc_down+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    -0x10(%rbp),%esi
call   1030 <buddy_check_alloc@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1159 <buddy_check_alloc_down+0x39>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <buddy_check_alloc_down+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buddy_check_alloc_down>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
call   1040 <buddy_map_size@plt>
cmp    %r14d,%eax
jbe    1174 <buddy_check_alloc_down+0x54>
mov    $0x1,%r15d
jmp    1153 <buddy_check_alloc_down+0x33>
add    %r14d,%r14d
add    %r15d,%r15d
mov    %r12,%rdi
call   1040 <buddy_map_size@plt>
cmp    %eax,%r14d
jae    1174 <buddy_check_alloc_down+0x54>
test   %r15d,%r15d
je     1140 <buddy_check_alloc_down+0x20>
mov    %r14d,%ebp
mov    %r15d,%ebx
xchg   %ax,%ax
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <buddy_check_alloc@plt>
add    $0x1,%ebp
add    $0xffffffff,%ebx
jne    1160 <buddy_check_alloc_down+0x40>
jmp    1140 <buddy_check_alloc_down+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buddy = type { i32 }
define void @buddy_check_alloc_down(%struct.buddy* %0, i32 %1) {
%3 = alloca %struct.buddy*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.buddy* %0, %struct.buddy** %3
store i32 %1, i32* %4
store i32 1, i32* %6
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %4
%9 = load %struct.buddy*, %struct.buddy** %3
%10 = call i32 @buddy_map_size(%struct.buddy* %9)
%11 = icmp ult i32 %8, %10
br i1 %11, label %12, label %31
12: ; preds = %7
store i32 0, i32* %5
br label %13
13: ; preds = %23, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load %struct.buddy*, %struct.buddy** %3
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = add i32 %19, %20
%22 = call i32 @buddy_check_alloc(%struct.buddy* %18, i32 %21)
br label %23
23: ; preds = %17
%24 = load i32, i32* %5
%25 = add i32 %24, 1
store i32 %25, i32* %5
br label %13
26: ; preds = %13
%27 = load i32, i32* %4
%28 = shl i32 %27, 1
store i32 %28, i32* %4
%29 = load i32, i32* %6
%30 = shl i32 %29, 1
store i32 %30, i32* %6
br label %7
31: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.buddy = type { i32 }
define void @buddy_check_alloc_down(%struct.buddy* %0, i32 %1) {
%3 = tail call i32 @buddy_map_size(%struct.buddy* %0)
%4 = icmp ugt i32 %3, %1
br i1 %4, label %5, label %20
5: ; preds = %2, %15
%6 = phi i32 [ %17, %15 ], [ 1, %2 ]
%7 = phi i32 [ %16, %15 ], [ %1, %2 ]
%8 = icmp eq i32 %6, 0
br i1 %8, label %15, label %9
9: ; preds = %5, %9
%10 = phi i32 [ %13, %9 ], [ 0, %5 ]
%11 = add i32 %10, %7
%12 = tail call i32 @buddy_check_alloc(%struct.buddy* %0, i32 %11)
%13 = add nuw i32 %10, 1
%14 = icmp eq i32 %13, %6
br i1 %14, label %15, label %9
15: ; preds = %9, %5
%16 = shl i32 %7, 1
%17 = shl i32 %6, 1
%18 = tail call i32 @buddy_map_size(%struct.buddy* %0)
%19 = icmp ult i32 %16, %18
br i1 %19, label %5, label %20
20: ; preds = %15, %2
ret void
}