; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Cryptography/Shamir_Cipher (Shamir_Cipher)

; 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
declare dso_local i32 @mod_expo(i32 noundef, i32 noundef, i32 noundef) #0

; 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: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @split_number(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul i64 4, %14
  %16 = call noalias ptr @malloc(i64 noundef %15) #5
  store ptr %16, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul i64 4, %18
  %20 = call noalias ptr @malloc(i64 noundef %19) #5
  store ptr %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = getelementptr inbounds i32, ptr %22, i64 0
  store i32 %21, ptr %23, align 4, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %35, %3
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %24
  %29 = call i32 @rand() #4
  %30 = srem i32 %29, 256
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  store i32 %30, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %28
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %10, align 4, !tbaa !5
  br label %24, !llvm.loop !11

38:                                               ; preds = %24
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %79, %38
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %82

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %44, i64 0
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %11, align 4, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %67, %43
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %70

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = call i32 @mod_expo(i32 noundef %53, i32 noundef %54, i32 noundef 256)
  store i32 %55, ptr %12, align 4, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = mul nsw i32 %61, %62
  %64 = srem i32 %63, 256
  %65 = add nsw i32 %56, %64
  %66 = srem i32 %65, 256
  store i32 %66, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %67

67:                                               ; preds = %51
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !5
  br label %47, !llvm.loop !13

70:                                               ; preds = %47
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = add nsw i32 %71, 256
  %73 = srem i32 %72, 256
  store i32 %73, ptr %11, align 4, !tbaa !5
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  store i32 %74, ptr %78, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %79

79:                                               ; preds = %70
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %9, align 4, !tbaa !5
  br label %39, !llvm.loop !14

82:                                               ; preds = %39
  %83 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %83) #4
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %84
}

; Function Attrs: nounwind
declare i32 @rand() #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 = { 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 allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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
declare dso_local i32 @mod_expo(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @split_number(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %1 to i64
  %5 = shl nsw i64 %4, 2
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #4
  %7 = sext i32 %2 to i64
  %8 = shl nsw i64 %7, 2
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #4
  %10 = icmp sgt i32 %2, 1
  br i1 %10, label %.lr.ph.preheader, label %.preheader30.thread

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

.preheader30:                                     ; preds = %.lr.ph
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.preheader.lr.ph, label %._crit_edge36

.preheader30.thread:                              ; preds = %3
  %12 = icmp sgt i32 %1, 0
  br i1 %12, label %.preheader.lr.ph.split, label %._crit_edge36

.preheader.lr.ph:                                 ; preds = %.preheader30
  br i1 %10, label %.preheader.us.preheader, label %.preheader.lr.ph.split

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count52 = zext nneg i32 %1 to i64
  %wide.trip.count47 = zext nneg i32 %2 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv49 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next50, %._crit_edge.us ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %13 = trunc nuw nsw i64 %indvars.iv.next50 to i32
  br label %14

14:                                               ; preds = %.preheader.us, %14
  %indvars.iv44 = phi i64 [ 1, %.preheader.us ], [ %indvars.iv.next45, %14 ]
  %.02733.us = phi i32 [ %0, %.preheader.us ], [ %22, %14 ]
  %15 = trunc nuw nsw i64 %indvars.iv44 to i32
  %16 = tail call i32 @mod_expo(i32 noundef %13, i32 noundef %15, i32 noundef 256)
  %17 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv44
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 %18, %16
  %20 = srem i32 %19, 256
  %21 = add nsw i32 %20, %.02733.us
  %22 = srem i32 %21, 256
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count47
  br i1 %exitcond48.not, label %._crit_edge.us, label %14, !llvm.loop !9

._crit_edge.us:                                   ; preds = %14
  %23 = and i32 %22, 255
  %24 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv49
  store i32 %23, ptr %24, align 4, !tbaa !5
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %._crit_edge36, label %.preheader.us, !llvm.loop !11

.preheader.lr.ph.split:                           ; preds = %.preheader30.thread, %.preheader.lr.ph
  %25 = add nsw i32 %0, 256
  %26 = srem i32 %25, 256
  %wide.trip.count42 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  br i1 %min.iters.check, label %.preheader.preheader, label %vector.ph

.preheader.preheader:                             ; preds = %middle.block, %.preheader.lr.ph.split
  %indvars.iv39.ph = phi i64 [ 0, %.preheader.lr.ph.split ], [ %n.vec, %middle.block ]
  br label %.preheader

vector.ph:                                        ; preds = %.preheader.lr.ph.split
  %n.vec = and i64 %wide.trip.count42, 2147483640
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %26, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %27 = getelementptr inbounds i32, ptr %6, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <4 x i32> %broadcast.splat, ptr %27, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat, ptr %28, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count42
  br i1 %cmp.n, label %._crit_edge36, label %.preheader.preheader

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %30 = tail call i32 @rand() #5
  %31 = srem i32 %30, 256
  %32 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  store i32 %31, ptr %32, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader30, label %.lr.ph, !llvm.loop !15

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.preheader ], [ %indvars.iv39.ph, %.preheader.preheader ]
  %33 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv39
  store i32 %26, ptr %33, align 4, !tbaa !5
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge36, label %.preheader, !llvm.loop !16

._crit_edge36:                                    ; preds = %.preheader, %._crit_edge.us, %middle.block, %.preheader30.thread, %.preheader30
  tail call void @free(ptr noundef %9) #5
  ret ptr %6
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { 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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10, !14, !13}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass