#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 sb {
  int dummy;
};
struct buffer_head {
  int dummy;
};
struct bnode {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bfree(struct sb *, int /*<<< orphan*/, int);
scalar_t__ bnode_merge_nodes(struct sb *, struct bnode *, struct bnode *);
struct bnode *bufdata(struct buffer_head *);
int /*<<< orphan*/ bufindex(struct buffer_head *);
int /*<<< orphan*/ log_bnode_merge(struct sb *, int /*<<< orphan*/,
                                   int /*<<< orphan*/);
int try_bnode_merge(struct sb *sb, struct buffer_head *intobuf,
                    struct buffer_head *frombuf) {
  struct bnode *into = bufdata(intobuf);
  struct bnode *from = bufdata(frombuf);
  if (bnode_merge_nodes(sb, into, from)) {
    bfree(sb, bufindex(frombuf), 1);
    log_bnode_merge(sb, bufindex(frombuf), bufindex(intobuf));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<try_bnode_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <bufdata@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <bufdata@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <bnode_merge_nodes@plt>
cmp    $0x0,%rax
je     11f1 <try_bnode_merge+0xa1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <bufindex@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1060 <bfree@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <bufindex@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <bufindex@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
call   1030 <log_bnode_merge@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f8 <try_bnode_merge+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_bnode_merge>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1070 <bufdata@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <bufdata@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1050 <bnode_merge_nodes@plt>
test   %rax,%rax
je     11c2 <try_bnode_merge+0x72>
mov    %rbx,%rdi
call   1040 <bufindex@plt>
mov    $0x1,%ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1060 <bfree@plt>
mov    %rbx,%rdi
call   1040 <bufindex@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <bufindex@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <log_bnode_merge@plt>
jmp    11c4 <try_bnode_merge+0x74>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sb = type { i32 }
%struct.buffer_head = type { i32 }
%struct.bnode = type { i32 }
define i32 @try_bnode_merge(%struct.sb* %0, %struct.buffer_head* %1, %struct.buffer_head* %2) {
%4 = alloca i32
%5 = alloca %struct.sb*
%6 = alloca %struct.buffer_head*
%7 = alloca %struct.buffer_head*
%8 = alloca %struct.bnode*
%9 = alloca %struct.bnode*
store %struct.sb* %0, %struct.sb** %5
store %struct.buffer_head* %1, %struct.buffer_head** %6
store %struct.buffer_head* %2, %struct.buffer_head** %7
%10 = load %struct.buffer_head*, %struct.buffer_head** %6
%11 = call %struct.bnode* @bufdata(%struct.buffer_head* %10)
store %struct.bnode* %11, %struct.bnode** %8
%12 = load %struct.buffer_head*, %struct.buffer_head** %7
%13 = call %struct.bnode* @bufdata(%struct.buffer_head* %12)
store %struct.bnode* %13, %struct.bnode** %9
%14 = load %struct.sb*, %struct.sb** %5
%15 = load %struct.bnode*, %struct.bnode** %8
%16 = load %struct.bnode*, %struct.bnode** %9
%17 = call i64 @bnode_merge_nodes(%struct.sb* %14, %struct.bnode* %15, %struct.bnode* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %3
%20 = load %struct.sb*, %struct.sb** %5
%21 = load %struct.buffer_head*, %struct.buffer_head** %7
%22 = call i32 @bufindex(%struct.buffer_head* %21)
%23 = call i32 @bfree(%struct.sb* %20, i32 %22, i32 1)
%24 = load %struct.sb*, %struct.sb** %5
%25 = load %struct.buffer_head*, %struct.buffer_head** %7
%26 = call i32 @bufindex(%struct.buffer_head* %25)
%27 = load %struct.buffer_head*, %struct.buffer_head** %6
%28 = call i32 @bufindex(%struct.buffer_head* %27)
%29 = call i32 @log_bnode_merge(%struct.sb* %24, i32 %26, i32 %28)
store i32 1, i32* %4
br label %31
30: ; preds = %3
store i32 0, i32* %4
br label %31
31: ; preds = %30, %19
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.sb = type { i32 }
%struct.buffer_head = type { i32 }
%struct.bnode = type { i32 }
define i32 @try_bnode_merge(%struct.sb* %0, %struct.buffer_head* %1, %struct.buffer_head* %2) {
%4 = tail call %struct.bnode* @bufdata(%struct.buffer_head* %1)
%5 = tail call %struct.bnode* @bufdata(%struct.buffer_head* %2)
%6 = tail call i64 @bnode_merge_nodes(%struct.sb* %0, %struct.bnode* %4, %struct.bnode* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = tail call i32 @bufindex(%struct.buffer_head* %2)
%10 = tail call i32 @bfree(%struct.sb* %0, i32 %9, i32 1)
%11 = tail call i32 @bufindex(%struct.buffer_head* %2)
%12 = tail call i32 @bufindex(%struct.buffer_head* %1)
%13 = tail call i32 @log_bnode_merge(%struct.sb* %0, i32 %11, i32 %12)
br label %14
14: ; preds = %3, %8
%15 = phi i32 [ 1, %8 ], [ 0, %3 ]
ret i32 %15
}