; LLVM IR from linuxkerneltravel/lmp :: eBPF_Supermarket/CPU_Subsystem/old_project/go_sar/program (tracepoint)

; 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.__irq_info = type { i64, i32 }

@bpf_ktime_get_ns = external hidden global ptr, align 8
@bpf_map_update_elem = external hidden global ptr, align 8
@bpf_map_lookup_elem = external hidden global ptr, align 8
@irqCpuEnterTime = external dso_local global %struct.bpf_map_def, section "maps", align 4
@IrqLastTime = external dso_local global %struct.bpf_map_def, section "maps", align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @irq_handler_exit(ptr noundef %0) #1 section "tracepoint/irq/irq_handler_exit" {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.__irq_info, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  store i32 %10, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %11 = load ptr, ptr @bpf_ktime_get_ns, align 8, !tbaa !5
  %12 = call i64 %11()
  store i64 %12, ptr %4, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr null, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !5
  %14 = call ptr %13(ptr noundef @irqCpuEnterTime, ptr noundef %3)
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %35

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %18 = load i64, ptr %4, align 8, !tbaa !14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = sub i64 %18, %20
  store i64 %21, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !13
  %22 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !5
  %23 = call ptr %22(ptr noundef @IrqLastTime, ptr noundef %7)
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %29, label %26

26:                                               ; preds = %17
  %27 = load ptr, ptr @bpf_map_update_elem, align 8, !tbaa !5
  %28 = call i64 %27(ptr noundef @IrqLastTime, ptr noundef %7, ptr noundef %6, i64 noundef 0)
  br label %34

29:                                               ; preds = %17
  %30 = load i64, ptr %6, align 8, !tbaa !14
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = add i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %29, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %35

35:                                               ; preds = %34, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !12, i64 8}
!10 = !{!"__irq_info", !11, i64 0, !12, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !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 }

@bpf_ktime_get_ns = external hidden local_unnamed_addr global ptr, align 8
@bpf_map_update_elem = external hidden local_unnamed_addr global ptr, align 8
@bpf_map_lookup_elem = external hidden local_unnamed_addr global ptr, align 8
@irqCpuEnterTime = external dso_local global %struct.bpf_map_def, section "maps", align 4
@IrqLastTime = external dso_local global %struct.bpf_map_def, section "maps", align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @irq_handler_exit(ptr nocapture noundef readonly %0) local_unnamed_addr #1 section "tracepoint/irq/irq_handler_exit" {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  store i32 %6, ptr %2, align 4, !tbaa !11
  %7 = load ptr, ptr @bpf_ktime_get_ns, align 8, !tbaa !12
  %8 = tail call i64 %7() #2
  %9 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !12
  %10 = call ptr %9(ptr noundef nonnull @irqCpuEnterTime, ptr noundef nonnull %2) #2
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %23, label %11

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %12 = load i64, ptr %10, align 8, !tbaa !14
  %13 = sub i64 %8, %12
  store i64 %13, ptr %3, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  store i32 0, ptr %4, align 4, !tbaa !11
  %14 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !12
  %15 = call ptr %14(ptr noundef nonnull @IrqLastTime, ptr noundef nonnull %4) #2
  %.not6 = icmp eq ptr %15, null
  br i1 %.not6, label %16, label %19

16:                                               ; preds = %11
  %17 = load ptr, ptr @bpf_map_update_elem, align 8, !tbaa !12
  %18 = call i64 %17(ptr noundef nonnull @IrqLastTime, ptr noundef nonnull %4, ptr noundef nonnull %3, i64 noundef 0) #2
  br label %22

19:                                               ; preds = %11
  %20 = load i64, ptr %15, align 8, !tbaa !14
  %21 = add i64 %20, %13
  store i64 %21, ptr %15, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %19, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  br label %23

23:                                               ; preds = %22, %1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  ret i32 0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 8}
!6 = !{!"__irq_info", !7, i64 0, !10, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass