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

; 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.repcodes_s = type { [3 x i32] }

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @ZSTD_updateRep(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca %struct.repcodes_s, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp uge i32 %11, 3
  br i1 %12, label %13, label %28

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i32, ptr %14, i64 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %18 = getelementptr inbounds [3 x i32], ptr %17, i64 0, i64 2
  store i32 %16, ptr %18, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %19, i64 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %23 = getelementptr inbounds [3 x i32], ptr %22, i64 0, i64 1
  store i32 %21, ptr %23, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sub i32 %24, 2
  %26 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %27 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 0
  store i32 %25, ptr %27, align 4, !tbaa !9
  br label %75

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add i32 %29, %30
  store i32 %31, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp ugt i32 %32, 0
  br i1 %33, label %34, label %72

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 3
  br i1 %36, label %37, label %42

37:                                               ; preds = %34
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i64 0
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sub i32 %40, 1
  br label %48

42:                                               ; preds = %34
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %42, %37
  %49 = phi i32 [ %41, %37 ], [ %47, %42 ]
  store i32 %49, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = icmp uge i32 %50, 2
  br i1 %51, label %52, label %56

52:                                               ; preds = %48
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i64 1
  %55 = load i32, ptr %54, align 4, !tbaa !9
  br label %60

56:                                               ; preds = %48
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i64 2
  %59 = load i32, ptr %58, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %56, %52
  %61 = phi i32 [ %55, %52 ], [ %59, %56 ]
  %62 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %63 = getelementptr inbounds [3 x i32], ptr %62, i64 0, i64 2
  store i32 %61, ptr %63, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i64 0
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %68 = getelementptr inbounds [3 x i32], ptr %67, i64 0, i64 1
  store i32 %66, ptr %68, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  %71 = getelementptr inbounds [3 x i32], ptr %70, i64 0, i64 0
  store i32 %69, ptr %71, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %74

72:                                               ; preds = %28
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %73, i64 12, i1 false)
  br label %74

74:                                               ; preds = %72, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %75

75:                                               ; preds = %74, %13
  %76 = getelementptr inbounds %struct.repcodes_s, ptr %4, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 4 %76, i64 12, i1 false)
  %77 = load { i64, i32 }, ptr %10, align 8
  ret { i64, i32 } %77
}

; 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

; 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) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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}


; 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(read, inaccessiblemem: none) uwtable
define dso_local { i64, i32 } @ZSTD_updateRep(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ugt i32 %1, 2
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %0, align 4, !tbaa !5
  %8 = add i32 %1, -2
  br label %22

9:                                                ; preds = %3
  %10 = add i32 %2, %1
  switch i32 %10, label %14 [
    i32 0, label %21
    i32 3, label %11
  ]

11:                                               ; preds = %9
  %12 = load i32, ptr %0, align 4, !tbaa !5
  %13 = add i32 %12, -1
  br label %18

14:                                               ; preds = %9
  %15 = zext i32 %10 to i64
  %16 = getelementptr inbounds i32, ptr %0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.pre = load i32, ptr %0, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %14, %11
  %19 = phi i32 [ %12, %11 ], [ %.pre, %14 ]
  %20 = phi i32 [ %13, %11 ], [ %17, %14 ]
  %.not19 = icmp eq i32 %10, 1
  %.in.v = select i1 %.not19, i64 8, i64 4
  %.in = getelementptr inbounds i8, ptr %0, i64 %.in.v
  br label %22

21:                                               ; preds = %9
  %.sroa.016.0.copyload = load i64, ptr %0, align 4
  %.sroa.016.sroa.0.0.extract.trunc = trunc i64 %.sroa.016.0.copyload to i32
  %.sroa.016.sroa.4.0.extract.shift = lshr i64 %.sroa.016.0.copyload, 32
  %.sroa.016.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.016.sroa.4.0.extract.shift to i32
  %.sroa.6.0..0.15.sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  br label %22

22:                                               ; preds = %18, %21, %5
  %.sroa.6.1.in = phi ptr [ %6, %5 ], [ %.in, %18 ], [ %.sroa.6.0..0.15.sroa_idx, %21 ]
  %.sroa.016.sroa.0.1 = phi i32 [ %8, %5 ], [ %20, %18 ], [ %.sroa.016.sroa.0.0.extract.trunc, %21 ]
  %.sroa.016.sroa.4.1 = phi i32 [ %7, %5 ], [ %19, %18 ], [ %.sroa.016.sroa.4.0.extract.trunc, %21 ]
  %.sroa.6.1 = load i32, ptr %.sroa.6.1.in, align 4
  %.sroa.016.sroa.4.0.insert.ext = zext i32 %.sroa.016.sroa.4.1 to i64
  %.sroa.016.sroa.4.0.insert.shift = shl nuw i64 %.sroa.016.sroa.4.0.insert.ext, 32
  %.sroa.016.sroa.0.0.insert.ext = zext i32 %.sroa.016.sroa.0.1 to i64
  %.sroa.016.sroa.0.0.insert.insert = or disjoint i64 %.sroa.016.sroa.4.0.insert.shift, %.sroa.016.sroa.0.0.insert.ext
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.016.sroa.0.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.6.1, 1
  ret { i64, i32 } %.fca.1.insert
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass