; LLVM IR from openssl/openssl :: crypto/des (str2key)

; 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.DES_ks = type { [16 x %union.anon] }
%union.anon = type { [2 x i32] }

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

declare void @DES_set_odd_parity(ptr noundef) #3

declare void @DES_set_key_unchecked(ptr noundef, ptr noundef) #3

declare i32 @DES_cbc_cksum(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @DES_string_to_2keys(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.DES_ks, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %11, i8 0, i64 8, i1 false)
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 8, i1 false)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #7
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %122, %3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %125

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #6
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  store i8 %25, ptr %10, align 1, !tbaa !11
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = srem i32 %26, 32
  %28 = icmp slt i32 %27, 16
  br i1 %28, label %29, label %60

29:                                               ; preds = %20
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = srem i32 %30, 16
  %32 = icmp slt i32 %31, 8
  br i1 %32, label %33, label %46

33:                                               ; preds = %29
  %34 = load i8, ptr %10, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = shl i32 %35, 1
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = srem i32 %38, 8
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [8 x i8], ptr %37, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = xor i32 %43, %36
  %45 = trunc i32 %44 to i8
  store i8 %45, ptr %41, align 1, !tbaa !11
  br label %59

46:                                               ; preds = %29
  %47 = load i8, ptr %10, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = shl i32 %48, 1
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = srem i32 %51, 8
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [8 x i8], ptr %50, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = zext i8 %55 to i32
  %57 = xor i32 %56, %49
  %58 = trunc i32 %57 to i8
  store i8 %58, ptr %54, align 1, !tbaa !11
  br label %59

59:                                               ; preds = %46, %33
  br label %121

60:                                               ; preds = %20
  %61 = load i8, ptr %10, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = shl i32 %62, 4
  %64 = and i32 %63, 240
  %65 = load i8, ptr %10, align 1, !tbaa !11
  %66 = zext i8 %65 to i32
  %67 = ashr i32 %66, 4
  %68 = and i32 %67, 15
  %69 = or i32 %64, %68
  %70 = trunc i32 %69 to i8
  store i8 %70, ptr %10, align 1, !tbaa !11
  %71 = load i8, ptr %10, align 1, !tbaa !11
  %72 = zext i8 %71 to i32
  %73 = shl i32 %72, 2
  %74 = and i32 %73, 204
  %75 = load i8, ptr %10, align 1, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = ashr i32 %76, 2
  %78 = and i32 %77, 51
  %79 = or i32 %74, %78
  %80 = trunc i32 %79 to i8
  store i8 %80, ptr %10, align 1, !tbaa !11
  %81 = load i8, ptr %10, align 1, !tbaa !11
  %82 = zext i8 %81 to i32
  %83 = shl i32 %82, 1
  %84 = and i32 %83, 170
  %85 = load i8, ptr %10, align 1, !tbaa !11
  %86 = zext i8 %85 to i32
  %87 = ashr i32 %86, 1
  %88 = and i32 %87, 85
  %89 = or i32 %84, %88
  %90 = trunc i32 %89 to i8
  store i8 %90, ptr %10, align 1, !tbaa !11
  %91 = load i32, ptr %8, align 4, !tbaa !9
  %92 = srem i32 %91, 16
  %93 = icmp slt i32 %92, 8
  br i1 %93, label %94, label %107

94:                                               ; preds = %60
  %95 = load i8, ptr %10, align 1, !tbaa !11
  %96 = zext i8 %95 to i32
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = srem i32 %98, 8
  %100 = sub nsw i32 7, %99
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [8 x i8], ptr %97, i64 0, i64 %101
  %103 = load i8, ptr %102, align 1, !tbaa !11
  %104 = zext i8 %103 to i32
  %105 = xor i32 %104, %96
  %106 = trunc i32 %105 to i8
  store i8 %106, ptr %102, align 1, !tbaa !11
  br label %120

107:                                              ; preds = %60
  %108 = load i8, ptr %10, align 1, !tbaa !11
  %109 = zext i8 %108 to i32
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !9
  %112 = srem i32 %111, 8
  %113 = sub nsw i32 7, %112
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [8 x i8], ptr %110, i64 0, i64 %114
  %116 = load i8, ptr %115, align 1, !tbaa !11
  %117 = zext i8 %116 to i32
  %118 = xor i32 %117, %109
  %119 = trunc i32 %118 to i8
  store i8 %119, ptr %115, align 1, !tbaa !11
  br label %120

120:                                              ; preds = %107, %94
  br label %121

121:                                              ; preds = %120, %59
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #6
  br label %122

122:                                              ; preds = %121
  %123 = load i32, ptr %8, align 4, !tbaa !9
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !12

125:                                              ; preds = %16
  %126 = load i32, ptr %9, align 4, !tbaa !9
  %127 = icmp sle i32 %126, 8
  br i1 %127, label %128, label %131

128:                                              ; preds = %125
  %129 = load ptr, ptr %6, align 8, !tbaa !5
  %130 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %129, ptr align 1 %130, i64 8, i1 false)
  br label %131

131:                                              ; preds = %128, %125
  %132 = load ptr, ptr %5, align 8, !tbaa !5
  call void @DES_set_odd_parity(ptr noundef %132)
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  call void @DES_set_odd_parity(ptr noundef %133)
  %134 = load ptr, ptr %5, align 8, !tbaa !5
  call void @DES_set_key_unchecked(ptr noundef %134, ptr noundef %7)
  %135 = load ptr, ptr %4, align 8, !tbaa !5
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = load i32, ptr %9, align 4, !tbaa !9
  %138 = sext i32 %137 to i64
  %139 = load ptr, ptr %5, align 8, !tbaa !5
  %140 = call i32 @DES_cbc_cksum(ptr noundef %135, ptr noundef %136, i64 noundef %138, ptr noundef %7, ptr noundef %139)
  %141 = load ptr, ptr %6, align 8, !tbaa !5
  call void @DES_set_key_unchecked(ptr noundef %141, ptr noundef %7)
  %142 = load ptr, ptr %4, align 8, !tbaa !5
  %143 = load ptr, ptr %6, align 8, !tbaa !5
  %144 = load i32, ptr %9, align 4, !tbaa !9
  %145 = sext i32 %144 to i64
  %146 = load ptr, ptr %6, align 8, !tbaa !5
  %147 = call i32 @DES_cbc_cksum(ptr noundef %142, ptr noundef %143, i64 noundef %145, ptr noundef %7, ptr noundef %146)
  call void @OPENSSL_cleanse(ptr noundef %7, i64 noundef 128)
  %148 = load ptr, ptr %5, align 8, !tbaa !5
  call void @DES_set_odd_parity(ptr noundef %148)
  %149 = load ptr, ptr %6, align 8, !tbaa !5
  call void @DES_set_odd_parity(ptr noundef %149)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #6
  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) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind willreturn memory(read) "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 = { "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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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"}


; 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.DES_ks = type { [16 x %union.anon] }
%union.anon = type { [2 x i32] }

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture 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

declare void @DES_set_odd_parity(ptr noundef) local_unnamed_addr #2

declare void @DES_set_key_unchecked(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @DES_cbc_cksum(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @DES_string_to_2keys(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca %struct.DES_ks, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #5
  store i64 0, ptr %1, align 1
  store i64 0, ptr %2, align 1
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %6 = trunc i64 %5 to i32
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = and i64 %5, 2147483647
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %27 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  %11 = and i32 %10, 16
  %.not.not = icmp eq i32 %11, 0
  %12 = and i64 %indvars.iv, 7
  br i1 %.not.not, label %13, label %20

13:                                               ; preds = %.lr.ph
  %14 = and i32 %10, 8
  %.not.not47 = icmp eq i32 %14, 0
  %15 = shl i8 %9, 1
  br i1 %.not.not47, label %16, label %18

16:                                               ; preds = %13
  %17 = getelementptr inbounds [8 x i8], ptr %1, i64 0, i64 %12
  br label %27

18:                                               ; preds = %13
  %19 = getelementptr inbounds [8 x i8], ptr %2, i64 0, i64 %12
  br label %27

20:                                               ; preds = %.lr.ph
  %rev = tail call i8 @llvm.bitreverse.i8(i8 %9)
  %21 = and i32 %10, 8
  %.not.not46 = icmp eq i32 %21, 0
  %22 = xor i64 %12, 7
  br i1 %.not.not46, label %23, label %25

23:                                               ; preds = %20
  %24 = getelementptr inbounds [8 x i8], ptr %1, i64 0, i64 %22
  br label %27

25:                                               ; preds = %20
  %26 = getelementptr inbounds [8 x i8], ptr %2, i64 0, i64 %22
  br label %27

27:                                               ; preds = %23, %25, %16, %18
  %.sink = phi ptr [ %24, %23 ], [ %26, %25 ], [ %17, %16 ], [ %19, %18 ]
  %rev.sink = phi i8 [ %rev, %23 ], [ %rev, %25 ], [ %15, %16 ], [ %15, %18 ]
  %28 = load i8, ptr %.sink, align 1, !tbaa !5
  %29 = xor i8 %28, %rev.sink
  store i8 %29, ptr %.sink, 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, !llvm.loop !8

._crit_edge:                                      ; preds = %27
  %30 = icmp slt i32 %6, 9
  br i1 %30, label %._crit_edge.thread, label %32

._crit_edge.thread:                               ; preds = %3, %._crit_edge
  %31 = load i64, ptr %1, align 1
  store i64 %31, ptr %2, align 1
  br label %32

32:                                               ; preds = %._crit_edge.thread, %._crit_edge
  tail call void @DES_set_odd_parity(ptr noundef nonnull %1) #5
  tail call void @DES_set_odd_parity(ptr noundef nonnull %2) #5
  call void @DES_set_key_unchecked(ptr noundef nonnull %1, ptr noundef nonnull %4) #5
  %sext = shl i64 %5, 32
  %33 = ashr exact i64 %sext, 32
  %34 = call i32 @DES_cbc_cksum(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %33, ptr noundef nonnull %4, ptr noundef nonnull %1) #5
  call void @DES_set_key_unchecked(ptr noundef nonnull %2, ptr noundef nonnull %4) #5
  %35 = call i32 @DES_cbc_cksum(ptr noundef %0, ptr noundef nonnull %2, i64 noundef %33, ptr noundef nonnull %4, ptr noundef nonnull %2) #5
  call void @OPENSSL_cleanse(ptr noundef nonnull %4, i64 noundef 128) #5
  call void @DES_set_odd_parity(ptr noundef nonnull %1) #5
  call void @DES_set_odd_parity(ptr noundef nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.bitreverse.i8(i8) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass