; LLVM IR from catid/Zpng :: zstd (zstd_ldm)

; 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.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @ZSTD_ldm_adjustParameters(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %9, ptr %5, align 4, !tbaa !12
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ldmParams_t, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ldmParams_t, ptr %15, i32 0, i32 2
  store i32 3, ptr %16, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %14, %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ldmParams_t, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ldmParams_t, ptr %23, i32 0, i32 3
  store i32 64, ptr %24, align 4, !tbaa !15
  br label %25

25:                                               ; preds = %22, %17
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %26, i32 0, i32 6
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %29 = icmp uge i32 %28, 7
  br i1 %29, label %30, label %51

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ldmParams_t, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = icmp ugt i32 %33, %36
  br i1 %37, label %38, label %42

38:                                               ; preds = %30
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %39, i32 0, i32 5
  %41 = load i32, ptr %40, align 4, !tbaa !17
  br label %46

42:                                               ; preds = %30
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ldmParams_t, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !15
  br label %46

46:                                               ; preds = %42, %38
  %47 = phi i32 [ %41, %38 ], [ %45, %42 ]
  store i32 %47, ptr %6, align 4, !tbaa !12
  %48 = load i32, ptr %6, align 4, !tbaa !12
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ldmParams_t, ptr %49, i32 0, i32 3
  store i32 %48, ptr %50, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %51

51:                                               ; preds = %46, %25
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ldmParams_t, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !18
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %68

56:                                               ; preds = %51
  %57 = load i32, ptr %5, align 4, !tbaa !12
  %58 = sub i32 %57, 7
  %59 = icmp ugt i32 6, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %56
  br label %64

61:                                               ; preds = %56
  %62 = load i32, ptr %5, align 4, !tbaa !12
  %63 = sub i32 %62, 7
  br label %64

64:                                               ; preds = %61, %60
  %65 = phi i32 [ 6, %60 ], [ %63, %61 ]
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ldmParams_t, ptr %66, i32 0, i32 1
  store i32 %65, ptr %67, align 4, !tbaa !18
  br label %68

68:                                               ; preds = %64, %51
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ldmParams_t, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %70, align 4, !tbaa !19
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %90

73:                                               ; preds = %68
  %74 = load i32, ptr %5, align 4, !tbaa !12
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ldmParams_t, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !18
  %78 = icmp ult i32 %74, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %73
  br label %86

80:                                               ; preds = %73
  %81 = load i32, ptr %5, align 4, !tbaa !12
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ldmParams_t, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !18
  %85 = sub i32 %81, %84
  br label %86

86:                                               ; preds = %80, %79
  %87 = phi i32 [ 0, %79 ], [ %85, %80 ]
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ldmParams_t, ptr %88, i32 0, i32 4
  store i32 %87, ptr %89, align 4, !tbaa !19
  br label %90

90:                                               ; preds = %86, %68
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.ldmParams_t, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %92, align 4, !tbaa !13
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ldmParams_t, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !18
  %97 = icmp ult i32 %93, %96
  br i1 %97, label %98, label %102

98:                                               ; preds = %90
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.ldmParams_t, ptr %99, i32 0, i32 2
  %101 = load i32, ptr %100, align 4, !tbaa !13
  br label %106

102:                                              ; preds = %90
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.ldmParams_t, ptr %103, i32 0, i32 1
  %105 = load i32, ptr %104, align 4, !tbaa !18
  br label %106

106:                                              ; preds = %102, %98
  %107 = phi i32 [ %101, %98 ], [ %105, %102 ]
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.ldmParams_t, ptr %108, i32 0, i32 2
  store i32 %107, ptr %109, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; 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 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 = { 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!15 = !{!14, !11, i64 12}
!16 = !{!10, !11, i64 24}
!17 = !{!10, !11, i64 20}
!18 = !{!14, !11, i64 4}
!19 = !{!14, !11, i64 16}


; 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(argmem: readwrite) uwtable
define dso_local void @ZSTD_ldm_adjustParameters(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 4, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %.not31 = icmp eq i32 %7, 0
  br i1 %.not31, label %8, label %9

8:                                                ; preds = %2
  store i32 64, ptr %6, align 4, !tbaa !12
  br label %9

9:                                                ; preds = %8, %2
  %10 = phi i32 [ 64, %8 ], [ %7, %2 ]
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp ugt i32 %12, 6
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %1, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %. = tail call i32 @llvm.umax.i32(i32 %16, i32 %10)
  store i32 %., ptr %6, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %14, %9
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = add i32 %3, -7
  %23 = tail call i32 @llvm.umax.i32(i32 %22, i32 6)
  store i32 %23, ptr %18, align 4, !tbaa !15
  br label %24

24:                                               ; preds = %21, %17
  %25 = phi i32 [ %23, %21 ], [ %19, %17 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  %spec.select = tail call i32 @llvm.usub.sat.i32(i32 %3, i32 %25)
  store i32 %spec.select, ptr %26, align 4, !tbaa !16
  br label %30

30:                                               ; preds = %29, %24
  %.not = icmp eq i32 %5, 0
  %spec.select33 = select i1 %.not, i32 3, i32 %5
  %.32 = tail call i32 @llvm.umin.i32(i32 %spec.select33, i32 %25)
  store i32 %.32, ptr %4, align 4, !tbaa !10
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.usub.sat.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

!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 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!12 = !{!11, !7, i64 12}
!13 = !{!6, !7, i64 24}
!14 = !{!6, !7, i64 20}
!15 = !{!11, !7, i64 4}
!16 = !{!11, !7, i64 16}


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