; LLVM IR from linuxkerneltravel/lmp :: eBPF_Supermarket/old_project/sidecar/bpf/sockops (bpf_sockops)

; 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_sock_ops = type { i32, %union.anon, i32, i32, i32, [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, %union.anon.0, %union.anon.1, %union.anon.2, i32, i32 }
%union.anon = type { [4 x i32] }
%union.anon.0 = type { ptr }
%union.anon.1 = type { ptr }
%union.anon.2 = type { ptr }

@bpf_sock_ops_cb_flags_set = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @bpf_sockmap(ptr noundef %0) #0 section "sockops" {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.bpf_sock_ops, ptr %4, i32 0, i32 2
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %14, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.bpf_sock_ops, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  store i32 0, ptr %2, align 4
  br label %36

14:                                               ; preds = %8, %1
  %15 = load ptr, ptr @bpf_sock_ops_cb_flags_set, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i64 %15(ptr noundef %16, i32 noundef 4)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.bpf_sock_ops, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !14
  switch i32 %20, label %34 [
    i32 4, label %21
    i32 5, label %23
    i32 10, label %25
  ]

21:                                               ; preds = %14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @bpf_sock_ops_active_establish_cb(ptr noundef %22)
  br label %35

23:                                               ; preds = %14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  call void @bpf_sock_ops_passive_establish_cb(ptr noundef %24)
  br label %35

25:                                               ; preds = %14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.bpf_sock_ops, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds [4 x i32], ptr %27, i64 0, i64 1
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = icmp eq i32 %29, 7
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @bpf_sock_ops_state_cb(ptr noundef %32)
  br label %33

33:                                               ; preds = %31, %25
  br label %35

34:                                               ; preds = %14
  br label %35

35:                                               ; preds = %34, %33, %23, %21
  store i32 0, ptr %2, align 4
  br label %36

36:                                               ; preds = %35, %13
  %37 = load i32, ptr %2, align 4
  ret i32 %37
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_active_establish_cb(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_passive_establish_cb(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_state_cb(ptr noundef) #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 = { inlinehint 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" }

!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 20}
!10 = !{!"bpf_sock_ops", !11, i64 0, !7, i64 4, !11, i64 20, !11, i64 24, !11, i64 28, !7, i64 32, !7, i64 48, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !12, i64 168, !12, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !11, i64 208, !11, i64 212}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !11, i64 0}
!15 = !{!7, !7, 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"

@bpf_sock_ops_cb_flags_set = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @bpf_sockmap(ptr noundef %0) local_unnamed_addr #0 section "sockops" {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %8, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %19, label %8

8:                                                ; preds = %5, %1
  %9 = load ptr, ptr @bpf_sock_ops_cb_flags_set, align 8, !tbaa !12
  %10 = tail call i64 %9(ptr noundef nonnull %0, i32 noundef 4) #2
  %11 = load i32, ptr %0, align 8, !tbaa !14
  switch i32 %11, label %19 [
    i32 4, label %12
    i32 5, label %13
    i32 10, label %14
  ]

12:                                               ; preds = %8
  tail call void @bpf_sock_ops_active_establish_cb(ptr noundef nonnull %0)
  br label %19

13:                                               ; preds = %8
  tail call void @bpf_sock_ops_passive_establish_cb(ptr noundef nonnull %0)
  br label %19

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = icmp eq i32 %16, 7
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  tail call void @bpf_sock_ops_state_cb(ptr noundef nonnull %0)
  br label %19

19:                                               ; preds = %12, %13, %18, %14, %8, %5
  ret i32 0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_active_establish_cb(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_passive_establish_cb(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bpf_sock_ops_state_cb(ptr noundef) local_unnamed_addr #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 = { inlinehint 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, !7, i64 20}
!6 = !{!"bpf_sock_ops", !7, i64 0, !8, i64 4, !7, i64 20, !7, i64 24, !7, i64 28, !8, i64 32, !8, i64 48, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !10, i64 168, !10, i64 176, !8, i64 184, !8, i64 192, !8, i64 200, !7, i64 208, !7, i64 212}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!8, !8, i64 0}


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