; LLVM IR from JamisHoo/Cryptographic-Algorithms :: src/des_ctr.ll (Z7des_ctrPKvmS0_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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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_ctr_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef, ptr noundef nonnull align 1 dereferenceable(96), ptr noundef) #0

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

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

30:                                               ; preds = %26
  store i32 2, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %76

31:                                               ; preds = %26
  %32 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %33, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  store i64 0, ptr %20, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %50, %31
  %35 = load i64, ptr %20, align 8, !tbaa !9
  %36 = icmp ult i64 %35, 8
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 5, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %53

38:                                               ; preds = %34
  %39 = load i64, ptr %20, align 8, !tbaa !9
  %40 = sub i64 7, %39
  %41 = getelementptr inbounds [8 x i8], ptr %15, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = load i64, ptr %20, align 8, !tbaa !9
  %45 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = xor i32 %47, %43
  %49 = trunc i32 %48 to i8
  store i8 %49, ptr %45, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %38
  %51 = load i64, ptr %20, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %20, align 8, !tbaa !9
  br label %34, !llvm.loop !12

53:                                               ; preds = %37
  %54 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load i64, ptr %18, align 8, !tbaa !9
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  call void @_Z17des_ctr_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef %54, ptr noundef nonnull align 1 dereferenceable(96) %17, ptr noundef %57)
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %58, align 8, !tbaa !9
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i64, ptr %18, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = zext i8 %64 to i32
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = load i64, ptr %18, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = zext i8 %69 to i32
  %71 = xor i32 %70, %65
  %72 = trunc i32 %71 to i8
  store i8 %72, ptr %68, align 1, !tbaa !11
  br label %73

73:                                               ; preds = %53
  %74 = load i64, ptr %18, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %18, align 8, !tbaa !9
  br label %26, !llvm.loop !14

76:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 96, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  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 = { 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 = !{!"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_ctr_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_ctrPKvmS0_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 1
  %7 = alloca %"struct.std::array", align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %7) #2
  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.preheader

.lr.ph.preheader:                                 ; preds = %5
  %8 = getelementptr inbounds i8, ptr %6, i64 1
  %9 = getelementptr inbounds i8, ptr %6, i64 2
  %10 = getelementptr inbounds i8, ptr %6, i64 3
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  %12 = getelementptr inbounds i8, ptr %6, i64 5
  %13 = getelementptr inbounds i8, ptr %6, i64 6
  %14 = getelementptr inbounds i8, ptr %6, i64 7
  br label %.lr.ph

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.sroa.12.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.12.0.extract.trunc, %.lr.ph ]
  %.sroa.11.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.11.0.extract.trunc, %.lr.ph ]
  %.sroa.10.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.10.0.extract.trunc, %.lr.ph ]
  %.sroa.9.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.9.0.extract.trunc, %.lr.ph ]
  %.sroa.8.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.8.0.extract.trunc, %.lr.ph ]
  %.sroa.7.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.7.0.extract.trunc, %.lr.ph ]
  %.sroa.6.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.6.0.extract.trunc, %.lr.ph ]
  %.sroa.0.0 = phi i8 [ 0, %.lr.ph.preheader ], [ %.sroa.0.0.extract.trunc, %.lr.ph ]
  %.01820 = phi i64 [ 0, %.lr.ph.preheader ], [ %45, %.lr.ph ]
  %15 = load i64, ptr %3, align 1
  %16 = trunc i64 %15 to i8
  %17 = xor i8 %.sroa.12.0, %16
  store i8 %17, ptr %6, align 1, !tbaa !5
  %18 = lshr i64 %15, 8
  %19 = trunc i64 %18 to i8
  %20 = xor i8 %.sroa.11.0, %19
  store i8 %20, ptr %8, align 1, !tbaa !5
  %21 = lshr i64 %15, 16
  %22 = trunc i64 %21 to i8
  %23 = xor i8 %.sroa.10.0, %22
  store i8 %23, ptr %9, align 1, !tbaa !5
  %24 = lshr i64 %15, 24
  %25 = trunc i64 %24 to i8
  %26 = xor i8 %.sroa.9.0, %25
  store i8 %26, ptr %10, align 1, !tbaa !5
  %27 = lshr i64 %15, 32
  %28 = trunc i64 %27 to i8
  %29 = xor i8 %.sroa.8.0, %28
  store i8 %29, ptr %11, align 1, !tbaa !5
  %30 = lshr i64 %15, 40
  %31 = trunc i64 %30 to i8
  %32 = xor i8 %.sroa.7.0, %31
  store i8 %32, ptr %12, align 1, !tbaa !5
  %33 = lshr i64 %15, 48
  %34 = trunc i64 %33 to i8
  %35 = xor i8 %.sroa.6.0, %34
  store i8 %35, ptr %13, align 1, !tbaa !5
  %36 = lshr i64 %15, 56
  %37 = trunc nuw i64 %36 to i8
  %38 = xor i8 %.sroa.0.0, %37
  store i8 %38, ptr %14, align 1, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %4, i64 %.01820
  call void @_Z17des_ctr_iterationPKhRKSt5arrayIS1_IhLm6EELm16EEPh(ptr noundef nonnull %6, ptr noundef nonnull align 1 dereferenceable(96) %7, ptr noundef %39)
  %.sroa.12.0.insert.ext = zext i8 %.sroa.12.0 to i64
  %.sroa.12.0.insert.shift = shl nuw i64 %.sroa.12.0.insert.ext, 56
  %.sroa.11.0.insert.ext = zext i8 %.sroa.11.0 to i64
  %.sroa.11.0.insert.shift = shl nuw nsw i64 %.sroa.11.0.insert.ext, 48
  %.sroa.11.0.insert.insert = or disjoint i64 %.sroa.12.0.insert.shift, %.sroa.11.0.insert.shift
  %.sroa.10.0.insert.ext = zext i8 %.sroa.10.0 to i64
  %.sroa.10.0.insert.shift = shl nuw nsw i64 %.sroa.10.0.insert.ext, 40
  %.sroa.10.0.insert.insert = or disjoint i64 %.sroa.11.0.insert.insert, %.sroa.10.0.insert.shift
  %.sroa.9.0.insert.ext = zext i8 %.sroa.9.0 to i64
  %.sroa.9.0.insert.shift = shl nuw nsw i64 %.sroa.9.0.insert.ext, 32
  %.sroa.9.0.insert.insert = or disjoint i64 %.sroa.10.0.insert.insert, %.sroa.9.0.insert.shift
  %.sroa.8.0.insert.ext = zext i8 %.sroa.8.0 to i64
  %.sroa.8.0.insert.shift = shl nuw nsw i64 %.sroa.8.0.insert.ext, 24
  %.sroa.8.0.insert.insert = or disjoint i64 %.sroa.9.0.insert.insert, %.sroa.8.0.insert.shift
  %.sroa.7.0.insert.ext = zext i8 %.sroa.7.0 to i64
  %.sroa.7.0.insert.shift = shl nuw nsw i64 %.sroa.7.0.insert.ext, 16
  %.sroa.6.0.insert.ext = zext i8 %.sroa.6.0 to i64
  %.sroa.6.0.insert.shift = shl nuw nsw i64 %.sroa.6.0.insert.ext, 8
  %.sroa.6.0.insert.mask = or disjoint i64 %.sroa.8.0.insert.insert, %.sroa.7.0.insert.shift
  %.sroa.0.0.insert.ext = zext i8 %.sroa.0.0 to i64
  %.sroa.0.0.insert.mask = or i64 %.sroa.6.0.insert.mask, %.sroa.6.0.insert.shift
  %.sroa.0.0.insert.insert = or i64 %.sroa.0.0.insert.mask, %.sroa.0.0.insert.ext
  %40 = add i64 %.sroa.0.0.insert.insert, 1
  %.sroa.0.0.extract.trunc = trunc i64 %40 to i8
  %.sroa.6.0.extract.shift = lshr i64 %40, 8
  %.sroa.6.0.extract.trunc = trunc i64 %.sroa.6.0.extract.shift to i8
  %.sroa.7.0.extract.shift = lshr i64 %40, 16
  %.sroa.7.0.extract.trunc = trunc i64 %.sroa.7.0.extract.shift to i8
  %.sroa.8.0.extract.shift = lshr i64 %40, 24
  %.sroa.8.0.extract.trunc = trunc i64 %.sroa.8.0.extract.shift to i8
  %.sroa.9.0.extract.shift = lshr i64 %40, 32
  %.sroa.9.0.extract.trunc = trunc i64 %.sroa.9.0.extract.shift to i8
  %.sroa.10.0.extract.shift = lshr i64 %40, 40
  %.sroa.10.0.extract.trunc = trunc i64 %.sroa.10.0.extract.shift to i8
  %.sroa.11.0.extract.shift = lshr i64 %40, 48
  %.sroa.11.0.extract.trunc = trunc i64 %.sroa.11.0.extract.shift to i8
  %.sroa.12.0.extract.shift = lshr i64 %40, 56
  %.sroa.12.0.extract.trunc = trunc nuw i64 %.sroa.12.0.extract.shift to i8
  %41 = getelementptr inbounds i8, ptr %0, i64 %.01820
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = load i8, ptr %39, align 1, !tbaa !5
  %44 = xor i8 %43, %42
  store i8 %44, ptr %39, align 1, !tbaa !5
  %45 = add nuw i64 %.01820, 1
  %exitcond.not = icmp eq i64 %45, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8
}

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 = { 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass