#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 block {
  int dummy;
};

/* Variables and functions */
size_t blk_size(struct block *);
int /*<<< orphan*/ mark_block_free(struct block *, size_t);
int /*<<< orphan*/ mark_block_used(struct block *, size_t);
struct block *next_blk(struct block *);
void place(struct block *bp, size_t asize) {
  size_t csize = blk_size(bp);
  if ((csize - asize) >= 4) {
    mark_block_used(bp, asize);
    bp = next_blk(bp);
    mark_block_free(bp, csize - asize);
  } else {
    mark_block_used(bp, csize);
  }
}


x86 assembly (clang, -O0):
<place>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <blk_size@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    $0x4,%rax
jb     119f <place+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <mark_block_used@plt>
mov    -0x8(%rbp),%rdi
call   1030 <next_blk@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x10(%rbp),%rsi
call   1040 <mark_block_free@plt>
jmp    11ac <place+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <mark_block_used@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<place>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <blk_size@plt>
mov    %rax,%rbx
sub    %r15,%rbx
cmp    $0x4,%rbx
jb     117f <place+0x3f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <mark_block_used@plt>
mov    %r14,%rdi
call   1030 <next_blk@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <mark_block_free@plt>
mov    %r14,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <mark_block_used@plt>

LLVM IR (-O0):
%struct.block = type { i32 }
define void @place(%struct.block* %0, i64 %1) {
%3 = alloca %struct.block*
%4 = alloca i64
%5 = alloca i64
store %struct.block* %0, %struct.block** %3
store i64 %1, i64* %4
%6 = load %struct.block*, %struct.block** %3
%7 = call i64 @blk_size(%struct.block* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = sub i64 %8, %9
%11 = icmp uge i64 %10, 4
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load %struct.block*, %struct.block** %3
%14 = load i64, i64* %4
%15 = call i32 @mark_block_used(%struct.block* %13, i64 %14)
%16 = load %struct.block*, %struct.block** %3
%17 = call %struct.block* @next_blk(%struct.block* %16)
store %struct.block* %17, %struct.block** %3
%18 = load %struct.block*, %struct.block** %3
%19 = load i64, i64* %5
%20 = load i64, i64* %4
%21 = sub i64 %19, %20
%22 = call i32 @mark_block_free(%struct.block* %18, i64 %21)
br label %27
23: ; preds = %2
%24 = load %struct.block*, %struct.block** %3
%25 = load i64, i64* %5
%26 = call i32 @mark_block_used(%struct.block* %24, i64 %25)
br label %27
27: ; preds = %23, %12
ret void
}

LLVM IR (-O2):
%struct.block = type { i32 }
define void @place(%struct.block* %0, i64 %1) {
%3 = tail call i64 @blk_size(%struct.block* %0)
%4 = sub i64 %3, %1
%5 = icmp ugt i64 %4, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @mark_block_used(%struct.block* %0, i64 %1)
%8 = tail call %struct.block* @next_blk(%struct.block* %0)
%9 = tail call i32 @mark_block_free(%struct.block* %8, i64 %4)
br label %12
10: ; preds = %2
%11 = tail call i32 @mark_block_used(%struct.block* %0, i64 %3)
br label %12
12: ; preds = %10, %6
ret void
}