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

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

15:                                               ; preds = %36, %5
  %16 = load i8, ptr %11, align 1, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = icmp slt i32 %17, 8
  br i1 %18, label %19, label %39

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

36:                                               ; preds = %19
  %37 = load i8, ptr %11, align 1, !tbaa !11
  %38 = add i8 %37, 1
  store i8 %38, ptr %11, align 1, !tbaa !11
  br label %15, !llvm.loop !12

39:                                               ; preds = %15
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %102, %39
  %41 = load i32, ptr %14, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp ult i32 %41, %42
  br i1 %43, label %44, label %105

44:                                               ; preds = %40
  %45 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 0
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  call void @yd_des_crypto(ptr noundef %45, ptr noundef %46, i8 noundef zeroext 0)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 0
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = xor i32 %52, %55
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  store i8 %57, ptr %61, align 1, !tbaa !11
  %62 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 0
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  store i8 %63, ptr %64, align 1, !tbaa !11
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %65

65:                                               ; preds = %79, %44
  %66 = load i8, ptr %11, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  %68 = icmp slt i32 %67, 7
  br i1 %68, label %69, label %82

69:                                               ; preds = %65
  %70 = load i8, ptr %11, align 1, !tbaa !11
  %71 = zext i8 %70 to i32
  %72 = add nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = load i8, ptr %11, align 1, !tbaa !11
  %77 = zext i8 %76 to i64
  %78 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %77
  store i8 %75, ptr %78, align 1, !tbaa !11
  br label %79

79:                                               ; preds = %69
  %80 = load i8, ptr %11, align 1, !tbaa !11
  %81 = add i8 %80, 1
  store i8 %81, ptr %11, align 1, !tbaa !11
  br label %65, !llvm.loop !14

82:                                               ; preds = %65
  %83 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 7
  store i8 %84, ptr %85, align 1, !tbaa !11
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %86

86:                                               ; preds = %98, %82
  %87 = load i8, ptr %11, align 1, !tbaa !11
  %88 = zext i8 %87 to i32
  %89 = icmp slt i32 %88, 8
  br i1 %89, label %90, label %101

90:                                               ; preds = %86
  %91 = load i8, ptr %11, align 1, !tbaa !11
  %92 = zext i8 %91 to i64
  %93 = getelementptr inbounds [8 x i8], ptr %12, i64 0, i64 %92
  %94 = load i8, ptr %93, align 1, !tbaa !11
  %95 = load i8, ptr %11, align 1, !tbaa !11
  %96 = zext i8 %95 to i64
  %97 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 %96
  store i8 %94, ptr %97, align 1, !tbaa !11
  br label %98

98:                                               ; preds = %90
  %99 = load i8, ptr %11, align 1, !tbaa !11
  %100 = add i8 %99, 1
  store i8 %100, ptr %11, align 1, !tbaa !11
  br label %86, !llvm.loop !15

101:                                              ; preds = %86
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %14, align 4, !tbaa !9
  %104 = add i32 %103, 1
  store i32 %104, ptr %14, align 4, !tbaa !9
  br label %40, !llvm.loop !16

105:                                              ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, 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 1, ptr %11) #3
  ret void
}

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

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

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

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 = { "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: nounwind uwtable
define dso_local void @yd_des_ofb8_enc_dec_crypto(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #0 {
.preheader:
  %5 = alloca [8 x i8], align 8
  %.sroa.5 = alloca [7 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %.sroa.5)
  %6 = load i64, ptr %3, align 1, !tbaa !5
  store i64 %6, ptr %5, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) %.sroa.5, ptr noundef nonnull align 1 dereferenceable(7) %.sroa.5.0..sroa_idx, i64 7, i1 false), !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %5, i64 7
  %wide.trip.count = zext i32 %4 to i64
  %.sroa.5.0..sroa_idx34 = getelementptr inbounds i8, ptr %5, i64 1
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  call void @yd_des_crypto(ptr noundef nonnull %5, ptr noundef %2, i8 noundef zeroext 0) #4
  %9 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = load i8, ptr %5, align 8, !tbaa !5
  %12 = xor i8 %11, %10
  %13 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %12, ptr %13, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(7) %5, ptr noundef nonnull align 1 dereferenceable(7) %.sroa.5, i64 7, i1 false), !tbaa !5
  store i8 %11, ptr %7, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) %.sroa.5, ptr noundef nonnull align 1 dereferenceable(7) %.sroa.5.0..sroa_idx34, i64 7, i1 false), !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 %8, !llvm.loop !8

._crit_edge:                                      ; preds = %8, %.preheader
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %.sroa.5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret void
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/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,ReassociatePass,SROAPass,SimplifyCFGPass