#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*/ mb_clear_bit(int, void *);
int /*<<< orphan*/ mb_set_bit(int, void *);
scalar_t__ mb_test_bit(int, void *);
__attribute__((always_)) __attribute__((no_instrument_function)) int
mb_buddy_adjust_border(int *bit, void *bitmap, int side) {
  if (mb_test_bit(*bit + side, bitmap)) {
    mb_clear_bit(*bit, bitmap);
    (*bit) -= side;
    return 1;
  } else {
    (*bit) += side;
    mb_set_bit(*bit, bitmap);
    return -1;
  }
}


x86 assembly (clang, -O0):
<mb_buddy_adjust_border>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <mb_test_bit@plt>
cmp    $0x0,%rax
je     1187 <mb_buddy_adjust_border+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1050 <mb_clear_bit@plt>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11a8 <mb_buddy_adjust_border+0x78>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <mb_set_bit@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mb_buddy_adjust_border>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
add    %edx,%edi
call   1030 <mb_test_bit@plt>
mov    (%rbx),%edi
test   %rax,%rax
je     115d <mb_buddy_adjust_border+0x2d>
mov    %r14,%rsi
call   1050 <mb_clear_bit@plt>
sub    %ebp,(%rbx)
mov    $0x1,%eax
jmp    116e <mb_buddy_adjust_border+0x3e>
add    %ebp,%edi
mov    %edi,(%rbx)
mov    %r14,%rsi
call   1040 <mb_set_bit@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mb_buddy_adjust_border(i32* nocapture %0, i8* %1, i32 %2) {
%4 = load i32, i32* %0
%5 = add nsw i32 %4, %2
%6 = tail call i64 @mb_test_bit(i32 %5, i8* %1)
%7 = icmp eq i64 %6, 0
%8 = load i32, i32* %0
br i1 %7, label %13, label %9
9: ; preds = %3
%10 = tail call i32 @mb_clear_bit(i32 %8, i8* %1)
%11 = load i32, i32* %0
%12 = sub nsw i32 %11, %2
store i32 %12, i32* %0
br label %16
13: ; preds = %3
%14 = add nsw i32 %8, %2
store i32 %14, i32* %0
%15 = tail call i32 @mb_set_bit(i32 %14, i8* %1)
br label %16
16: ; preds = %13, %9
%17 = phi i32 [ 1, %9 ], [ -1, %13 ]
ret i32 %17
}