; LLVM IR from china-hai/yd_crypto :: src/des_tdes (yd_tdes_cfb)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @yd_des_crypto(ptr noundef, ptr noundef, i8 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @yd_tdes_cfb8_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6) #2 {
  %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 i32, align 4
  %15 = alloca i8, align 1
  %16 = alloca [8 x i8], align 1
  %17 = alloca [8 x i8], align 1
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store i32 %6, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i8 0, ptr %15, align 1, !tbaa !11
  br label %19

19:                                               ; preds = %40, %7
  %20 = load i8, ptr %15, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 8
  br i1 %22, label %23, label %43

23:                                               ; preds = %19
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = load i8, ptr %15, align 1, !tbaa !11
  %26 = zext i8 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = load i8, ptr %15, align 1, !tbaa !11
  %30 = zext i8 %29 to i64
  %31 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 %30
  store i8 %28, ptr %31, align 1, !tbaa !11
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = load i8, ptr %15, align 1, !tbaa !11
  %34 = zext i8 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = load i8, ptr %15, align 1, !tbaa !11
  %38 = zext i8 %37 to i64
  %39 = getelementptr inbounds [8 x i8], ptr %17, i64 0, i64 %38
  store i8 %36, ptr %39, align 1, !tbaa !11
  br label %40

40:                                               ; preds = %23
  %41 = load i8, ptr %15, align 1, !tbaa !11
  %42 = add i8 %41, 1
  store i8 %42, ptr %15, align 1, !tbaa !11
  br label %19, !llvm.loop !12

43:                                               ; preds = %19
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %110, %43
  %45 = load i32, ptr %18, align 4, !tbaa !9
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = icmp ult i32 %45, %46
  br i1 %47, label %48, label %113

48:                                               ; preds = %44
  %49 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  call void @yd_des_crypto(ptr noundef %49, ptr noundef %50, i8 noundef zeroext 0)
  %51 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  call void @yd_des_crypto(ptr noundef %51, ptr noundef %52, i8 noundef zeroext 1)
  %53 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  call void @yd_des_crypto(ptr noundef %53, ptr noundef %54, i8 noundef zeroext 0)
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %18, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = zext i8 %59 to i32
  %61 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = zext i8 %62 to i32
  %64 = xor i32 %60, %63
  %65 = trunc i32 %64 to i8
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i32, ptr %18, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  store i8 %65, ptr %69, align 1, !tbaa !11
  store i8 0, ptr %15, align 1, !tbaa !11
  br label %70

70:                                               ; preds = %84, %48
  %71 = load i8, ptr %15, align 1, !tbaa !11
  %72 = zext i8 %71 to i32
  %73 = icmp slt i32 %72, 7
  br i1 %73, label %74, label %87

74:                                               ; preds = %70
  %75 = load i8, ptr %15, align 1, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = add nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [8 x i8], ptr %17, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = load i8, ptr %15, align 1, !tbaa !11
  %82 = zext i8 %81 to i64
  %83 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 %82
  store i8 %80, ptr %83, align 1, !tbaa !11
  br label %84

84:                                               ; preds = %74
  %85 = load i8, ptr %15, align 1, !tbaa !11
  %86 = add i8 %85, 1
  store i8 %86, ptr %15, align 1, !tbaa !11
  br label %70, !llvm.loop !14

87:                                               ; preds = %70
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %18, align 4, !tbaa !9
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %88, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !11
  %93 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 7
  store i8 %92, ptr %93, align 1, !tbaa !11
  store i8 0, ptr %15, align 1, !tbaa !11
  br label %94

94:                                               ; preds = %106, %87
  %95 = load i8, ptr %15, align 1, !tbaa !11
  %96 = zext i8 %95 to i32
  %97 = icmp slt i32 %96, 8
  br i1 %97, label %98, label %109

98:                                               ; preds = %94
  %99 = load i8, ptr %15, align 1, !tbaa !11
  %100 = zext i8 %99 to i64
  %101 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 %100
  %102 = load i8, ptr %101, align 1, !tbaa !11
  %103 = load i8, ptr %15, align 1, !tbaa !11
  %104 = zext i8 %103 to i64
  %105 = getelementptr inbounds [8 x i8], ptr %17, i64 0, i64 %104
  store i8 %102, ptr %105, align 1, !tbaa !11
  br label %106

106:                                              ; preds = %98
  %107 = load i8, ptr %15, align 1, !tbaa !11
  %108 = add i8 %107, 1
  store i8 %108, ptr %15, align 1, !tbaa !11
  br label %94, !llvm.loop !15

109:                                              ; preds = %94
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %18, align 4, !tbaa !9
  %112 = add i32 %111, 1
  store i32 %112, ptr %18, align 4, !tbaa !9
  br label %44, !llvm.loop !16

113:                                              ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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/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}
!16 = distinct !{!16, !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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @yd_des_crypto(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @yd_tdes_cfb8_decrypt(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr nocapture noundef readonly %5, i32 noundef %6) local_unnamed_addr #2 {
.preheader:
  %7 = alloca [8 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %8 = load i64, ptr %5, align 1, !tbaa !5
  store i64 %8, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %7, i64 7
  %wide.trip.count = zext i32 %6 to i64
  %.sroa.0.0.peel = load i64, ptr %5, align 1, !tbaa !5
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %2, i8 noundef zeroext 0) #3
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %3, i8 noundef zeroext 1) #3
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %4, i8 noundef zeroext 0) #3
  %10 = load i8, ptr %0, align 1, !tbaa !5
  %11 = load i8, ptr %7, align 8, !tbaa !5
  %12 = xor i8 %11, %10
  store i8 %12, ptr %1, align 1, !tbaa !5
  %.sroa.0.1.extract.shift.peel = lshr i64 %.sroa.0.0.peel, 8
  %.sroa.0.1.extract.trunc.peel = trunc nuw i64 %.sroa.0.1.extract.shift.peel to i56
  store i56 %.sroa.0.1.extract.trunc.peel, ptr %7, align 8, !tbaa !5
  %13 = load i8, ptr %0, align 1, !tbaa !5
  store i8 %13, ptr %9, align 1, !tbaa !5
  %exitcond.not.peel = icmp eq i32 %6, 1
  br i1 %exitcond.not.peel, label %._crit_edge, label %.lr.ph.peel.newph

.lr.ph.peel.newph:                                ; preds = %.lr.ph, %.lr.ph.peel.newph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.peel.newph ], [ 1, %.lr.ph ]
  %.sroa.0.0 = load i64, ptr %7, align 8, !tbaa !5
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %2, i8 noundef zeroext 0) #3
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %3, i8 noundef zeroext 1) #3
  call void @yd_des_crypto(ptr noundef nonnull %7, ptr noundef %4, i8 noundef zeroext 0) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = load i8, ptr %7, align 8, !tbaa !5
  %17 = xor i8 %16, %15
  %18 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %17, ptr %18, align 1, !tbaa !5
  %.sroa.0.1.extract.shift = lshr i64 %.sroa.0.0, 8
  %.sroa.0.1.extract.trunc = trunc nuw i64 %.sroa.0.1.extract.shift to i56
  store i56 %.sroa.0.1.extract.trunc, ptr %7, align 8, !tbaa !5
  %19 = load i8, ptr %14, align 1, !tbaa !5
  store i8 %19, ptr %9, align 1, !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 %._crit_edge, label %.lr.ph.peel.newph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.peel.newph, %.preheader
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.peeled.count", i32 1}


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