; LLVM IR from attractivechaos/klib :: khmm (hmm_delete_par)

; 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.hmm_par_t = type { i32, i32, ptr, ptr, 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
define dso_local void @hmm_delete_par(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %81

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

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

15:                                               ; preds = %9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hmm_par_t, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  call void @free(ptr noundef %22) #3
  br label %23

23:                                               ; preds = %15
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 4, !tbaa !9
  br label %9, !llvm.loop !14

26:                                               ; preds = %9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %41, %26
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hmm_par_t, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %32 = icmp sle i32 %28, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %27
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.hmm_par_t, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  call void @free(ptr noundef %40) #3
  br label %41

41:                                               ; preds = %33
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !9
  br label %27, !llvm.loop !18

44:                                               ; preds = %27
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %64, %44
  %46 = load i32, ptr %3, align 4, !tbaa !9
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.hmm_par_t, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = add nsw i32 %49, 1
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.hmm_par_t, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = mul nsw i32 %50, %53
  %55 = icmp slt i32 %46, %54
  br i1 %55, label %56, label %67

56:                                               ; preds = %45
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hmm_par_t, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load i32, ptr %3, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %59, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  call void @free(ptr noundef %63) #3
  br label %64

64:                                               ; preds = %56
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !9
  br label %45, !llvm.loop !20

67:                                               ; preds = %45
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.hmm_par_t, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  call void @free(ptr noundef %70) #3
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.hmm_par_t, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  call void @free(ptr noundef %73) #3
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.hmm_par_t, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !21
  call void @free(ptr noundef %76) #3
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.hmm_par_t, ptr %77, i32 0, i32 4
  %79 = load ptr, ptr %78, align 8, !tbaa !19
  call void @free(ptr noundef %79) #3
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %80) #3
  store i32 0, ptr %4, align 4
  br label %81

81:                                               ; preds = %67, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %82 = load i32, ptr %4, align 4
  switch i32 %82, label %84 [
    i32 0, label %83
    i32 1, label %83
  ]

83:                                               ; preds = %81, %81
  ret void

84:                                               ; preds = %81
  unreachable
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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 "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 #3 = { 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 4}
!12 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !10, i64 0}
!17 = !{!12, !6, i64 16}
!18 = distinct !{!18, !15}
!19 = !{!12, !6, i64 24}
!20 = distinct !{!20, !15}
!21 = !{!12, !6, i64 32}


; 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
define dso_local void @hmm_delete_par(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %45, label %.preheader24

.preheader24:                                     ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not25 = icmp eq i32 %4, 0
  br i1 %.not25, label %.preheader23, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader24
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

.preheader23:                                     ; preds = %9, %.preheader24
  %6 = phi i32 [ 0, %.preheader24 ], [ %13, %9 ]
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %.not2227 = icmp slt i32 %7, 0
  br i1 %.not2227, label %.preheader, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader23
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %21

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %10 = load ptr, ptr %5, align 8, !tbaa !12
  %11 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  tail call void @free(ptr noundef %12) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %.not = icmp eq i64 %indvars.iv.next, %14
  br i1 %.not, label %.preheader23, label %9, !llvm.loop !14

.preheader.loopexit:                              ; preds = %21
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.preheader23
  %15 = phi i32 [ %.pre, %.preheader.loopexit ], [ %6, %.preheader23 ]
  %16 = phi i32 [ %25, %.preheader.loopexit ], [ %7, %.preheader23 ]
  %17 = add nsw i32 %16, 1
  %18 = mul nsw i32 %17, %15
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph31, label %._crit_edge

.lr.ph31:                                         ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  br label %27

21:                                               ; preds = %.lr.ph29, %21
  %indvars.iv33 = phi i64 [ 0, %.lr.ph29 ], [ %indvars.iv.next34, %21 ]
  %22 = load ptr, ptr %8, align 8, !tbaa !16
  %23 = getelementptr inbounds ptr, ptr %22, i64 %indvars.iv33
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  tail call void @free(ptr noundef %24) #2
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %25 = load i32, ptr %0, align 8, !tbaa !11
  %26 = sext i32 %25 to i64
  %.not22.not = icmp slt i64 %indvars.iv33, %26
  br i1 %.not22.not, label %21, label %.preheader.loopexit, !llvm.loop !17

27:                                               ; preds = %.lr.ph31, %27
  %indvars.iv36 = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next37, %27 ]
  %28 = load ptr, ptr %20, align 8, !tbaa !18
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv36
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  tail call void @free(ptr noundef %30) #2
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %31 = load i32, ptr %0, align 8, !tbaa !11
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = mul nsw i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next37, %35
  br i1 %36, label %27, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %27, %.preheader
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  tail call void @free(ptr noundef %38) #2
  %39 = getelementptr inbounds i8, ptr %0, i64 16
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  tail call void @free(ptr noundef %40) #2
  %41 = getelementptr inbounds i8, ptr %0, i64 32
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  tail call void @free(ptr noundef %42) #2
  %43 = getelementptr inbounds i8, ptr %0, i64 24
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  tail call void @free(ptr noundef %44) #2
  tail call void @free(ptr noundef nonnull %0) #2
  br label %45

45:                                               ; preds = %1, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 16}
!17 = distinct !{!17, !15}
!18 = !{!6, !10, i64 24}
!19 = distinct !{!19, !15}
!20 = !{!6, !10, i64 32}


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