#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 msg {
  int dummy;
};
struct evbuffer {
  int dummy;
};
typedef scalar_t__ ev_uint32_t;

/* Variables and functions */
int /*<<< orphan*/ evbuffer_free(struct evbuffer *);
struct evbuffer *evbuffer_new();
int evtag_unmarshal(struct evbuffer *, scalar_t__ *, struct evbuffer *);
int msg_unmarshal(struct msg *, struct evbuffer *);
int evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag,
                        struct msg *msg) {
  ev_uint32_t tag;
  int res = -1;
  struct evbuffer *tmp = evbuffer_new();
  if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
    goto error;
  if (msg_unmarshal(msg, tmp) == -1)
    goto error;
  res = 0;
error:
  evbuffer_free(tmp);
  return (res);
}


x86 assembly (clang, -O0):
<evtag_unmarshal_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    $0x0,%al
call   1050 <evbuffer_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1060 <evtag_unmarshal@plt>
cmp    $0xffffffff,%eax
je     118e <evtag_unmarshal_msg+0x4e>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1193 <evtag_unmarshal_msg+0x53>
jmp    11b5 <evtag_unmarshal_msg+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <msg_unmarshal@plt>
cmp    $0xffffffff,%eax
jne    11ae <evtag_unmarshal_msg+0x6e>
jmp    11b5 <evtag_unmarshal_msg+0x75>
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <evbuffer_free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evtag_unmarshal_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <evbuffer_new@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
call   1060 <evtag_unmarshal@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     118e <evtag_unmarshal_msg+0x4e>
cmp    %r15,(%rsp)
jne    118e <evtag_unmarshal_msg+0x4e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <msg_unmarshal@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <evbuffer_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
%struct.msg = type { i32 }
define i32 @evtag_unmarshal_msg(%struct.evbuffer* %0, i64 %1, %struct.msg* %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = tail call %struct.evbuffer* (...) @evbuffer_new()
%7 = call i32 @evtag_unmarshal(%struct.evbuffer* %0, i64* %4, %struct.evbuffer* %6)
%8 = icmp ne i32 %7, -1
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, %1
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = call i32 @msg_unmarshal(%struct.msg* %2, %struct.evbuffer* %6)
%14 = icmp eq i32 %13, -1
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %12, %3
%17 = phi i32 [ -1, %3 ], [ %15, %12 ]
%18 = call i32 @evbuffer_free(%struct.evbuffer* %6)
ret i32 %17
}