#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ irq;
};
struct TYPE_3__ {
  scalar_t__ type;
};
struct cxl_event {
  TYPE_2__ irq;
  TYPE_1__ header;
};
struct cxl_afu_h {
  int dummy;
};
typedef scalar_t__ __u32;
typedef scalar_t__ __u16;

/* Variables and functions */
scalar_t__ CXL_EVENT_AFU_INTERRUPT;
int cxl_read_event(struct cxl_afu_h *, struct cxl_event *);
int cxl_read_expected_event(struct cxl_afu_h *afu, struct cxl_event *event,
                            __u32 type, __u16 irq) {
  int rv;
  if ((rv = cxl_read_event(afu, event)) < 0)
    return rv;
  if (event->header.type != type)
    return -1;
  if ((type == CXL_EVENT_AFU_INTERRUPT) && irq) {
    if (!(event->irq.irq == irq))
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cxl_read_expected_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <cxl_read_event@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    114c <cxl_read_expected_event+0x3c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <cxl_read_expected_event+0xa2>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x20(%rbp),%rax
je     116a <cxl_read_expected_event+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <cxl_read_expected_event+0xa2>
mov    -0x20(%rbp),%rax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
jne    11ab <cxl_read_expected_event+0x9b>
cmpq   $0x0,-0x28(%rbp)
je     11ab <cxl_read_expected_event+0x9b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
je     11a6 <cxl_read_expected_event+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <cxl_read_expected_event+0xa2>
jmp    11ab <cxl_read_expected_event+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_read_expected_event>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
call   1030 <cxl_read_event@plt>
test   %eax,%eax
js     114a <cxl_read_expected_event+0x3a>
mov    $0xffffffff,%eax
cmp    %r15,0x8(%rbx)
jne    114a <cxl_read_expected_event+0x3a>
test   %r14,%r14
je     1148 <cxl_read_expected_event+0x38>
mov    0x2e9a(%rip),%rcx
cmp    %r15,(%rcx)
jne    1148 <cxl_read_expected_event+0x38>
cmp    %r14,(%rbx)
jne    114a <cxl_read_expected_event+0x3a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cxl_afu_h = type { i32 }
%struct.cxl_event = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i64 }
@CXL_EVENT_AFU_INTERRUPT = global i64 0
define i32 @cxl_read_expected_event(%struct.cxl_afu_h* %0, %struct.cxl_event* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.cxl_afu_h*
%7 = alloca %struct.cxl_event*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store %struct.cxl_afu_h* %0, %struct.cxl_afu_h** %6
store %struct.cxl_event* %1, %struct.cxl_event** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load %struct.cxl_afu_h*, %struct.cxl_afu_h** %6
%12 = load %struct.cxl_event*, %struct.cxl_event** %7
%13 = call i32 @cxl_read_event(%struct.cxl_afu_h* %11, %struct.cxl_event* %12)
store i32 %13, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i32, i32* %10
store i32 %16, i32* %5
br label %42
17: ; preds = %4
%18 = load %struct.cxl_event*, %struct.cxl_event** %7
%19 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %18, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* %8
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %5
br label %42
25: ; preds = %17
%26 = load i64, i64* %8
%27 = load i64, i64* @CXL_EVENT_AFU_INTERRUPT
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i64, i64* %9
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load %struct.cxl_event*, %struct.cxl_event** %7
%34 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %33, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i64, i64* %9
%38 = icmp eq i64 %36, %37
br i1 %38, label %40, label %39
39: ; preds = %32
store i32 -1, i32* %5
br label %42
40: ; preds = %32
br label %41
41: ; preds = %40, %29, %25
store i32 0, i32* %5
br label %42
42: ; preds = %41, %39, %24, %15
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.cxl_afu_h = type { i32 }
%struct.cxl_event = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64 }
%struct.TYPE_3__ = type { i64 }
@CXL_EVENT_AFU_INTERRUPT = global i64 0
define i32 @cxl_read_expected_event(%struct.cxl_afu_h* %0, %struct.cxl_event* %1, i64 %2, i64 %3) {
%5 = tail call i32 @cxl_read_event(%struct.cxl_afu_h* %0, %struct.cxl_event* %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 1, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, %2
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i64, i64* @CXL_EVENT_AFU_INTERRUPT
%13 = icmp eq i64 %12, %2
%14 = icmp ne i64 %3, 0
%15 = and i1 %14, %13
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 0, i32 0
%18 = load i64, i64* %17
%19 = icmp eq i64 %18, %3
br i1 %19, label %20, label %21
20: ; preds = %16, %11
br label %21
21: ; preds = %16, %7, %4, %20
%22 = phi i32 [ 0, %20 ], [ %5, %4 ], [ -1, %7 ], [ -1, %16 ]
ret i32 %22
}