#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 feed_heap {
  int dummy;
};
struct feed_client {
  int dummy;
};

/* Variables and functions */
struct feed_heap *feed_client_get_heap(struct feed_client *const);
void *feed_heap_alloc(struct feed_heap *, unsigned long const);
int /*<<< orphan*/ feed_heap_free(struct feed_heap *, void *);
char stub1(void *const, struct feed_client *const, void const *const);
void *feed_object_create(struct feed_client *const p_client,
                         unsigned long int const i_buf_len,
                         char (*p_init_cb)(void *const p_buf,
                                           struct feed_client *const p_client,
                                           void const *const p_descriptor),
                         void const *const p_descriptor) {
  void *p_buf;
  struct feed_heap *p_heap;
  p_heap = feed_client_get_heap(p_client);
  p_buf = feed_heap_alloc(p_heap, i_buf_len);
  if (p_buf) {
    if ((*p_init_cb)(p_buf, p_client, p_descriptor)) {
    } else {
      feed_heap_free(p_heap, p_buf);
      p_buf = (void *)(0);
    }
  }
  return p_buf;
}


x86 assembly (clang, -O0):
<feed_object_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feed_client_get_heap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <feed_heap_alloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11aa <feed_object_create+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   *%rax
cmp    $0x0,%al
je     1190 <feed_object_create+0x60>
jmp    11a5 <feed_object_create+0x75>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <feed_heap_free@plt>
movq   $0x0,-0x28(%rbp)
jmp    11aa <feed_object_create+0x7a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feed_object_create>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
call   1040 <feed_client_get_heap@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <feed_heap_alloc@plt>
test   %rax,%rax
je     117b <feed_object_create+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   *%r15
test   %al,%al
jne    117d <feed_object_create+0x4d>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <feed_heap_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.feed_client = type { i32 }
%struct.feed_heap = type { i32 }
define i8* @feed_object_create(%struct.feed_client* %0, i64 %1, i8 (i8*, %struct.feed_client*, i8*)* %2, i8* %3) {
%5 = alloca %struct.feed_client*
%6 = alloca i64
%7 = alloca i8 (i8*, %struct.feed_client*, i8*)*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.feed_heap*
store %struct.feed_client* %0, %struct.feed_client** %5
store i64 %1, i64* %6
store i8 (i8*, %struct.feed_client*, i8*)* %2, i8 (i8*, %struct.feed_client*, i8*)** %7
store i8* %3, i8** %8
%11 = load %struct.feed_client*, %struct.feed_client** %5
%12 = call %struct.feed_heap* @feed_client_get_heap(%struct.feed_client* %11)
store %struct.feed_heap* %12, %struct.feed_heap** %10
%13 = load %struct.feed_heap*, %struct.feed_heap** %10
%14 = load i64, i64* %6
%15 = call i8* @feed_heap_alloc(%struct.feed_heap* %13, i64 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %4
%19 = load i8 (i8*, %struct.feed_client*, i8*)*, i8 (i8*, %struct.feed_client*, i8*)** %7
%20 = load i8*, i8** %9
%21 = load %struct.feed_client*, %struct.feed_client** %5
%22 = load i8*, i8** %8
%23 = call signext i8 %19(i8* %20, %struct.feed_client* %21, i8* %22)
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br label %30
26: ; preds = %18
%27 = load %struct.feed_heap*, %struct.feed_heap** %10
%28 = load i8*, i8** %9
%29 = call i32 @feed_heap_free(%struct.feed_heap* %27, i8* %28)
store i8* null, i8** %9
br label %30
30: ; preds = %26, %25
br label %31
31: ; preds = %30, %4
%32 = load i8*, i8** %9
ret i8* %32
}

LLVM IR (-O2):
%struct.feed_client = type { i32 }
%struct.feed_heap = type { i32 }
define i8* @feed_object_create(%struct.feed_client* %0, i64 %1, i8 (i8*, %struct.feed_client*, i8*)* nocapture %2, i8* %3) {
%5 = tail call %struct.feed_heap* @feed_client_get_heap(%struct.feed_client* %0)
%6 = tail call i8* @feed_heap_alloc(%struct.feed_heap* %5, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call signext i8 %2(i8* %6, %struct.feed_client* %0, i8* %3)
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @feed_heap_free(%struct.feed_heap* %5, i8* %6)
br label %13
13: ; preds = %11, %8, %4
%14 = phi i8* [ %6, %8 ], [ null, %11 ], [ null, %4 ]
ret i8* %14
}