#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 decode_tag_internal(unsigned long *, struct evbuffer *, int);
unsigned long evbuffer_get_length(struct evbuffer *);
int evtag_decode_int(unsigned long *, struct evbuffer *);
int evtag_unmarshal_header(struct evbuffer *evbuf, unsigned long *ptag) {
  unsigned long len;
  if (decode_tag_internal(ptag, evbuf, 1) == -1)
    return (-1);
  if (evtag_decode_int(&len, evbuf) == -1)
    return (-1);
  if (evbuffer_get_length(evbuf) < len)
    return (-1);
  return (len);
}


x86 assembly (clang, -O0):
<evtag_unmarshal_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <decode_tag_internal@plt>
cmp    $0xffffffff,%eax
jne    1167 <evtag_unmarshal_header+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <evtag_unmarshal_header+0x7f>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1050 <evtag_decode_int@plt>
cmp    $0xffffffff,%eax
jne    1189 <evtag_unmarshal_header+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <evtag_unmarshal_header+0x7f>
mov    -0x10(%rbp),%rdi
call   1040 <evbuffer_get_length@plt>
cmp    -0x20(%rbp),%rax
jae    11a8 <evtag_unmarshal_header+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <evtag_unmarshal_header+0x7f>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evtag_unmarshal_header>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <decode_tag_internal@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     1177 <evtag_unmarshal_header+0x47>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <evtag_decode_int@plt>
cmp    $0xffffffff,%eax
je     1177 <evtag_unmarshal_header+0x47>
mov    %rbx,%rdi
call   1040 <evbuffer_get_length@plt>
mov    (%rsp),%rcx
cmp    %rcx,%rax
mov    $0xffffffff,%ebp
cmovae %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
define i32 @evtag_unmarshal_header(%struct.evbuffer* %0, i64* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32 @decode_tag_internal(i64* %1, %struct.evbuffer* %0, i32 1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = call i32 @evtag_decode_int(i64* %3, %struct.evbuffer* %0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = call i64 @evbuffer_get_length(%struct.evbuffer* %0)
%12 = load i64, i64* %3
%13 = icmp ult i64 %11, %12
%14 = trunc i64 %12 to i32
%15 = select i1 %13, i32 -1, i32 %14
br label %16
16: ; preds = %10, %7, %2
%17 = phi i32 [ -1, %2 ], [ -1, %7 ], [ %15, %10 ]
ret i32 %17
}