#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int type;
};
struct cxl_event {
  int /*<<< orphan*/ afu_error;
  int /*<<< orphan*/ fault;
  int /*<<< orphan*/ irq;
  TYPE_1__ header;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
#define CXL_EVENT_AFU_ERROR 130
#define CXL_EVENT_AFU_INTERRUPT 129
#define CXL_EVENT_DATA_STORAGE 128
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENODATA;
int cxl_fprint_afu_error(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int cxl_fprint_afu_interrupt(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int cxl_fprint_data_storage(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int cxl_fprint_unknown_event(int /*<<< orphan*/ *, struct cxl_event *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int cxl_fprint_event(FILE *stream, struct cxl_event *event) {
  if (!event) {
    errno = EINVAL;
    return -1;
  }
  switch (event->header.type) {
  case 0xffff:
    fprintf(stderr, "cxl_fprint_event: CXL Read failed\n");
    errno = ENODATA;
    return -1;
  case CXL_EVENT_AFU_INTERRUPT:
    return cxl_fprint_afu_interrupt(stream, &event->irq);
  case CXL_EVENT_DATA_STORAGE:
    return cxl_fprint_data_storage(stream, &event->fault);
  case CXL_EVENT_AFU_ERROR:
    return cxl_fprint_afu_error(stream, &event->afu_error);
  default:
    return cxl_fprint_unknown_event(stream, event);
  }
}


x86 assembly (clang, -O0):
<cxl_fprint_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <cxl_fprint_event+0x39>
mov    0x2e56(%rip),%rax
mov    (%rax),%ecx
mov    0x2e55(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <cxl_fprint_event+0x116>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1228 <cxl_fprint_event+0xd8>
jmp    11a3 <cxl_fprint_event+0x53>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     120f <cxl_fprint_event+0xbf>
jmp    11b6 <cxl_fprint_event+0x66>
mov    -0x1c(%rbp),%eax
sub    $0x82,%eax
je     1241 <cxl_fprint_event+0xf1>
jmp    11c9 <cxl_fprint_event+0x79>
mov    -0x1c(%rbp),%eax
sub    $0xffff,%eax
jne    1256 <cxl_fprint_event+0x106>
jmp    11dc <cxl_fprint_event+0x8c>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%ecx
mov    0x2dcf(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <cxl_fprint_event+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x8,%rsi
call   1030 <cxl_fprint_afu_interrupt@plt>
mov    %eax,-0x4(%rbp)
jmp    1266 <cxl_fprint_event+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
call   1050 <cxl_fprint_data_storage@plt>
mov    %eax,-0x4(%rbp)
jmp    1266 <cxl_fprint_event+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <cxl_fprint_afu_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1266 <cxl_fprint_event+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <cxl_fprint_unknown_event@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_fprint_event>:
push   %rax
test   %rsi,%rsi
je     1178 <cxl_fprint_event+0x28>
mov    0xc(%rsi),%eax
cmp    $0x81,%eax
jg     1181 <cxl_fprint_event+0x31>
cmp    $0x80,%eax
je     11c3 <cxl_fprint_event+0x73>
cmp    $0x81,%eax
jne    11bd <cxl_fprint_event+0x6d>
add    $0x8,%rsi
pop    %rax
jmp    1030 <cxl_fprint_afu_interrupt@plt>
mov    0x2e49(%rip),%rax
jmp    11ab <cxl_fprint_event+0x5b>
cmp    $0x82,%eax
je     11cd <cxl_fprint_event+0x7d>
cmp    $0xffff,%eax
jne    11bd <cxl_fprint_event+0x6d>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    0x2e1c(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret
pop    %rax
jmp    1070 <cxl_fprint_unknown_event@plt>
add    $0x4,%rsi
pop    %rax
jmp    1050 <cxl_fprint_data_storage@plt>
pop    %rax
jmp    1060 <cxl_fprint_afu_error@plt>

LLVM IR (-O0):
%struct.cxl_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"cxl_fprint_event: CXL Read failed\0A\00"
@ENODATA = global i32 0
define i32 @cxl_fprint_event(i32* %0, %struct.cxl_event* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.cxl_event*
store i32* %0, i32** %4
store %struct.cxl_event* %1, %struct.cxl_event** %5
%6 = load %struct.cxl_event*, %struct.cxl_event** %5
%7 = icmp ne %struct.cxl_event* %6, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
store i32 -1, i32* %3
br label %38
10: ; preds = %2
%11 = load %struct.cxl_event*, %struct.cxl_event** %5
%12 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %11, i32 0, i32 3
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
%14 = load i32, i32* %13
switch i32 %14, label %34 [
i32 65535, label %15
i32 129, label %19
i32 128, label %24
i32 130, label %29
]
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @ENODATA
store i32 %18, i32* @errno
store i32 -1, i32* %3
br label %38
19: ; preds = %10
%20 = load i32*, i32** %4
%21 = load %struct.cxl_event*, %struct.cxl_event** %5
%22 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %21, i32 0, i32 2
%23 = call i32 @cxl_fprint_afu_interrupt(i32* %20, i32* %22)
store i32 %23, i32* %3
br label %38
24: ; preds = %10
%25 = load i32*, i32** %4
%26 = load %struct.cxl_event*, %struct.cxl_event** %5
%27 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %26, i32 0, i32 1
%28 = call i32 @cxl_fprint_data_storage(i32* %25, i32* %27)
store i32 %28, i32* %3
br label %38
29: ; preds = %10
%30 = load i32*, i32** %4
%31 = load %struct.cxl_event*, %struct.cxl_event** %5
%32 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %31, i32 0, i32 0
%33 = call i32 @cxl_fprint_afu_error(i32* %30, i32* %32)
store i32 %33, i32* %3
br label %38
34: ; preds = %10
%35 = load i32*, i32** %4
%36 = load %struct.cxl_event*, %struct.cxl_event** %5
%37 = call i32 @cxl_fprint_unknown_event(i32* %35, %struct.cxl_event* %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %34, %29, %24, %19, %15, %8
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.cxl_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"cxl_fprint_event: CXL Read failed\0A\00"
@ENODATA = global i32 0
define i32 @cxl_fprint_event(i32* %0, %struct.cxl_event* %1) {
%3 = icmp eq %struct.cxl_event* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EINVAL
store i32 %5, i32* @errno
br label %24
6: ; preds = %2
%7 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 3, i32 0
%8 = load i32, i32* %7
switch i32 %8, label %22 [
i32 65535, label %9
i32 129, label %13
i32 128, label %16
i32 130, label %19
]
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @ENODATA
store i32 %12, i32* @errno
br label %24
13: ; preds = %6
%14 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 2
%15 = tail call i32 @cxl_fprint_afu_interrupt(i32* %0, i32* %14)
br label %24
16: ; preds = %6
%17 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 1
%18 = tail call i32 @cxl_fprint_data_storage(i32* %0, i32* %17)
br label %24
19: ; preds = %6
%20 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 0
%21 = tail call i32 @cxl_fprint_afu_error(i32* %0, i32* %20)
br label %24
22: ; preds = %6
%23 = tail call i32 @cxl_fprint_unknown_event(i32* %0, %struct.cxl_event* %1)
br label %24
24: ; preds = %22, %19, %16, %13, %9, %4
%25 = phi i32 [ %23, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ], [ -1, %9 ], [ -1, %4 ]
ret i32 %25
}