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

; 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.anon = type { ptr, ptr, ptr, ptr, ptr }
%struct.anon.0 = type { ptr, ptr, ptr, ptr, ptr }
%struct.anon.1 = type { ptr, ptr, ptr, ptr, ptr }
%struct.socket_4_tuple = type { %struct.addr_2_tuple, %struct.addr_2_tuple }
%struct.addr_2_tuple = type { i32, i32 }

@bpf_msg_redirect_hash = external hidden global ptr, align 8
@map_redir = external dso_local global %struct.anon, section ".maps", align 8
@bpf_map_lookup_elem = external hidden global ptr, align 8
@map_proxy = external dso_local global %struct.anon.0, section ".maps", align 8
@debug_map = external dso_local global %struct.anon.1, section ".maps", align 8
@__const.bpf_redir_proxy.info_fmt = external hidden unnamed_addr constant [38 x i8], align 16
@bpf_trace_printk = external hidden global ptr, align 8
@bpf_map_update_elem = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @bpf_redir_proxy(ptr noundef %0) #0 section "sk_msg" {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.socket_4_tuple, align 4
  %10 = alloca %struct.socket_4_tuple, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca [38 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  call void @llvm.memset.p0.i64(ptr align 4 %9, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr null, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  call void @sk_msg_extract4_keys(ptr noundef %14, ptr noundef %9, ptr noundef %10)
  %15 = getelementptr inbounds %struct.socket_4_tuple, ptr %10, i32 0, i32 0
  %16 = getelementptr inbounds %struct.addr_2_tuple, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = call i32 @is_inbound_ip(i32 noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %1
  %21 = getelementptr inbounds %struct.socket_4_tuple, ptr %10, i32 0, i32 1
  %22 = getelementptr inbounds %struct.addr_2_tuple, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = call i32 @is_inbound_ip(i32 noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %20, %1
  %27 = load ptr, ptr @bpf_msg_redirect_hash, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call i64 %27(ptr noundef %28, ptr noundef @map_redir, ptr noundef %10, i64 noundef 1)
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %4, align 4, !tbaa !9
  br label %43

31:                                               ; preds = %20
  %32 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !5
  %33 = call ptr %32(ptr noundef @map_proxy, ptr noundef %9)
  store ptr %33, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  store i32 1, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %78

37:                                               ; preds = %31
  %38 = load ptr, ptr @bpf_msg_redirect_hash, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = call i64 %38(ptr noundef %39, ptr noundef @map_redir, ptr noundef %40, i64 noundef 1)
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %37, %26
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %77

46:                                               ; preds = %43
  %47 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !5
  %48 = call ptr %47(ptr noundef @debug_map, ptr noundef %7)
  store ptr %48, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %76

51:                                               ; preds = %46
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = icmp eq i32 %53, 1
  br i1 %54, label %55, label %76

55:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 38, ptr %13) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %13, ptr align 16 @__const.bpf_redir_proxy.info_fmt, i64 38, i1 false)
  %56 = load ptr, ptr @bpf_trace_printk, align 8, !tbaa !5
  %57 = getelementptr inbounds [38 x i8], ptr %13, i64 0, i64 0
  %58 = getelementptr inbounds %struct.socket_4_tuple, ptr %9, i32 0, i32 0
  %59 = getelementptr inbounds %struct.addr_2_tuple, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = getelementptr inbounds %struct.socket_4_tuple, ptr %9, i32 0, i32 1
  %62 = getelementptr inbounds %struct.addr_2_tuple, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !14
  %64 = call i64 (ptr, i32, ...) %56(ptr noundef %57, i32 noundef 38, i32 noundef %60, i32 noundef %63)
  %65 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !5
  %66 = call ptr %65(ptr noundef @debug_map, ptr noundef %8)
  store ptr %66, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %70

69:                                               ; preds = %55
  store i32 0, ptr %6, align 4, !tbaa !9
  store ptr %6, ptr %5, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %69, %55
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = atomicrmw add ptr %71, i32 1 seq_cst, align 4
  %73 = load ptr, ptr @bpf_map_update_elem, align 8, !tbaa !5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = call i64 %73(ptr noundef @debug_map, ptr noundef %8, ptr noundef %74, i64 noundef 0)
  call void @llvm.lifetime.end.p0(i64 38, ptr %13) #5
  br label %76

76:                                               ; preds = %70, %51, %46
  br label %77

77:                                               ; preds = %76, %43
  store i32 1, ptr %2, align 4
  store i32 1, ptr %12, align 4
  br label %78

78:                                               ; preds = %77, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %79 = load i32, ptr %2, align 4
  ret i32 %79
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sk_msg_extract4_keys(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @is_inbound_ip(i32 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"socket_4_tuple", !13, i64 0, !13, i64 8}
!13 = !{!"addr_2_tuple", !10, i64 0, !10, i64 4}
!14 = !{!12, !10, i64 8}


; 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.anon = type { ptr, ptr, ptr, ptr, ptr }
%struct.anon.0 = type { ptr, ptr, ptr, ptr, ptr }
%struct.anon.1 = type { ptr, ptr, ptr, ptr, ptr }
%struct.socket_4_tuple = type { %struct.addr_2_tuple, %struct.addr_2_tuple }
%struct.addr_2_tuple = type { i32, i32 }

@bpf_msg_redirect_hash = external hidden local_unnamed_addr global ptr, align 8
@map_redir = external dso_local global %struct.anon, section ".maps", align 8
@bpf_map_lookup_elem = external hidden local_unnamed_addr global ptr, align 8
@map_proxy = external dso_local global %struct.anon.0, section ".maps", align 8
@debug_map = external dso_local global %struct.anon.1, section ".maps", align 8
@__const.bpf_redir_proxy.info_fmt = external hidden unnamed_addr constant [38 x i8], align 16
@bpf_trace_printk = external hidden local_unnamed_addr global ptr, align 8
@bpf_map_update_elem = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @bpf_redir_proxy(ptr noundef %0) local_unnamed_addr #0 section "sk_msg" {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.socket_4_tuple, align 4
  %6 = alloca %struct.socket_4_tuple, align 4
  %7 = alloca [38 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %5, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  call void @sk_msg_extract4_keys(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = call i32 @is_inbound_ip(i32 noundef %8)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %18

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = call i32 @is_inbound_ip(i32 noundef %12)
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %14, label %18

14:                                               ; preds = %10
  %15 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !13
  %16 = call ptr %15(ptr noundef nonnull @map_proxy, ptr noundef nonnull %5) #5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %43, label %18

18:                                               ; preds = %14, %1, %10
  %.sink = phi ptr [ %6, %10 ], [ %6, %1 ], [ %16, %14 ]
  %19 = load ptr, ptr @bpf_msg_redirect_hash, align 8, !tbaa !13
  %20 = call i64 %19(ptr noundef %0, ptr noundef nonnull @map_redir, ptr noundef nonnull %.sink, i64 noundef 1) #5
  %21 = and i64 %20, 4294967295
  %22 = icmp eq i64 %21, 1
  br i1 %22, label %23, label %43

23:                                               ; preds = %18
  %24 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !13
  %25 = call ptr %24(ptr noundef nonnull @debug_map, ptr noundef nonnull %3) #5
  %.not17 = icmp eq ptr %25, null
  br i1 %.not17, label %43, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %25, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %43

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 38, ptr nonnull %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(38) %7, ptr noundef nonnull align 16 dereferenceable(38) @__const.bpf_redir_proxy.info_fmt, i64 38, i1 false)
  %30 = load ptr, ptr @bpf_trace_printk, align 8, !tbaa !13
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %5, i64 8
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = call i64 (ptr, i32, ...) %30(ptr noundef nonnull %7, i32 noundef 38, i32 noundef %31, i32 noundef %33) #5
  %35 = load ptr, ptr @bpf_map_lookup_elem, align 8, !tbaa !13
  %36 = call ptr %35(ptr noundef nonnull @debug_map, ptr noundef nonnull %4) #5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %29
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %38, %29
  %.0 = phi ptr [ %2, %38 ], [ %36, %29 ]
  %40 = atomicrmw add ptr %.0, i32 1 seq_cst, align 4
  %41 = load ptr, ptr @bpf_map_update_elem, align 8, !tbaa !13
  %42 = call i64 %41(ptr noundef nonnull @debug_map, ptr noundef nonnull %4, ptr noundef nonnull %.0, i64 noundef 0) #5
  call void @llvm.lifetime.end.p0(i64 38, ptr nonnull %7) #5
  br label %43

43:                                               ; preds = %18, %39, %26, %23, %14
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  ret i32 1
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sk_msg_extract4_keys(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @is_inbound_ip(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"socket_4_tuple", !11, i64 0, !11, i64 8}
!11 = !{!"addr_2_tuple", !6, i64 0, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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