; LLVM IR from intel/cryptography-primitives :: sources/ippcp (pcpbnu32_getoctstr)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cpToOctStr_BNU32(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = call i32 @cpFix_BNU32(ptr noundef %15, i32 noundef %16)
  store i32 %17, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = mul nsw i32 %18, 32
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %20, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = call i32 @cpNLZ_BNU32(i32 noundef %25)
  %27 = sub nsw i32 %19, %26
  store i32 %27, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = mul nsw i32 %29, 8
  %31 = icmp sle i32 %28, %30
  br i1 %31, label %32, label %120

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %33, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  store i32 %38, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %48, %32
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %39
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !11
  br label %48

48:                                               ; preds = %43
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %12, align 4, !tbaa !9
  br label %39, !llvm.loop !12

51:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add nsw i32 %53, 7
  %55 = ashr i32 %54, 3
  %56 = sub nsw i32 %52, %55
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds i8, ptr %57, i64 %58
  store ptr %59, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %118

62:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = call i32 @cpNLZ_BNU32(i32 noundef %63)
  %65 = sdiv i32 %64, 8
  store i32 %65, ptr %13, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %78, %62
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = icmp slt i32 %67, 4
  br i1 %68, label %69, label %81

69:                                               ; preds = %66
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = sub nsw i32 3, %71
  %73 = mul nsw i32 8, %72
  %74 = lshr i32 %70, %73
  %75 = trunc i32 %74 to i8
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %6, align 8, !tbaa !5
  store i8 %75, ptr %76, align 1, !tbaa !11
  br label %78

78:                                               ; preds = %69
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %13, align 4, !tbaa !9
  br label %66, !llvm.loop !14

81:                                               ; preds = %66
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = add nsw i32 %82, -1
  store i32 %83, ptr %9, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %114, %81
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = icmp sgt i32 %85, 0
  br i1 %86, label %87, label %117

87:                                               ; preds = %84
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = sub nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i32, ptr %88, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !9
  store i32 %93, ptr %11, align 4, !tbaa !9
  %94 = load i32, ptr %11, align 4, !tbaa !9
  %95 = lshr i32 %94, 24
  %96 = trunc i32 %95 to i8
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i32 1
  store ptr %98, ptr %6, align 8, !tbaa !5
  store i8 %96, ptr %97, align 1, !tbaa !11
  %99 = load i32, ptr %11, align 4, !tbaa !9
  %100 = lshr i32 %99, 16
  %101 = trunc i32 %100 to i8
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds i8, ptr %102, i32 1
  store ptr %103, ptr %6, align 8, !tbaa !5
  store i8 %101, ptr %102, align 1, !tbaa !11
  %104 = load i32, ptr %11, align 4, !tbaa !9
  %105 = lshr i32 %104, 8
  %106 = trunc i32 %105 to i8
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds i8, ptr %107, i32 1
  store ptr %108, ptr %6, align 8, !tbaa !5
  store i8 %106, ptr %107, align 1, !tbaa !11
  %109 = load i32, ptr %11, align 4, !tbaa !9
  %110 = lshr i32 %109, 0
  %111 = trunc i32 %110 to i8
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = getelementptr inbounds i8, ptr %112, i32 1
  store ptr %113, ptr %6, align 8, !tbaa !5
  store i8 %111, ptr %112, align 1, !tbaa !11
  br label %114

114:                                              ; preds = %87
  %115 = load i32, ptr %9, align 4, !tbaa !9
  %116 = add nsw i32 %115, -1
  store i32 %116, ptr %9, align 4, !tbaa !9
  br label %84, !llvm.loop !15

117:                                              ; preds = %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %118

118:                                              ; preds = %117, %51
  %119 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %119, ptr %5, align 4
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %121

120:                                              ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %121

121:                                              ; preds = %120, %118
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %122 = load i32, ptr %5, align 4
  ret i32 %122
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU32(ptr noundef, i32 noundef) #1

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

declare i32 @cpNLZ_BNU32(i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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 noundef i32 @cpToOctStr_BNU32(ptr nocapture noundef writeonly %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @cpFix_BNU32(ptr noundef %2, i32 noundef %3)
  %6 = shl nsw i32 %5, 5
  %7 = sext i32 %5 to i64
  %8 = getelementptr i32, ptr %2, i64 %7
  %9 = getelementptr i8, ptr %8, i64 -4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = tail call i32 @cpNLZ_BNU32(i32 noundef %10) #4
  %12 = sub nsw i32 %6, %11
  %13 = shl nsw i32 %1, 3
  %.not = icmp sgt i32 %12, %13
  br i1 %.not, label %.loopexit, label %14

14:                                               ; preds = %4
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = icmp sgt i32 %1, 0
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %14
  %17 = zext nneg i32 %1 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %0, i8 0, i64 %17, i1 false), !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %14
  %.not45 = icmp eq i32 %15, 0
  br i1 %.not45, label %.loopexit, label %18

18:                                               ; preds = %._crit_edge
  %19 = add nsw i32 %12, 7
  %20 = ashr i32 %19, 3
  %21 = sub nsw i32 %1, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %0, i64 %22
  %24 = tail call i32 @cpNLZ_BNU32(i32 noundef %15) #4
  %25 = icmp slt i32 %24, 32
  br i1 %25, label %.lr.ph50.preheader, label %.preheader

.lr.ph50.preheader:                               ; preds = %18
  %26 = sdiv i32 %24, 8
  %27 = sub nsw i32 3, %26
  %28 = zext i32 %27 to i64
  %29 = add nuw nsw i64 %28, 1
  %min.iters.check = icmp ult i32 %27, 15
  br i1 %min.iters.check, label %.lr.ph50.preheader58, label %vector.ph

.lr.ph50.preheader58:                             ; preds = %middle.block, %.lr.ph50.preheader
  %.048.ph = phi i32 [ %26, %.lr.ph50.preheader ], [ %ind.end, %middle.block ]
  %.04147.ph = phi ptr [ %23, %.lr.ph50.preheader ], [ %ind.end56, %middle.block ]
  br label %.lr.ph50

vector.ph:                                        ; preds = %.lr.ph50.preheader
  %n.vec = and i64 %29, 8589934576
  %.cast = trunc i64 %n.vec to i32
  %ind.end = add i32 %26, %.cast
  %ind.end56 = getelementptr i8, ptr %23, i64 %n.vec
  %.splatinsert = insertelement <16 x i32> poison, i32 %26, i64 0
  %.splat = shufflevector <16 x i32> %.splatinsert, <16 x i32> poison, <16 x i32> zeroinitializer
  %induction = add <16 x i32> %.splat, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
  %broadcast.splatinsert = insertelement <16 x i32> poison, i32 %15, i64 0
  %broadcast.splat = shufflevector <16 x i32> %broadcast.splatinsert, <16 x i32> poison, <16 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <16 x i32> [ %induction, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %23, i64 %index
  %30 = shl <16 x i32> %vec.ind, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
  %31 = sub <16 x i32> <i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24, i32 24>, %30
  %32 = lshr <16 x i32> %broadcast.splat, %31
  %33 = trunc <16 x i32> %32 to <16 x i8>
  store <16 x i8> %33, ptr %next.gep, align 1, !tbaa !9
  %index.next = add nuw i64 %index, 16
  %vec.ind.next = add <16 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %29, %n.vec
  br i1 %cmp.n, label %.preheader, label %.lr.ph50.preheader58

.preheader:                                       ; preds = %.lr.ph50, %middle.block, %18
  %.041.lcssa = phi ptr [ %23, %18 ], [ %ind.end56, %middle.block ], [ %41, %.lr.ph50 ]
  %invariant.gep = getelementptr i8, ptr %2, i64 -8
  %35 = icmp sgt i32 %5, 1
  br i1 %35, label %.lr.ph53.preheader, label %.loopexit

.lr.ph53.preheader:                               ; preds = %.preheader
  %36 = zext nneg i32 %5 to i64
  br label %.lr.ph53

.lr.ph50:                                         ; preds = %.lr.ph50.preheader58, %.lr.ph50
  %.048 = phi i32 [ %42, %.lr.ph50 ], [ %.048.ph, %.lr.ph50.preheader58 ]
  %.04147 = phi ptr [ %41, %.lr.ph50 ], [ %.04147.ph, %.lr.ph50.preheader58 ]
  %37 = shl i32 %.048, 3
  %38 = sub i32 24, %37
  %39 = lshr i32 %15, %38
  %40 = trunc i32 %39 to i8
  %41 = getelementptr inbounds i8, ptr %.04147, i64 1
  store i8 %40, ptr %.04147, align 1, !tbaa !9
  %42 = add nsw i32 %.048, 1
  %exitcond.not = icmp eq i32 %.048, 3
  br i1 %exitcond.not, label %.preheader, label %.lr.ph50, !llvm.loop !14

.lr.ph53:                                         ; preds = %.lr.ph53.preheader, %.lr.ph53
  %indvars.iv = phi i64 [ %36, %.lr.ph53.preheader ], [ %indvars.iv.next, %.lr.ph53 ]
  %.151 = phi ptr [ %.041.lcssa, %.lr.ph53.preheader ], [ %54, %.lr.ph53 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  %43 = load i32, ptr %gep, align 4, !tbaa !5
  %44 = lshr i32 %43, 24
  %45 = trunc nuw i32 %44 to i8
  %46 = getelementptr inbounds i8, ptr %.151, i64 1
  store i8 %45, ptr %.151, align 1, !tbaa !9
  %47 = lshr i32 %43, 16
  %48 = trunc i32 %47 to i8
  %49 = getelementptr inbounds i8, ptr %.151, i64 2
  store i8 %48, ptr %46, align 1, !tbaa !9
  %50 = lshr i32 %43, 8
  %51 = trunc i32 %50 to i8
  %52 = getelementptr inbounds i8, ptr %.151, i64 3
  store i8 %51, ptr %49, align 1, !tbaa !9
  %53 = trunc i32 %43 to i8
  %54 = getelementptr inbounds i8, ptr %.151, i64 4
  store i8 %53, ptr %52, align 1, !tbaa !9
  %55 = icmp ugt i64 %indvars.iv, 2
  br i1 %55, label %.lr.ph53, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph53, %.preheader, %4, %._crit_edge
  %.039 = phi i32 [ %1, %._crit_edge ], [ 0, %4 ], [ %1, %.preheader ], [ %1, %.lr.ph53 ]
  ret i32 %.039
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpFix_BNU32(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @cpNLZ_BNU32(i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { inlinehint 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !13, !12}
!15 = distinct !{!15, !11}


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