#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 _mmpool_impl {
  int dummy;
};
struct _block_head {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _block_size_by_idx(struct _mmpool_impl *, long);
struct _block_head *_make_block(void *, int /*<<< orphan*/);
long _return_free_node_to_head(struct _mmpool_impl *, struct _block_head *);
long _mmp_init_block(struct _mmpool_impl *mmpi, void *blk, long head_idx) {
  struct _block_head *hd = _make_block(blk, _block_size_by_idx(mmpi, head_idx));
  if (!hd)
    goto error_ret;
  return _return_free_node_to_head(mmpi, hd);
error_ret:
  return -1;
}


x86 assembly (clang, -O0):
<_mmp_init_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <_block_size_by_idx@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <_make_block@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1178 <_mmp_init_block+0x48>
jmp    118e <_mmp_init_block+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <_return_free_node_to_head@plt>
mov    %rax,-0x8(%rbp)
jmp    1196 <_mmp_init_block+0x66>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mmp_init_block>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1050 <_block_size_by_idx@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_make_block@plt>
test   %rax,%rax
je     1163 <_mmp_init_block+0x33>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <_return_free_node_to_head@plt>
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct._mmpool_impl = type { i32 }
%struct._block_head = type { i32 }
define i64 @_mmp_init_block(%struct._mmpool_impl* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca %struct._mmpool_impl*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct._block_head*
store %struct._mmpool_impl* %0, %struct._mmpool_impl** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %6
%10 = load %struct._mmpool_impl*, %struct._mmpool_impl** %5
%11 = load i64, i64* %7
%12 = call i32 @_block_size_by_idx(%struct._mmpool_impl* %10, i64 %11)
%13 = call %struct._block_head* @_make_block(i8* %9, i32 %12)
store %struct._block_head* %13, %struct._block_head** %8
%14 = load %struct._block_head*, %struct._block_head** %8
%15 = icmp ne %struct._block_head* %14, null
br i1 %15, label %17, label %16
16: ; preds = %3
br label %21
17: ; preds = %3
%18 = load %struct._mmpool_impl*, %struct._mmpool_impl** %5
%19 = load %struct._block_head*, %struct._block_head** %8
%20 = call i64 @_return_free_node_to_head(%struct._mmpool_impl* %18, %struct._block_head* %19)
store i64 %20, i64* %4
br label %22
21: ; preds = %16
store i64 -1, i64* %4
br label %22
22: ; preds = %21, %17
%23 = load i64, i64* %4
ret i64 %23
}

LLVM IR (-O2):
%struct._mmpool_impl = type { i32 }
%struct._block_head = type { i32 }
define i64 @_mmp_init_block(%struct._mmpool_impl* %0, i8* %1, i64 %2) {
%4 = tail call i32 @_block_size_by_idx(%struct._mmpool_impl* %0, i64 %2)
%5 = tail call %struct._block_head* @_make_block(i8* %1, i32 %4)
%6 = icmp eq %struct._block_head* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i64 @_return_free_node_to_head(%struct._mmpool_impl* %0, %struct._block_head* %5)
br label %9
9: ; preds = %3, %7
%10 = phi i64 [ %8, %7 ], [ -1, %3 ]
ret i64 %10
}