; 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: nounwind uwtable
define dso_local zeroext i8 @ipv4_add_existing_fragment(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.NetIfaceStruct, ptr %8, i32 0, i32 8
  %10 = getelementptr inbounds %struct.NetFragStruct, ptr %9, i32 0, i32 0
  %11 = load i16, ptr %10, align 8, !tbaa !11
  %12 = zext i16 %11 to i32
  %13 = load i16, ptr %6, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = icmp eq i32 %12, %14
  br i1 %15, label %16, label %40

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NetIfaceStruct, ptr %17, i32 0, i32 8
  %19 = getelementptr inbounds %struct.NetFragStruct, ptr %18, i32 0, i32 1
  %20 = load i8, ptr %19, align 2, !tbaa !15
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 32
  br i1 %22, label %23, label %39

23:                                               ; preds = %16
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.NetIfaceStruct, ptr %25, i32 0, i32 8
  %27 = getelementptr inbounds %struct.NetFragStruct, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.NetIfaceStruct, ptr %28, i32 0, i32 8
  %30 = getelementptr inbounds %struct.NetFragStruct, ptr %29, i32 0, i32 1
  %31 = load i8, ptr %30, align 2, !tbaa !15
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds [32 x ptr], ptr %27, i64 0, i64 %32
  store ptr %24, ptr %33, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NetIfaceStruct, ptr %34, i32 0, i32 8
  %36 = getelementptr inbounds %struct.NetFragStruct, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 2, !tbaa !15
  %38 = add i8 %37, 1
  store i8 %38, ptr %36, align 2, !tbaa !15
  store i8 1, ptr %4, align 1
  br label %75

39:                                               ; preds = %16
  br label %74

40:                                               ; preds = %3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.NetIfaceStruct, ptr %41, i32 0, i32 9
  %43 = getelementptr inbounds %struct.NetFragStruct, ptr %42, i32 0, i32 0
  %44 = load i16, ptr %43, align 8, !tbaa !16
  %45 = zext i16 %44 to i32
  %46 = load i16, ptr %6, align 2, !tbaa !9
  %47 = zext i16 %46 to i32
  %48 = icmp eq i32 %45, %47
  br i1 %48, label %49, label %73

49:                                               ; preds = %40
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.NetIfaceStruct, ptr %50, i32 0, i32 9
  %52 = getelementptr inbounds %struct.NetFragStruct, ptr %51, i32 0, i32 1
  %53 = load i8, ptr %52, align 2, !tbaa !17
  %54 = zext i8 %53 to i32
  %55 = icmp slt i32 %54, 32
  br i1 %55, label %56, label %72

56:                                               ; preds = %49
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.NetIfaceStruct, ptr %58, i32 0, i32 9
  %60 = getelementptr inbounds %struct.NetFragStruct, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.NetIfaceStruct, ptr %61, i32 0, i32 9
  %63 = getelementptr inbounds %struct.NetFragStruct, ptr %62, i32 0, i32 1
  %64 = load i8, ptr %63, align 2, !tbaa !17
  %65 = zext i8 %64 to i64
  %66 = getelementptr inbounds [32 x ptr], ptr %60, i64 0, i64 %65
  store ptr %57, ptr %66, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.NetIfaceStruct, ptr %67, i32 0, i32 9
  %69 = getelementptr inbounds %struct.NetFragStruct, ptr %68, i32 0, i32 1
  %70 = load i8, ptr %69, align 2, !tbaa !17
  %71 = add i8 %70, 1
  store i8 %71, ptr %69, align 2, !tbaa !17
  store i8 1, ptr %4, align 1
  br label %75

72:                                               ; preds = %49
  br label %73

73:                                               ; preds = %72, %40
  br label %74

74:                                               ; preds = %73, %39
  store i8 0, ptr %4, align 1
  br label %75

75:                                               ; preds = %74, %56, %23
  %76 = load i8, ptr %4, align 1
  ret i8 %76
}

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, !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 = !{!12, !10, i64 1048}
!12 = !{!"NetIfaceStruct", !13, i64 0, !7, i64 4, !10, i64 6, !7, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !7, i64 24, !14, i64 1048, !14, i64 1312}
!13 = !{!"int", !7, i64 0}
!14 = !{!"NetFragStruct", !10, i64 0, !7, i64 2, !7, i64 8}
!15 = !{!12, !7, i64 1050}
!16 = !{!12, !10, i64 1312}
!17 = !{!12, !7, i64 1314}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @ipv4_add_existing_fragment(ptr nocapture noundef %0, i16 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 1048
  %5 = load i16, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i16 %5, %1
  br i1 %6, label %7, label %11

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 1050
  %9 = load i8, ptr %8, align 2, !tbaa !12
  %10 = icmp ult i8 %9, 32
  br i1 %10, label %.sink.split, label %23

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 1312
  %13 = load i16, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i16 %13, %1
  br i1 %14, label %15, label %23

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 1314
  %17 = load i8, ptr %16, align 2, !tbaa !14
  %18 = icmp ult i8 %17, 32
  br i1 %18, label %.sink.split, label %23

.sink.split:                                      ; preds = %15, %7
  %.sink19 = phi i64 [ 1056, %7 ], [ 1320, %15 ]
  %.sink = phi i8 [ %9, %7 ], [ %17, %15 ]
  %.sink15 = phi ptr [ %8, %7 ], [ %16, %15 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 %.sink19
  %20 = zext nneg i8 %.sink to i64
  %21 = getelementptr inbounds [32 x ptr], ptr %19, i64 0, i64 %20
  store ptr %2, ptr %21, align 8, !tbaa !15
  %22 = add nuw nsw i8 %.sink, 1
  store i8 %22, ptr %.sink15, align 2, !tbaa !17
  br label %23

23:                                               ; preds = %.sink.split, %7, %15, %11
  %.0 = phi i8 [ 0, %11 ], [ 0, %15 ], [ 0, %7 ], [ 1, %.sink.split ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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, !10, i64 1048}
!6 = !{!"NetIfaceStruct", !7, i64 0, !8, i64 4, !10, i64 6, !8, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !8, i64 24, !11, i64 1048, !11, i64 1312}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"NetFragStruct", !10, i64 0, !8, i64 2, !8, i64 8}
!12 = !{!6, !8, i64 1050}
!13 = !{!6, !10, i64 1312}
!14 = !{!6, !8, i64 1314}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!8, !8, i64 0}


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