; LLVM IR from JamisHoo/Cryptographic-Algorithms :: src/des_cfb.ll (Z7des_cfbPKvmS0_S0_Pv)

; 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.std::array" = type { [16 x %"struct.std::array.0"] }
%"struct.std::array.0" = type { [6 x i8] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15generateSubkeysPKh(ptr dead_on_unwind noalias writable sret(%"struct.std::array") align 1, ptr 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17des_cfb_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef, ptr noundef nonnull align 1 dereferenceable(96), ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7des_cfbPKvmS0_S0_Pv(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca [8 x i8], align 1
  %15 = alloca %"struct.std::array", align 1
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %19, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %20, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %21, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %22 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr align 1 %23, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 96, ptr %15) #3
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_Z15generateSubkeysPKh(ptr dead_on_unwind writable sret(%"struct.std::array") align 1 %15, ptr noundef %24)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %67, %5
  %26 = load i64, ptr %16, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %70

30:                                               ; preds = %25
  %31 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = load i64, ptr %16, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  call void @_Z17des_cfb_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef %31, ptr noundef nonnull align 1 dereferenceable(96) %15, ptr noundef %34)
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load i64, ptr %16, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load i64, ptr %16, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = xor i32 %44, %39
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %42, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %58, %30
  %48 = load i64, ptr %18, align 8, !tbaa !9
  %49 = icmp ult i64 %48, 7
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 5, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %61

51:                                               ; preds = %47
  %52 = load i64, ptr %18, align 8, !tbaa !9
  %53 = add i64 %52, 1
  %54 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = load i64, ptr %18, align 8, !tbaa !9
  %57 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 %56
  store i8 %55, ptr %57, align 1, !tbaa !11
  br label %58

58:                                               ; preds = %51
  %59 = load i64, ptr %18, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %18, align 8, !tbaa !9
  br label %47, !llvm.loop !12

61:                                               ; preds = %50
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load i64, ptr %16, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !11
  %66 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 7
  store i8 %65, ptr %66, align 1, !tbaa !11
  br label %67

67:                                               ; preds = %61
  %68 = load i64, ptr %16, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %16, align 8, !tbaa !9
  br label %25, !llvm.loop !14

70:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 96, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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"

%"struct.std::array" = type { [16 x %"struct.std::array.0"] }
%"struct.std::array.0" = type { [6 x i8] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15generateSubkeysPKh(ptr dead_on_unwind noalias writable sret(%"struct.std::array") align 1, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17des_cfb_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef, ptr noundef nonnull align 1 dereferenceable(96), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7des_cfbPKvmS0_S0_Pv(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [8 x i8], align 8
  %7 = alloca %"struct.std::array", align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %8 = load i64, ptr %3, align 1
  store i64 %8, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %7) #3
  call void @_Z15generateSubkeysPKh(ptr dead_on_unwind nonnull writable sret(%"struct.std::array") align 1 %7, ptr noundef %2)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %9 = getelementptr inbounds i8, ptr %6, i64 7
  %scevgep = getelementptr inbounds i8, ptr %6, i64 1
  br label %10

._crit_edge:                                      ; preds = %10, %5
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret void

10:                                               ; preds = %.lr.ph, %10
  %.01921 = phi i64 [ 0, %.lr.ph ], [ %16, %10 ]
  %11 = getelementptr inbounds i8, ptr %4, i64 %.01921
  call void @_Z17des_cfb_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef nonnull %6, ptr noundef nonnull align 1 dereferenceable(96) %7, ptr noundef %11)
  %12 = getelementptr inbounds i8, ptr %0, i64 %.01921
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = load i8, ptr %11, align 1, !tbaa !5
  %15 = xor i8 %14, %13
  store i8 %15, ptr %11, align 1, !tbaa !5
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(7) %6, ptr noundef nonnull align 1 dereferenceable(7) %scevgep, i64 7, i1 false), !tbaa !5
  store i8 %15, ptr %9, align 1, !tbaa !5
  %16 = add nuw i64 %.01921, 1
  %exitcond.not = icmp eq i64 %16, %1
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !8
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress 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 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass