; LLVM IR from asllop/AppOS :: net/ipv4 (ipv4_internal)

; 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.NetIfaceStruct = type { i32, i8, i16, i8, i32, i32, i32, [128 x ptr], %struct.NetFragStruct, %struct.NetFragStruct }
%struct.NetFragStruct = type { i16, i8, [32 x ptr] }

; 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
declare dso_local zeroext i8 @ipv4_fragment_present(ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @ipv4_sort_fragments(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i16, align 2
  %14 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i16, ptr %5, align 2, !tbaa !9
  %17 = call zeroext i8 @ipv4_fragment_present(ptr noundef %15, i16 noundef zeroext %16)
  %18 = zext i8 %17 to i32
  switch i32 %18, label %25 [
    i32 1, label %19
    i32 2, label %22
  ]

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.NetIfaceStruct, ptr %20, i32 0, i32 8
  store ptr %21, ptr %6, align 8, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %26

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NetIfaceStruct, ptr %23, i32 0, i32 9
  store ptr %24, ptr %6, align 8, !tbaa !5
  store i8 2, ptr %7, align 1, !tbaa !11
  br label %26

25:                                               ; preds = %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %110

26:                                               ; preds = %22, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %27

27:                                               ; preds = %106, %26
  %28 = load i32, ptr %9, align 4, !tbaa !12
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.NetFragStruct, ptr %29, i32 0, i32 1
  %31 = load i8, ptr %30, align 2, !tbaa !14
  %32 = zext i8 %31 to i32
  %33 = icmp slt i32 %28, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %27
  store i32 3, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %109

35:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %36 = load i32, ptr %9, align 4, !tbaa !12
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %10, align 4, !tbaa !12
  br label %38

38:                                               ; preds = %102, %35
  %39 = load i32, ptr %10, align 4, !tbaa !12
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.NetFragStruct, ptr %40, i32 0, i32 1
  %42 = load i8, ptr %41, align 2, !tbaa !14
  %43 = zext i8 %42 to i32
  %44 = icmp slt i32 %39, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %38
  store i32 6, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %105

46:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.NetFragStruct, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %9, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32 x ptr], ptr %48, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  store ptr %52, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NetFragStruct, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %10, align 4, !tbaa !12
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [32 x ptr], ptr %54, i64 0, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  store ptr %58, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #2
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 6
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = and i32 %62, 31
  %64 = shl i32 %63, 8
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 7
  %67 = load i8, ptr %66, align 1, !tbaa !11
  %68 = zext i8 %67 to i32
  %69 = or i32 %64, %68
  %70 = trunc i32 %69 to i16
  store i16 %70, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #2
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 6
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = and i32 %74, 31
  %76 = shl i32 %75, 8
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 7
  %79 = load i8, ptr %78, align 1, !tbaa !11
  %80 = zext i8 %79 to i32
  %81 = or i32 %76, %80
  %82 = trunc i32 %81 to i16
  store i16 %82, ptr %14, align 2, !tbaa !9
  %83 = load i16, ptr %13, align 2, !tbaa !9
  %84 = zext i16 %83 to i32
  %85 = load i16, ptr %14, align 2, !tbaa !9
  %86 = zext i16 %85 to i32
  %87 = icmp sgt i32 %84, %86
  br i1 %87, label %88, label %101

88:                                               ; preds = %46
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.NetFragStruct, ptr %90, i32 0, i32 2
  %92 = load i32, ptr %9, align 4, !tbaa !12
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [32 x ptr], ptr %91, i64 0, i64 %93
  store ptr %89, ptr %94, align 8, !tbaa !5
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.NetFragStruct, ptr %96, i32 0, i32 2
  %98 = load i32, ptr %10, align 4, !tbaa !12
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [32 x ptr], ptr %97, i64 0, i64 %99
  store ptr %95, ptr %100, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %88, %46
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %10, align 4, !tbaa !12
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %10, align 4, !tbaa !12
  br label %38, !llvm.loop !16

105:                                              ; preds = %45
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %9, align 4, !tbaa !12
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %9, align 4, !tbaa !12
  br label %27, !llvm.loop !18

109:                                              ; preds = %34
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %110

110:                                              ; preds = %109, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %111 = load i8, ptr %3, align 1
  ret i8 %111
}

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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !7, i64 2}
!15 = !{!"NetFragStruct", !10, i64 0, !7, i64 2, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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"

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @ipv4_fragment_present(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @ipv4_sort_fragments(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i8 @ipv4_fragment_present(ptr noundef %0, i16 noundef zeroext %1)
  switch i8 %3, label %.loopexit30 [
    i8 1, label %5
    i8 2, label %4
  ]

4:                                                ; preds = %2
  br label %5

5:                                                ; preds = %2, %4
  %.sink = phi i64 [ 1312, %4 ], [ 1048, %2 ]
  %6 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %7 = getelementptr inbounds i8, ptr %6, i64 2
  %8 = load i8, ptr %7, align 2, !tbaa !5
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %.loopexit30, label %.lr.ph33

.lr.ph33:                                         ; preds = %5
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  %10 = zext i8 %8 to i64
  br label %11

.loopexit:                                        ; preds = %38, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next38, %10
  br i1 %exitcond41.not, label %.loopexit30, label %11, !llvm.loop !10

11:                                               ; preds = %.lr.ph33, %.loopexit
  %indvars.iv37 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next38, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph33 ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %12 = icmp ult i64 %indvars.iv.next38, %10
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %11
  %13 = getelementptr inbounds [32 x ptr], ptr %9, i64 0, i64 %indvars.iv37
  br label %14

14:                                               ; preds = %.lr.ph, %38
  %indvars.iv34 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next35, %38 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !12
  %16 = getelementptr inbounds [32 x ptr], ptr %9, i64 0, i64 %indvars.iv34
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %15, i64 6
  %19 = load i8, ptr %18, align 1, !tbaa !14
  %20 = and i8 %19, 31
  %21 = zext nneg i8 %20 to i32
  %22 = shl nuw nsw i32 %21, 8
  %23 = getelementptr inbounds i8, ptr %15, i64 7
  %24 = load i8, ptr %23, align 1, !tbaa !14
  %25 = zext i8 %24 to i32
  %26 = or disjoint i32 %22, %25
  %27 = getelementptr inbounds i8, ptr %17, i64 6
  %28 = load i8, ptr %27, align 1, !tbaa !14
  %29 = and i8 %28, 31
  %30 = zext nneg i8 %29 to i32
  %31 = shl nuw nsw i32 %30, 8
  %32 = getelementptr inbounds i8, ptr %17, i64 7
  %33 = load i8, ptr %32, align 1, !tbaa !14
  %34 = zext i8 %33 to i32
  %35 = or disjoint i32 %31, %34
  %36 = icmp ugt i32 %26, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %14
  store ptr %17, ptr %13, align 8, !tbaa !12
  store ptr %15, ptr %16, align 8, !tbaa !12
  br label %38

38:                                               ; preds = %37, %14
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next35, %10
  br i1 %exitcond.not, label %.loopexit, label %14, !llvm.loop !15

.loopexit30:                                      ; preds = %.loopexit, %5, %2
  %.0 = phi i8 [ 0, %2 ], [ 1, %5 ], [ 1, %.loopexit ]
  ret i8 %.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" }

!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, !8, i64 2}
!6 = !{!"NetFragStruct", !7, i64 0, !8, i64 2, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass