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

/* Variables and functions */
int ccnl_rdr_getFlatLen(struct rdr_ds_s *);
int /*<<< orphan*/ ccnl_rdr_serialize_fill(struct rdr_ds_s *, unsigned char *);
int ccnl_rdr_serialize(struct rdr_ds_s *ds, unsigned char *buf, int buflen) {
  int len;
  if (!ds)
    return -1;
  len = ccnl_rdr_getFlatLen(ds);
  if (len > buflen)
    return -1;
  ccnl_rdr_serialize_fill(ds, buf);
  return len;
}


x86 assembly (clang, -O0):
<ccnl_rdr_serialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <ccnl_rdr_serialize+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <ccnl_rdr_serialize+0x61>
mov    -0x10(%rbp),%rdi
call   1040 <ccnl_rdr_getFlatLen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    116e <ccnl_rdr_serialize+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <ccnl_rdr_serialize+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ccnl_rdr_serialize_fill@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_rdr_serialize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1156 <ccnl_rdr_serialize+0x36>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <ccnl_rdr_getFlatLen@plt>
cmp    %r12d,%eax
jg     1156 <ccnl_rdr_serialize+0x36>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <ccnl_rdr_serialize_fill@plt>
mov    %r15d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.rdr_ds_s = type { i32 }
define i32 @ccnl_rdr_serialize(%struct.rdr_ds_s* %0, i8* %1, i32 %2) {
%4 = icmp eq %struct.rdr_ds_s* %0, null
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i32 @ccnl_rdr_getFlatLen(%struct.rdr_ds_s* %0)
%7 = icmp sgt i32 %6, %2
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @ccnl_rdr_serialize_fill(%struct.rdr_ds_s* %0, i8* %1)
br label %10
10: ; preds = %5, %3, %8
%11 = phi i32 [ %6, %8 ], [ -1, %3 ], [ -1, %5 ]
ret i32 %11
}