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

/* Variables and functions */
int evbuffer_add(struct evbuffer *, int /*<<< orphan*/, int);
int /*<<< orphan*/ evbuffer_drain(struct evbuffer *, int);
int /*<<< orphan*/ evbuffer_pullup(struct evbuffer *, int);
int evtag_unmarshal_header(struct evbuffer *, unsigned long *);
int evtag_unmarshal(struct evbuffer *src, unsigned long *ptag,
                    struct evbuffer *dst) {
  int len;
  if ((len = evtag_unmarshal_header(src, ptag)) == -1)
    return (-1);
  if (evbuffer_add(dst, evbuffer_pullup(src, len), len) == -1)
    return (-1);
  evbuffer_drain(src, len);
  return (len);
}


x86 assembly (clang, -O0):
<evtag_unmarshal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <evtag_unmarshal_header@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1179 <evtag_unmarshal+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <evtag_unmarshal+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <evbuffer_pullup@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x24(%rbp),%edx
call   1040 <evbuffer_add@plt>
cmp    $0xffffffff,%eax
jne    11b0 <evtag_unmarshal+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <evtag_unmarshal+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <evbuffer_drain@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evtag_unmarshal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%rbx
call   1050 <evtag_unmarshal_header@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1187 <evtag_unmarshal+0x47>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <evbuffer_pullup@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1040 <evbuffer_add@plt>
cmp    $0xffffffff,%eax
je     1187 <evtag_unmarshal+0x47>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <evbuffer_drain@plt>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.evbuffer = type { i32 }
define i32 @evtag_unmarshal(%struct.evbuffer* %0, i64* %1, %struct.evbuffer* %2) {
%4 = alloca i32
%5 = alloca %struct.evbuffer*
%6 = alloca i64*
%7 = alloca %struct.evbuffer*
%8 = alloca i32
store %struct.evbuffer* %0, %struct.evbuffer** %5
store i64* %1, i64** %6
store %struct.evbuffer* %2, %struct.evbuffer** %7
%9 = load %struct.evbuffer*, %struct.evbuffer** %5
%10 = load i64*, i64** %6
%11 = call i32 @evtag_unmarshal_header(%struct.evbuffer* %9, i64* %10)
store i32 %11, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %28
14: ; preds = %3
%15 = load %struct.evbuffer*, %struct.evbuffer** %7
%16 = load %struct.evbuffer*, %struct.evbuffer** %5
%17 = load i32, i32* %8
%18 = call i32 @evbuffer_pullup(%struct.evbuffer* %16, i32 %17)
%19 = load i32, i32* %8
%20 = call i32 @evbuffer_add(%struct.evbuffer* %15, i32 %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 -1, i32* %4
br label %28
23: ; preds = %14
%24 = load %struct.evbuffer*, %struct.evbuffer** %5
%25 = load i32, i32* %8
%26 = call i32 @evbuffer_drain(%struct.evbuffer* %24, i32 %25)
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %28
28: ; preds = %23, %22, %13
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
define i32 @evtag_unmarshal(%struct.evbuffer* %0, i64* %1, %struct.evbuffer* %2) {
%4 = tail call i32 @evtag_unmarshal_header(%struct.evbuffer* %0, i64* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i32 @evbuffer_pullup(%struct.evbuffer* %0, i32 %4)
%8 = tail call i32 @evbuffer_add(%struct.evbuffer* %2, i32 %7, i32 %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @evbuffer_drain(%struct.evbuffer* %0, i32 %4)
br label %12
12: ; preds = %6, %3, %10
%13 = phi i32 [ %4, %10 ], [ -1, %3 ], [ -1, %6 ]
ret i32 %13
}