; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i64, i32, i32, i32, i32, i64, i32, i32, %struct.ldmParams_t, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ZSTD_customMem, i32, i32, ptr, ptr, i64, i32 }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_customMem = type { 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_adjustCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, i64 noundef, i64 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.ZSTD_compressionParameters, align 8
  %11 = alloca %struct.ZSTD_compressionParameters, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  store i32 %4, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 28, ptr %10) #3
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = icmp eq i64 %12, -1
  br i1 %13, label %14, label %24

14:                                               ; preds = %5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %15, i32 0, i32 6
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %20, i32 0, i32 6
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %7, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %19, %14, %5
  call void @llvm.lifetime.start.p0(i64 28, ptr %11) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !19
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !11
  call void @ZSTD_getCParams_internal(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %11, i32 noundef %27, i64 noundef %28, i64 noundef %29, i32 noundef %30)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %11, i64 28, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 28, ptr %11) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %31, i32 0, i32 13
  %33 = getelementptr inbounds %struct.ldmParams_t, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !21
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %38

36:                                               ; preds = %24
  %37 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %10, i32 0, i32 0
  store i32 27, ptr %37, align 4, !tbaa !22
  br label %38

38:                                               ; preds = %36, %24
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %39, i32 0, i32 1
  call void @ZSTD_overrideCParams(ptr noundef %10, ptr noundef %40)
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %44, i32 0, i32 20
  %46 = load i32, ptr %45, align 8, !tbaa !23
  call void @ZSTD_adjustCParams_internal(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %10, i64 noundef %41, i64 noundef %42, i32 noundef %43, i32 noundef %46)
  call void @llvm.lifetime.end.p0(i64 28, ptr %10) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_getCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, i32 noundef, i64 noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_overrideCParams(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 64}
!14 = !{!"ZSTD_CCtx_params_s", !12, i64 0, !15, i64 4, !16, i64 32, !12, i64 44, !12, i64 48, !10, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !10, i64 80, !12, i64 88, !12, i64 92, !17, i64 96, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !18, i64 152, !12, i64 176, !12, i64 180, !6, i64 184, !6, i64 192, !10, i64 200, !12, i64 208}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!17 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!14, !12, i64 44}
!20 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 12, i64 4, !11, i64 16, i64 4, !11, i64 20, i64 4, !11, i64 24, i64 4, !11}
!21 = !{!14, !12, i64 96}
!22 = !{!15, !12, i64 0}
!23 = !{!14, !12, i64 144}


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

%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_adjustCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, i64 noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.ZSTD_compressionParameters, align 8
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %6) #2
  %7 = icmp eq i64 %2, -1
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 64
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  %12 = zext nneg i32 %10 to i64
  %spec.select = select i1 %11, i64 %12, i64 -1
  br label %13

13:                                               ; preds = %8, %5
  %.0 = phi i64 [ %2, %5 ], [ %spec.select, %8 ]
  %14 = getelementptr inbounds i8, ptr %1, i64 44
  %15 = load i32, ptr %14, align 4, !tbaa !16
  call void @ZSTD_getCParams_internal(ptr dead_on_unwind nonnull writable sret(%struct.ZSTD_compressionParameters) align 4 %6, i32 noundef %15, i64 noundef %.0, i64 noundef %3, i32 noundef %4)
  %16 = getelementptr inbounds i8, ptr %1, i64 96
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  store i32 27, ptr %6, align 8, !tbaa !18
  br label %20

20:                                               ; preds = %19, %13
  %21 = getelementptr inbounds i8, ptr %1, i64 4
  call void @ZSTD_overrideCParams(ptr noundef nonnull %6, ptr noundef nonnull %21)
  %22 = getelementptr inbounds i8, ptr %1, i64 144
  %23 = load i32, ptr %22, align 8, !tbaa !19
  call void @ZSTD_adjustCParams_internal(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %6, i64 noundef %.0, i64 noundef %3, i32 noundef %4, i32 noundef %23)
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %6) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_getCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, i32 noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_overrideCParams(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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, !7, i64 64}
!6 = !{!"ZSTD_CCtx_params_s", !7, i64 0, !10, i64 4, !11, i64 32, !7, i64 44, !7, i64 48, !12, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !12, i64 80, !7, i64 88, !7, i64 92, !13, i64 96, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !14, i64 152, !7, i64 176, !7, i64 180, !15, i64 184, !15, i64 192, !12, i64 200, !7, i64 208}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!6, !7, i64 44}
!17 = !{!6, !7, i64 96}
!18 = !{!10, !7, i64 0}
!19 = !{!6, !7, i64 144}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass