; LLVM IR from linuxkerneltravel/lmp :: eBPF_Supermarket/CPU_Subsystem/old_project/Interrupt_exception (interrupt)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.bpf_map_def = type { i32, i32, i32, i32, i32 }
%struct.pt_regs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.intr_message = type { i64, i32, i32 }

@stack_traces = external dso_local global %struct.bpf_map_def, section "maps", align 4
@events = external dso_local global %struct.bpf_map_def, section "maps", align 4
@bpf_get_current_pid_tgid = external hidden global ptr, align 8
@bpf_ringbuf_reserve = external hidden global ptr, align 8
@bpf_get_stackid = external hidden global ptr, align 8
@bpf_ringbuf_submit = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @kprobe__do_error_trap(ptr noundef %0) #0 section "kprobe/do_error_trap" {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.pt_regs, ptr %8, i32 0, i32 11
  %10 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %10, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %11 = load ptr, ptr @bpf_get_current_pid_tgid, align 8, !tbaa !5
  %12 = call i64 %11()
  %13 = lshr i64 %12, 32
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %6, align 4, !tbaa !13
  %15 = load ptr, ptr @bpf_ringbuf_reserve, align 8, !tbaa !5
  %16 = call ptr %15(ptr noundef @events, i64 noundef 16, i64 noundef 0)
  store ptr %16, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %35

20:                                               ; preds = %1
  %21 = load ptr, ptr @bpf_get_stackid, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i64 %21(ptr noundef %22, ptr noundef @stack_traces, i64 noundef 0)
  %24 = trunc i64 %23 to i32
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.intr_message, ptr %25, i32 0, i32 2
  store i32 %24, ptr %26, align 4, !tbaa !15
  %27 = load i32, ptr %6, align 4, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.intr_message, ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 8, !tbaa !17
  %30 = load i64, ptr %5, align 8, !tbaa !12
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.intr_message, ptr %31, i32 0, i32 0
  store i64 %30, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr @bpf_ringbuf_submit, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void %33(ptr noundef %34, i64 noundef 0)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %35

35:                                               ; preds = %20, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %36 = load i32, ptr %2, align 4
  ret i32 %36
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 88}
!10 = !{!"pt_regs", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 12}
!16 = !{!"intr_message", !11, i64 0, !14, i64 8, !14, i64 12}
!17 = !{!16, !14, i64 8}
!18 = !{!16, !11, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.bpf_map_def = type { i32, i32, i32, i32, i32 }

@stack_traces = external dso_local global %struct.bpf_map_def, section "maps", align 4
@events = external dso_local global %struct.bpf_map_def, section "maps", align 4
@bpf_get_current_pid_tgid = external hidden local_unnamed_addr global ptr, align 8
@bpf_ringbuf_reserve = external hidden local_unnamed_addr global ptr, align 8
@bpf_get_stackid = external hidden local_unnamed_addr global ptr, align 8
@bpf_ringbuf_submit = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @kprobe__do_error_trap(ptr noundef %0) local_unnamed_addr #0 section "kprobe/do_error_trap" {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr @bpf_get_current_pid_tgid, align 8, !tbaa !10
  %5 = tail call i64 %4() #1
  %6 = load ptr, ptr @bpf_ringbuf_reserve, align 8, !tbaa !10
  %7 = tail call ptr %6(ptr noundef nonnull @events, i64 noundef 16, i64 noundef 0) #1
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %17, label %8

8:                                                ; preds = %1
  %9 = lshr i64 %5, 32
  %10 = trunc nuw i64 %9 to i32
  %11 = load ptr, ptr @bpf_get_stackid, align 8, !tbaa !10
  %12 = tail call i64 %11(ptr noundef nonnull %0, ptr noundef nonnull @stack_traces, i64 noundef 0) #1
  %13 = trunc i64 %12 to i32
  %14 = getelementptr inbounds i8, ptr %7, i64 12
  store i32 %13, ptr %14, align 4, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %10, ptr %15, align 8, !tbaa !15
  store i64 %3, ptr %7, align 8, !tbaa !16
  %16 = load ptr, ptr @bpf_ringbuf_submit, align 8, !tbaa !10
  tail call void %16(ptr noundef nonnull %7, i64 noundef 0) #1
  br label %17

17:                                               ; preds = %1, %8
  ret i32 0
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 88}
!6 = !{!"pt_regs", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !14, i64 12}
!13 = !{!"intr_message", !7, i64 0, !14, i64 8, !14, i64 12}
!14 = !{!"int", !8, i64 0}
!15 = !{!13, !14, i64 8}
!16 = !{!13, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass