; LLVM IR from imkcat/CatCrypto :: Sources/ModuleMaps/MD6 (md6_mode)

; 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.md6_state = type { i32, i32, [128 x i8], [129 x i8], i32, i64, i64, i32, [8 x i64], i32, i32, i32, i32, [29 x [64 x i64]], [29 x i32], [29 x i64] }

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

; Function Attrs: nounwind uwtable
declare dso_local void @md6_reverse_little_endian(ptr noundef, i32 noundef) #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) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @md6_process(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @md6_compute_hex_hashval(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @trim_hashval(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @md6_final(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 3, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %82

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.md6_state, ptr %13, i32 0, i32 4
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  store i32 5, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %82

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.md6_state, ptr %19, i32 0, i32 7
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %82

24:                                               ; preds = %18
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.md6_state, ptr %25, i32 0, i32 12
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 1, ptr %6, align 4, !tbaa !15
  br label %51

30:                                               ; preds = %24
  store i32 1, ptr %6, align 4, !tbaa !15
  br label %31

31:                                               ; preds = %47, %30
  %32 = load i32, ptr %6, align 4, !tbaa !15
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.md6_state, ptr %33, i32 0, i32 12
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = icmp sle i32 %32, %35
  br i1 %36, label %37, label %50

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.md6_state, ptr %38, i32 0, i32 14
  %40 = load i32, ptr %6, align 4, !tbaa !15
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [29 x i32], ptr %39, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = icmp ugt i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  br label %50

46:                                               ; preds = %37
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %6, align 4, !tbaa !15
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !15
  br label %31, !llvm.loop !16

50:                                               ; preds = %45, %31
  br label %51

51:                                               ; preds = %50, %29
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !15
  %54 = call i32 @md6_process(ptr noundef %52, i32 noundef %53, i32 noundef 1)
  store i32 %54, ptr %7, align 4, !tbaa !15
  %55 = load i32, ptr %7, align 4, !tbaa !15
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %51
  %58 = load i32, ptr %7, align 4, !tbaa !15
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %82

59:                                               ; preds = %51
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.md6_state, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds [128 x i8], ptr %61, i64 0, i64 0
  call void @md6_reverse_little_endian(ptr noundef %62, i32 noundef 16)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  call void @trim_hashval(ptr noundef %63)
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %77

66:                                               ; preds = %59
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.md6_state, ptr %68, i32 0, i32 2
  %70 = getelementptr inbounds [128 x i8], ptr %69, i64 0, i64 0
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.md6_state, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !18
  %74 = add nsw i32 %73, 7
  %75 = sdiv i32 %74, 8
  %76 = sext i32 %75 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %67, ptr align 8 %70, i64 %76, i1 false)
  br label %77

77:                                               ; preds = %66, %59
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = call i32 @md6_compute_hex_hashval(ptr noundef %78)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.md6_state, ptr %80, i32 0, i32 7
  store i32 1, ptr %81, align 8, !tbaa !13
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %82

82:                                               ; preds = %77, %57, %23, %17, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %83 = load i32, ptr %3, align 4
  ret i32 %83
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 268}
!10 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 136, !11, i64 268, !12, i64 272, !12, i64 280, !11, i64 288, !7, i64 296, !11, i64 360, !11, i64 364, !11, i64 368, !11, i64 372, !7, i64 376, !7, i64 15224, !7, i64 15344}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 288}
!14 = !{!10, !11, i64 372}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 0}


; 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
declare dso_local void @md6_reverse_little_endian(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @md6_process(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @md6_compute_hex_hashval(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @md6_final(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %32, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 268
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %32, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 288
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %32, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 372
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 15224
  %.not28 = icmp slt i32 %14, 1
  br i1 %.not28, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %17 = add nuw i32 %14, 1
  %wide.trip.count = zext i32 %17 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %18 = getelementptr inbounds [29 x i32], ptr %16, i64 0, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %.not25 = icmp eq i32 %19, 0
  br i1 %.not25, label %20, label %.loopexit.loopexit.split.loop.exit33

20:                                               ; preds = %.lr.ph
  %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 %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit.loopexit.split.loop.exit33:             ; preds = %.lr.ph
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit:                                        ; preds = %20, %.loopexit.loopexit.split.loop.exit33, %.preheader, %12
  %.1 = phi i32 [ 1, %12 ], [ 1, %.preheader ], [ %21, %.loopexit.loopexit.split.loop.exit33 ], [ %17, %20 ]
  %22 = tail call i32 @md6_process(ptr noundef nonnull %0, i32 noundef %.1, i32 noundef 1)
  %.not26 = icmp eq i32 %22, 0
  br i1 %.not26, label %23, label %32

23:                                               ; preds = %.loopexit
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @md6_reverse_little_endian(ptr noundef nonnull %24, i32 noundef 16)
  tail call void @trim_hashval(ptr noundef nonnull %0)
  %.not27 = icmp eq ptr %1, null
  br i1 %.not27, label %30, label %25

25:                                               ; preds = %23
  %26 = load i32, ptr %0, align 8, !tbaa !16
  %27 = add nsw i32 %26, 7
  %28 = sdiv i32 %27, 8
  %29 = sext i32 %28 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr nonnull align 8 %24, i64 %29, i1 false)
  br label %30

30:                                               ; preds = %25, %23
  %31 = tail call i32 @md6_compute_hex_hashval(ptr noundef nonnull %0)
  store i32 1, ptr %9, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %.loopexit, %8, %4, %2, %30
  %.0 = phi i32 [ 0, %30 ], [ 3, %2 ], [ 5, %4 ], [ 0, %8 ], [ %22, %.loopexit ]
  ret i32 %.0
}

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 nounwind willreturn memory(argmem: readwrite) }

!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, !7, i64 268}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 136, !7, i64 268, !10, i64 272, !10, i64 280, !7, i64 288, !8, i64 296, !7, i64 360, !7, i64 364, !7, i64 368, !7, i64 372, !8, i64 376, !8, i64 15224, !8, i64 15344}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 288}
!12 = !{!6, !7, i64 372}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass