; LLVM IR from JamisHoo/Cryptographic-Algorithms :: src/des_cbc.ll (Z15generateSubkeysPKh)

; 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] }
%class.anon = type { i8 }

@__const._Z15generateSubkeysPKh.pc1 = external hidden unnamed_addr constant [56 x i64], align 16
@__const._Z15generateSubkeysPKh.pc2 = external hidden unnamed_addr constant [48 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15generateSubkeysPKh(ptr dead_on_unwind noalias writable sret(%"struct.std::array") align 1 %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca [56 x i64], align 16
  %5 = alloca [48 x i64], align 16
  %6 = alloca %class.anon, align 1
  %7 = alloca [7 x i8], align 1
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 448, ptr %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const._Z15generateSubkeysPKh.pc1, i64 448, i1 false)
  call void @llvm.lifetime.start.p0(i64 384, ptr %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const._Z15generateSubkeysPKh.pc2, i64 384, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 7, ptr %7) #6
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 7, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %25, %2
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 56
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %28

16:                                               ; preds = %12
  %17 = getelementptr inbounds [7 x i8], ptr %7, i64 0, i64 0
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = getelementptr inbounds [56 x i64], ptr %4, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = sub i64 %22, 1
  %24 = call noundef zeroext i1 @_Z6getbitPKvm(ptr noundef %19, i64 noundef %23)
  call void @_Z6setbitPvmb(ptr noundef %17, i64 noundef %18, i1 noundef zeroext %24)
  br label %25

25:                                               ; preds = %16
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !9
  br label %12, !llvm.loop !11

28:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %68, %28
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = icmp ult i64 %30, 16
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %71

33:                                               ; preds = %29
  %34 = getelementptr inbounds [7 x i8], ptr %7, i64 0, i64 0
  call void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1) %6, ptr noundef %34)
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %48

37:                                               ; preds = %33
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = icmp ne i64 %38, 1
  br i1 %39, label %40, label %48

40:                                               ; preds = %37
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = icmp ne i64 %41, 8
  br i1 %42, label %43, label %48

43:                                               ; preds = %40
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = icmp ne i64 %44, 15
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = getelementptr inbounds [7 x i8], ptr %7, i64 0, i64 0
  call void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1) %6, ptr noundef %47)
  br label %48

48:                                               ; preds = %46, %43, %40, %37, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %64, %48
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = icmp ult i64 %50, 48
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %67

53:                                               ; preds = %49
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = call noundef nonnull align 1 dereferenceable(6) ptr @_ZNSt5arrayIS_IhLm6EELm16EEixEm(ptr noundef nonnull align 1 dereferenceable(96) %0, i64 noundef %54) #6
  %56 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm6EEixEm(ptr noundef nonnull align 1 dereferenceable(6) %55, i64 noundef 0) #6
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = getelementptr inbounds [7 x i8], ptr %7, i64 0, i64 0
  %59 = load i64, ptr %11, align 8, !tbaa !9
  %60 = getelementptr inbounds [48 x i64], ptr %5, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = sub i64 %61, 1
  %63 = call noundef zeroext i1 @_Z6getbitPKvm(ptr noundef %58, i64 noundef %62)
  call void @_Z6setbitPvmb(ptr noundef %56, i64 noundef %57, i1 noundef zeroext %63)
  br label %64

64:                                               ; preds = %53
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %11, align 8, !tbaa !9
  br label %49, !llvm.loop !13

67:                                               ; preds = %52
  br label %68

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

71:                                               ; preds = %32
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 7, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 384, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 448, ptr %4) #6
  ret void
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z6setbitPvmb(ptr noundef, i64 noundef, i1 noundef zeroext) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6getbitPKvm(ptr noundef, i64 noundef) #4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(6) ptr @_ZNSt5arrayIS_IhLm6EELm16EEixEm(ptr noundef nonnull align 1 dereferenceable(96), i64 noundef) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm6EEixEm(ptr noundef nonnull align 1 dereferenceable(6), i64 noundef) #5 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint mustprogress 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 #5 = { mustprogress 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 #6 = { 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 = 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"

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

@__const._Z15generateSubkeysPKh.pc1 = external hidden unnamed_addr constant [56 x i64], align 16
@__const._Z15generateSubkeysPKh.pc2 = external hidden unnamed_addr constant [48 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z15generateSubkeysPKh(ptr dead_on_unwind noalias writable sret(%"struct.std::array") align 1 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %class.anon, align 1
  %4 = alloca [7 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) %4, i8 0, i64 7, i1 false)
  br label %5

5:                                                ; preds = %2, %5
  %.02122 = phi i64 [ 0, %2 ], [ %10, %5 ]
  %6 = getelementptr inbounds [56 x i64], ptr @__const._Z15generateSubkeysPKh.pc1, i64 0, i64 %.02122
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add i64 %7, -1
  %9 = call noundef zeroext i1 @_Z6getbitPKvm(ptr noundef %1, i64 noundef %8)
  call void @_Z6setbitPvmb(ptr noundef nonnull %4, i64 noundef %.02122, i1 noundef zeroext %9)
  %10 = add nuw nsw i64 %.02122, 1
  %exitcond.not = icmp eq i64 %10, 56
  br i1 %exitcond.not, label %.preheader, label %5, !llvm.loop !9

11:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  ret void

.preheader:                                       ; preds = %5, %13
  %.02024 = phi i64 [ %14, %13 ], [ 0, %5 ]
  call void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1) %3, ptr noundef nonnull %4)
  switch i64 %.02024, label %12 [
    i64 15, label %.preheader27
    i64 8, label %.preheader27
    i64 1, label %.preheader27
    i64 0, label %.preheader27
  ]

12:                                               ; preds = %.preheader
  call void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1) %3, ptr noundef nonnull %4)
  br label %.preheader27

.preheader27:                                     ; preds = %.preheader, %.preheader, %.preheader, %.preheader, %12
  br label %15

13:                                               ; preds = %15
  %14 = add nuw nsw i64 %.02024, 1
  %exitcond26.not = icmp eq i64 %14, 16
  br i1 %exitcond26.not, label %11, label %.preheader, !llvm.loop !11

15:                                               ; preds = %.preheader27, %15
  %.023 = phi i64 [ %22, %15 ], [ 0, %.preheader27 ]
  %16 = call noundef nonnull align 1 dereferenceable(6) ptr @_ZNSt5arrayIS_IhLm6EELm16EEixEm(ptr noundef nonnull align 1 dereferenceable(96) %0, i64 noundef %.02024) #4
  %17 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm6EEixEm(ptr noundef nonnull align 1 dereferenceable(6) %16, i64 noundef 0) #4
  %18 = getelementptr inbounds [48 x i64], ptr @__const._Z15generateSubkeysPKh.pc2, i64 0, i64 %.023
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add i64 %19, -1
  %21 = call noundef zeroext i1 @_Z6getbitPKvm(ptr noundef nonnull %4, i64 noundef %20)
  call void @_Z6setbitPvmb(ptr noundef nonnull %17, i64 noundef %.023, i1 noundef zeroext %21)
  %22 = add nuw nsw i64 %.023, 1
  %exitcond25.not = icmp eq i64 %22, 48
  br i1 %exitcond25.not, label %13, label %15, !llvm.loop !12
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z6setbitPvmb(ptr noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6getbitPKvm(ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @"_ZZ15generateSubkeysPKhENK3$_0clEPh"(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(6) ptr @_ZNSt5arrayIS_IhLm6EELm16EEixEm(ptr noundef nonnull align 1 dereferenceable(96), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm6EEixEm(ptr noundef nonnull align 1 dereferenceable(6), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint mustprogress 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass