; LLVM IR from china-hai/yd_crypto :: src/aes (yd_aes_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_aes_encrypt(ptr noundef, ptr noundef) #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_aes_cfb8_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %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 [16 x i8], align 16
  %13 = alloca [16 x i8], align 16
  %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 16, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 16, 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, 16
  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 [16 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 [16 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 [16 x i8], ptr %12, i64 0, i64 0
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  call void @yd_aes_encrypt(ptr noundef %45, ptr noundef %46)
  %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 [16 x i8], ptr %12, i64 0, i64 0
  %54 = load i8, ptr %53, align 16, !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
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %76, %44
  %63 = load i8, ptr %11, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = icmp slt i32 %64, 15
  br i1 %65, label %66, label %79

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

76:                                               ; preds = %66
  %77 = load i8, ptr %11, align 1, !tbaa !11
  %78 = add i8 %77, 1
  store i8 %78, ptr %11, align 1, !tbaa !11
  br label %62, !llvm.loop !14

79:                                               ; preds = %62
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load i32, ptr %14, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 15
  store i8 %84, ptr %85, align 1, !tbaa !11
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %86

86:                                               ; preds = %98, %79
  %87 = load i8, ptr %11, align 1, !tbaa !11
  %88 = zext i8 %87 to i32
  %89 = icmp slt i32 %88, 16
  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 [16 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 [16 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 16, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #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_aes_encrypt(ptr noundef, ptr noundef) 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_aes_cfb8_decrypt(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #2 {
.preheader:
  %5 = alloca [16 x i8], align 16
  %6 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %5, ptr noundef nonnull align 1 dereferenceable(16) %3, i64 16, i1 false), !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %6, ptr noundef nonnull align 1 dereferenceable(16) %3, i64 16, 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 15
  %scevgep = getelementptr inbounds i8, ptr %6, i64 1
  %wide.trip.count = zext i32 %4 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  call void @yd_aes_encrypt(ptr noundef nonnull %5, ptr noundef %2) #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 16, !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 16 dereferenceable(15) %5, ptr noundef nonnull align 1 dereferenceable(15) %scevgep, i64 15, i1 false), !tbaa !5
  %14 = load i8, ptr %9, align 1, !tbaa !5
  store i8 %14, ptr %7, align 1, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %6, ptr noundef nonnull align 16 dereferenceable(16) %5, i64 16, 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 16, ptr nonnull %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  ret void
}

; 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 = { 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 = { 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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass