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

; 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"

@des_key = external hidden global [768 x i8], align 16
@ip_table = external hidden constant [64 x i8], align 16
@e_table = external hidden constant [48 x i8], align 16
@p_table = external hidden constant [32 x i8], align 16
@inv_ip_table = external hidden constant [64 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @yd_des_crypto(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca [64 x i8], align 16
  %11 = alloca [64 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  call void @key_proc(ptr noundef %12, ptr noundef @des_key)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @byte_to_bits(ptr noundef %13, ptr noundef %14)
  %15 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %16 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  call void @permutation(ptr noundef %15, ptr noundef %16, ptr noundef @ip_table, i8 noundef zeroext 64)
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %81, %3
  %18 = load i8, ptr %7, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = icmp slt i32 %19, 16
  br i1 %20, label %21, label %84

21:                                               ; preds = %17
  %22 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 32
  %23 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @permutation(ptr noundef %22, ptr noundef %23, ptr noundef @e_table, i8 noundef zeroext 48)
  %24 = load i8, ptr %6, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %21
  %28 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %29 = load i8, ptr %7, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = mul nsw i32 %30, 48
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [768 x i8], ptr @des_key, i64 0, i64 %32
  call void @byte_xor(ptr noundef %28, ptr noundef %33, i8 noundef zeroext 48)
  br label %42

34:                                               ; preds = %21
  %35 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %36 = load i8, ptr %7, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = sub nsw i32 15, %37
  %39 = mul nsw i32 %38, 48
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [768 x i8], ptr @des_key, i64 0, i64 %40
  call void @byte_xor(ptr noundef %35, ptr noundef %41, i8 noundef zeroext 48)
  br label %42

42:                                               ; preds = %34, %27
  %43 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @select_permutation(ptr noundef %43)
  %44 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %45 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 32
  call void @permutation(ptr noundef %44, ptr noundef %45, ptr noundef @p_table, i8 noundef zeroext 32)
  %46 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %47 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 32
  call void @byte_xor(ptr noundef %46, ptr noundef %47, i8 noundef zeroext 32)
  %48 = load i8, ptr %7, align 1, !tbaa !9
  %49 = zext i8 %48 to i32
  %50 = icmp ne i32 %49, 15
  br i1 %50, label %51, label %80

51:                                               ; preds = %42
  store i8 0, ptr %8, align 1, !tbaa !9
  br label %52

52:                                               ; preds = %76, %51
  %53 = load i8, ptr %8, align 1, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = icmp slt i32 %54, 32
  br i1 %55, label %56, label %79

56:                                               ; preds = %52
  %57 = load i8, ptr %8, align 1, !tbaa !9
  %58 = zext i8 %57 to i32
  %59 = add nsw i32 %58, 32
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !9
  store i8 %62, ptr %9, align 1, !tbaa !9
  %63 = load i8, ptr %8, align 1, !tbaa !9
  %64 = zext i8 %63 to i64
  %65 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9
  %67 = load i8, ptr %8, align 1, !tbaa !9
  %68 = zext i8 %67 to i32
  %69 = add nsw i32 %68, 32
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %70
  store i8 %66, ptr %71, align 1, !tbaa !9
  %72 = load i8, ptr %9, align 1, !tbaa !9
  %73 = load i8, ptr %8, align 1, !tbaa !9
  %74 = zext i8 %73 to i64
  %75 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %74
  store i8 %72, ptr %75, align 1, !tbaa !9
  br label %76

76:                                               ; preds = %56
  %77 = load i8, ptr %8, align 1, !tbaa !9
  %78 = add i8 %77, 1
  store i8 %78, ptr %8, align 1, !tbaa !9
  br label %52, !llvm.loop !10

79:                                               ; preds = %52
  br label %80

80:                                               ; preds = %79, %42
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr %7, align 1, !tbaa !9
  %83 = add i8 %82, 1
  store i8 %83, ptr %7, align 1, !tbaa !9
  br label %17, !llvm.loop !12

84:                                               ; preds = %17
  %85 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %86 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @permutation(ptr noundef %85, ptr noundef %86, ptr noundef @inv_ip_table, i8 noundef zeroext 64)
  %87 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  call void @bits_to_byte(ptr noundef %87, ptr noundef %88)
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  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: nounwind uwtable
declare hidden void @key_proc(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @byte_to_bits(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @permutation(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden void @byte_xor(ptr noundef, ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden void @select_permutation(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @bits_to_byte(ptr noundef, ptr noundef) #0

; 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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"

@des_key = external hidden global [768 x i8], align 16
@ip_table = external hidden constant [64 x i8], align 16
@e_table = external hidden constant [48 x i8], align 16
@p_table = external hidden constant [32 x i8], align 16
@inv_ip_table = external hidden constant [64 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @yd_des_crypto(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [64 x i8], align 16
  %5 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #2
  tail call void @key_proc(ptr noundef %1, ptr noundef nonnull @des_key)
  call void @byte_to_bits(ptr noundef %0, ptr noundef nonnull %4)
  call void @permutation(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull @ip_table, i8 noundef zeroext 64)
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = icmp eq i8 %2, 0
  %8 = getelementptr inbounds i8, ptr %4, i64 32
  %9 = getelementptr inbounds i8, ptr %5, i64 48
  %10 = getelementptr inbounds i8, ptr %5, i64 16
  br i1 %7, label %.split.us, label %.split

.split.us:                                        ; preds = %3, %.loopexit.us
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.loopexit.us ], [ 0, %3 ]
  call void @permutation(ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef nonnull @e_table, i8 noundef zeroext 48)
  %11 = mul nuw nsw i64 %indvars.iv29, 48
  %12 = getelementptr inbounds [768 x i8], ptr @des_key, i64 0, i64 %11
  call void @byte_xor(ptr noundef nonnull %4, ptr noundef nonnull %12, i8 noundef zeroext 48)
  call void @select_permutation(ptr noundef nonnull %4)
  call void @permutation(ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @p_table, i8 noundef zeroext 32)
  call void @byte_xor(ptr noundef nonnull %5, ptr noundef nonnull %8, i8 noundef zeroext 32)
  %.not.us = icmp eq i64 %indvars.iv29, 15
  br i1 %.not.us, label %.split21.us, label %.loopexit.us

.loopexit.us:                                     ; preds = %.split.us
  %13 = load <16 x i8>, ptr %6, align 16, !tbaa !5
  %14 = load <16 x i8>, ptr %5, align 16, !tbaa !5
  store <16 x i8> %14, ptr %6, align 16, !tbaa !5
  store <16 x i8> %13, ptr %5, align 16, !tbaa !5
  %15 = load <16 x i8>, ptr %9, align 16, !tbaa !5
  %16 = load <16 x i8>, ptr %10, align 16, !tbaa !5
  store <16 x i8> %16, ptr %9, align 16, !tbaa !5
  store <16 x i8> %15, ptr %10, align 16, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  br label %.split.us

.split:                                           ; preds = %3, %.loopexit
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 0, %3 ]
  call void @permutation(ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef nonnull @e_table, i8 noundef zeroext 48)
  %17 = sub nuw nsw i64 15, %indvars.iv
  %18 = mul nuw nsw i64 %17, 48
  %19 = getelementptr inbounds [768 x i8], ptr @des_key, i64 0, i64 %18
  call void @byte_xor(ptr noundef nonnull %4, ptr noundef nonnull %19, i8 noundef zeroext 48)
  call void @select_permutation(ptr noundef nonnull %4)
  call void @permutation(ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @p_table, i8 noundef zeroext 32)
  call void @byte_xor(ptr noundef nonnull %5, ptr noundef nonnull %8, i8 noundef zeroext 32)
  %.not = icmp eq i64 %indvars.iv, 15
  br i1 %.not, label %.split21.us, label %.loopexit

.loopexit:                                        ; preds = %.split
  %20 = load <16 x i8>, ptr %6, align 16, !tbaa !5
  %21 = load <16 x i8>, ptr %5, align 16, !tbaa !5
  store <16 x i8> %21, ptr %6, align 16, !tbaa !5
  store <16 x i8> %20, ptr %5, align 16, !tbaa !5
  %22 = load <16 x i8>, ptr %9, align 16, !tbaa !5
  %23 = load <16 x i8>, ptr %10, align 16, !tbaa !5
  store <16 x i8> %23, ptr %9, align 16, !tbaa !5
  store <16 x i8> %22, ptr %10, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %.split

.split21.us:                                      ; preds = %.split, %.split.us
  call void @permutation(ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef nonnull @inv_ip_table, i8 noundef zeroext 64)
  call void @bits_to_byte(ptr noundef nonnull %4, ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @key_proc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @byte_to_bits(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @permutation(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @byte_xor(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @select_permutation(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @bits_to_byte(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 = { 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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass