#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 _citrus_region {
  int dummy;
};
struct _citrus_db_factory {
  int dummy;
};

/* Variables and functions */
size_t _citrus_db_factory_calc_size(struct _citrus_db_factory *);
int _citrus_db_factory_serialize(struct _citrus_db_factory *, char *,
                                 struct _citrus_region *);
int /*<<< orphan*/ _citrus_region_init(struct _citrus_region *, void *, size_t);
int errno;
void *malloc(size_t);
int dump_db(struct _citrus_db_factory *df, struct _citrus_region *r) {
  size_t size;
  void *ptr;
  size = _citrus_db_factory_calc_size(df);
  ptr = malloc(size);
  if (ptr == NULL)
    return errno;
  _citrus_region_init(r, ptr, size);
  return _citrus_db_factory_serialize(df, "LOOKUP\0\0", r);
}


x86 assembly (clang, -O0):
<dump_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_citrus_db_factory_calc_size@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1186 <dump_db+0x46>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <dump_db+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <_citrus_region_init@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1060 <_citrus_db_factory_serialize@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_db>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <_citrus_db_factory_calc_size@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1185 <dump_db+0x45>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <_citrus_region_init@plt>
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <_citrus_db_factory_serialize@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct._citrus_db_factory = type { i32 }
%struct._citrus_region = type { i32 }
@errno = global i32 0
@.str = [9 x i8] c"LOOKUP\00\00\00"
define i32 @dump_db(%struct._citrus_db_factory* %0, %struct._citrus_region* %1) {
%3 = alloca i32
%4 = alloca %struct._citrus_db_factory*
%5 = alloca %struct._citrus_region*
%6 = alloca i64
%7 = alloca i8*
store %struct._citrus_db_factory* %0, %struct._citrus_db_factory** %4
store %struct._citrus_region* %1, %struct._citrus_region** %5
%8 = load %struct._citrus_db_factory*, %struct._citrus_db_factory** %4
%9 = call i64 @_citrus_db_factory_calc_size(%struct._citrus_db_factory* %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @errno
store i32 %15, i32* %3
br label %24
16: ; preds = %2
%17 = load %struct._citrus_region*, %struct._citrus_region** %5
%18 = load i8*, i8** %7
%19 = load i64, i64* %6
%20 = call i32 @_citrus_region_init(%struct._citrus_region* %17, i8* %18, i64 %19)
%21 = load %struct._citrus_db_factory*, %struct._citrus_db_factory** %4
%22 = load %struct._citrus_region*, %struct._citrus_region** %5
%23 = call i32 @_citrus_db_factory_serialize(%struct._citrus_db_factory* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct._citrus_region* %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %16, %14
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct._citrus_db_factory = type { i32 }
%struct._citrus_region = type { i32 }
@errno = global i32 0
@.str = [9 x i8] c"LOOKUP\00\00\00"
define i32 @dump_db(%struct._citrus_db_factory* %0, %struct._citrus_region* %1) {
%3 = tail call i64 @_citrus_db_factory_calc_size(%struct._citrus_db_factory* %0)
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @errno
br label %11
8: ; preds = %2
%9 = tail call i32 @_citrus_region_init(%struct._citrus_region* %1, i8* %4, i64 %3)
%10 = tail call i32 @_citrus_db_factory_serialize(%struct._citrus_db_factory* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct._citrus_region* %1)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %7, %6 ], [ %10, %8 ]
ret i32 %12
}