; LLVM IR from musetronstar/tagd :: tagl/src (lemon)

; 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.lemon = type { ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.state = type { ptr, ptr, i32, ptr, i32, i32, i32, i32, i32, ptr, i32 }
%struct.config = type { ptr, i32, ptr, ptr, ptr, ptr, i32, ptr, ptr }
%struct.plink = type { ptr, 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 void @Plink_add(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @FindLinks(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %37, %1
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.lemon, ptr %10, i32 0, i32 3
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %14, label %40

14:                                               ; preds = %8
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.lemon, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.state, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  store ptr %24, ptr %4, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %32, %14
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %25
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.config, ptr %30, i32 0, i32 5
  store ptr %29, ptr %31, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %28
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.config, ptr %33, i32 0, i32 7
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  store ptr %35, ptr %4, align 8, !tbaa !5
  br label %25, !llvm.loop !19

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !21

40:                                               ; preds = %8
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %85, %40
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lemon, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %47, label %88

47:                                               ; preds = %41
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.lemon, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.state, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  store ptr %57, ptr %4, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %80, %47
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %84

61:                                               ; preds = %58
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.config, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !22
  store ptr %64, ptr %7, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %75, %61
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %79

68:                                               ; preds = %65
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.plink, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !23
  store ptr %71, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.config, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  call void @Plink_add(ptr noundef %73, ptr noundef %74)
  br label %75

75:                                               ; preds = %68
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.plink, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !25
  store ptr %78, ptr %7, align 8, !tbaa !5
  br label %65, !llvm.loop !26

79:                                               ; preds = %65
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.config, ptr %81, i32 0, i32 7
  %83 = load ptr, ptr %82, align 8, !tbaa !18
  store ptr %83, ptr %4, align 8, !tbaa !5
  br label %58, !llvm.loop !27

84:                                               ; preds = %58
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %3, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %3, align 4, !tbaa !9
  br label %41, !llvm.loop !28

88:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  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 void
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"lemon", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !6, i64 72, !10, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !6, i64 280}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"state", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !6, i64 56, !10, i64 64}
!16 = !{!17, !6, i64 40}
!17 = !{!"config", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !6, i64 56, !6, i64 64}
!18 = !{!17, !6, i64 56}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{!17, !6, i64 32}
!23 = !{!24, !6, i64 0}
!24 = !{!"plink", !6, i64 0, !6, i64 8}
!25 = !{!24, !6, i64 8}
!26 = distinct !{!26, !20}
!27 = distinct !{!27, !20}
!28 = distinct !{!28, !20}


; 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 void @Plink_add(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @FindLinks(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph33, label %._crit_edge48

.lr.ph33:                                         ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %6 = icmp eq i32 %3, 1
  br i1 %6, label %.preheader.unr-lcssa, label %.lr.ph33.new

.lr.ph33.new:                                     ; preds = %.lr.ph33
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %12

.preheader.unr-lcssa:                             ; preds = %._crit_edge.1, %.lr.ph33
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next.1, %._crit_edge.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.unr-lcssa
  %7 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.unr
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %.02428.epil = load ptr, ptr %9, align 8, !tbaa !12
  %.not2729.epil = icmp eq ptr %.02428.epil, null
  br i1 %.not2729.epil, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.epil.preheader, %.lr.ph.epil
  %.02430.epil = phi ptr [ %.024.epil, %.lr.ph.epil ], [ %.02428.epil, %.epil.preheader ]
  %10 = getelementptr inbounds i8, ptr %.02430.epil, i64 40
  store ptr %8, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %.02430.epil, i64 56
  %.024.epil = load ptr, ptr %11, align 8, !tbaa !12
  %.not27.epil = icmp eq ptr %.024.epil, null
  br i1 %.not27.epil, label %.preheader, label %.lr.ph.epil, !llvm.loop !15

.preheader:                                       ; preds = %.epil.preheader, %.lr.ph.epil, %.preheader.unr-lcssa
  br i1 %4, label %.lr.ph47, label %._crit_edge48

12:                                               ; preds = %._crit_edge.1, %.lr.ph33.new
  %indvars.iv = phi i64 [ 0, %.lr.ph33.new ], [ %indvars.iv.next.1, %._crit_edge.1 ]
  %niter = phi i64 [ 0, %.lr.ph33.new ], [ %niter.next.1, %._crit_edge.1 ]
  %13 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %.02428 = load ptr, ptr %15, align 8, !tbaa !12
  %.not2729 = icmp eq ptr %.02428, null
  br i1 %.not2729, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.02430 = phi ptr [ %.024, %.lr.ph ], [ %.02428, %12 ]
  %16 = getelementptr inbounds i8, ptr %.02430, i64 40
  store ptr %14, ptr %16, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %.02430, i64 56
  %.024 = load ptr, ptr %17, align 8, !tbaa !12
  %.not27 = icmp eq ptr %.024, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %.02428.1 = load ptr, ptr %20, align 8, !tbaa !12
  %.not2729.1 = icmp eq ptr %.02428.1, null
  br i1 %.not2729.1, label %._crit_edge.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %.02430.1 = phi ptr [ %.024.1, %.lr.ph.1 ], [ %.02428.1, %._crit_edge ]
  %21 = getelementptr inbounds i8, ptr %.02430.1, i64 40
  store ptr %19, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %.02430.1, i64 56
  %.024.1 = load ptr, ptr %22, align 8, !tbaa !12
  %.not27.1 = icmp eq ptr %.024.1, null
  br i1 %.not27.1, label %._crit_edge.1, label %.lr.ph.1, !llvm.loop !15

._crit_edge.1:                                    ; preds = %.lr.ph.1, %._crit_edge
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.unr-lcssa, label %12, !llvm.loop !17

.lr.ph47:                                         ; preds = %.preheader, %._crit_edge45
  %23 = phi i32 [ %33, %._crit_edge45 ], [ %3, %.preheader ]
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %._crit_edge45 ], [ 0, %.preheader ]
  %24 = load ptr, ptr %0, align 8, !tbaa !11
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv50
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %.12540 = load ptr, ptr %27, align 8, !tbaa !12
  %.not41 = icmp eq ptr %.12540, null
  br i1 %.not41, label %._crit_edge45, label %.lr.ph44

.lr.ph44:                                         ; preds = %.lr.ph47, %._crit_edge39
  %.12542 = phi ptr [ %.125, %._crit_edge39 ], [ %.12540, %.lr.ph47 ]
  %28 = getelementptr inbounds i8, ptr %.12542, i64 32
  %.034 = load ptr, ptr %28, align 8, !tbaa !12
  %.not2635 = icmp eq ptr %.034, null
  br i1 %.not2635, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph44, %.lr.ph38
  %.036 = phi ptr [ %.0, %.lr.ph38 ], [ %.034, %.lr.ph44 ]
  %29 = load ptr, ptr %.036, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %29, i64 24
  tail call void @Plink_add(ptr noundef nonnull %30, ptr noundef nonnull %.12542)
  %31 = getelementptr inbounds i8, ptr %.036, i64 8
  %.0 = load ptr, ptr %31, align 8, !tbaa !12
  %.not26 = icmp eq ptr %.0, null
  br i1 %.not26, label %._crit_edge39, label %.lr.ph38, !llvm.loop !20

._crit_edge39:                                    ; preds = %.lr.ph38, %.lr.ph44
  %32 = getelementptr inbounds i8, ptr %.12542, i64 56
  %.125 = load ptr, ptr %32, align 8, !tbaa !12
  %.not = icmp eq ptr %.125, null
  br i1 %.not, label %._crit_edge45.loopexit, label %.lr.ph44, !llvm.loop !21

._crit_edge45.loopexit:                           ; preds = %._crit_edge39
  %.pre = load i32, ptr %2, align 8, !tbaa !5
  br label %._crit_edge45

._crit_edge45:                                    ; preds = %._crit_edge45.loopexit, %.lr.ph47
  %33 = phi i32 [ %.pre, %._crit_edge45.loopexit ], [ %23, %.lr.ph47 ]
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next51, %34
  br i1 %35, label %.lr.ph47, label %._crit_edge48, !llvm.loop !22

._crit_edge48:                                    ; preds = %._crit_edge45, %1, %.preheader
  ret void
}

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, !10, i64 24}
!6 = !{!"lemon", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !7, i64 280}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 40}
!14 = !{!"config", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !7, i64 64}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !7, i64 0}
!19 = !{!"plink", !7, i64 0, !7, i64 8}
!20 = distinct !{!20, !16}
!21 = distinct !{!21, !16}
!22 = distinct !{!22, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass