#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;
  int /*<<< orphan*/ size;
};
struct cxl_event {
  TYPE_1__ header;
};
typedef int /*<<< orphan*/ __u8;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ hexdump(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int cxl_fprint_unknown_event(FILE *stream, struct cxl_event *event) {
  int ret;
  if (!event) {
    errno = EINVAL;
    return -1;
  }
  ret = fprintf(stream, "CXL Unknown Event %i: ", event->header.type);
  if (ret < 0)
    return ret;
  ret += hexdump(stream, (__u8 *)event, event->header.size);
  return ret;
}


x86 assembly (clang, -O0):
<cxl_fprint_unknown_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <cxl_fprint_unknown_event+0x39>
mov    0x2e96(%rip),%rax
mov    (%rax),%ecx
mov    0x2e95(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <cxl_fprint_unknown_event+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1187 <cxl_fprint_unknown_event+0x67>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <cxl_fprint_unknown_event+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
call   1040 <hexdump@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cxl_fprint_unknown_event>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
je     1155 <cxl_fprint_unknown_event+0x35>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edx
lea    0xec8(%rip),%rsi
call   1030 <fprintf@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116c <cxl_fprint_unknown_event+0x4c>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <hexdump@plt>
add    %eax,%ebp
jmp    116c <cxl_fprint_unknown_event+0x4c>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    0x2e7b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.cxl_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"CXL Unknown Event %i: \00"
define i32 @cxl_fprint_unknown_event(i32* %0, %struct.cxl_event* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.cxl_event*
%6 = alloca i32
store i32* %0, i32** %4
store %struct.cxl_event* %1, %struct.cxl_event** %5
%7 = load %struct.cxl_event*, %struct.cxl_event** %5
%8 = icmp ne %struct.cxl_event* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
store i32 -1, i32* %3
br label %36
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = load %struct.cxl_event*, %struct.cxl_event** %5
%14 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %36
22: ; preds = %11
%23 = load i32*, i32** %4
%24 = load %struct.cxl_event*, %struct.cxl_event** %5
%25 = bitcast %struct.cxl_event* %24 to i32*
%26 = load %struct.cxl_event*, %struct.cxl_event** %5
%27 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i64 @hexdump(i32* %23, i32* %25, i32 %29)
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %6
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %22, %20, %9
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.cxl_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"CXL Unknown Event %i: \00"
define i32 @cxl_fprint_unknown_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 %17
6: ; preds = %2
%7 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = getelementptr inbounds %struct.cxl_event, %struct.cxl_event* %1, i64 0, i32 0, i32 1
%13 = load i32, i32* %12
%14 = tail call i64 @hexdump(i32* %0, i32* %7, i32 %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %9, %15
br label %17
17: ; preds = %6, %11, %4
%18 = phi i32 [ %16, %11 ], [ -1, %4 ], [ %9, %6 ]
ret i32 %18
}