; LLVM IR from imkcat/CatCrypto :: Sources/ModuleMaps/SHA3 (KeccakSpongeWidth1600)

; 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.KeccakWidth1600_12rounds_SpongeInstanceStruct = type { [200 x i8], i32, i32, i32 }

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

declare void @KeccakP1600_ExtractBytes(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

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

declare void @KeccakP1600_Permute_12rounds(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @KeccakWidth1600_12rounds_SpongeAbsorbLastFewBits(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @KeccakWidth1600_12rounds_SpongeSqueeze(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = udiv i32 %14, 8
  store i32 %15, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 @KeccakWidth1600_12rounds_SpongeAbsorbLastFewBits(ptr noundef %21, i8 noundef zeroext 1)
  br label %23

23:                                               ; preds = %20, %3
  store i64 0, ptr %7, align 8, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %24, ptr %11, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %125, %23
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %126

29:                                               ; preds = %25
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = load i32, ptr %10, align 4, !tbaa !14
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %73

35:                                               ; preds = %29
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !14
  %39 = zext i32 %38 to i64
  %40 = add i64 %37, %39
  %41 = icmp uge i64 %36, %40
  br i1 %41, label %42, label %73

42:                                               ; preds = %35
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = sub i64 %43, %44
  store i64 %45, ptr %8, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %64, %42
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !14
  %49 = zext i32 %48 to i64
  %50 = icmp uge i64 %47, %49
  br i1 %50, label %51, label %69

51:                                               ; preds = %46
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [200 x i8], ptr %53, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %54)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [200 x i8], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !14
  call void @KeccakP1600_ExtractBytes(ptr noundef %57, ptr noundef %58, i32 noundef 0, i32 noundef %59)
  %60 = load i32, ptr %10, align 4, !tbaa !14
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = zext i32 %60 to i64
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  store ptr %63, ptr %11, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %51
  %65 = load i32, ptr %10, align 4, !tbaa !14
  %66 = zext i32 %65 to i64
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = sub i64 %67, %66
  store i64 %68, ptr %8, align 8, !tbaa !9
  br label %46, !llvm.loop !17

69:                                               ; preds = %46
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = load i64, ptr %8, align 8, !tbaa !9
  %72 = sub i64 %70, %71
  store i64 %72, ptr %7, align 8, !tbaa !9
  br label %125

73:                                               ; preds = %35, %29
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 4, !tbaa !16
  %77 = load i32, ptr %10, align 4, !tbaa !14
  %78 = icmp eq i32 %76, %77
  br i1 %78, label %79, label %85

79:                                               ; preds = %73
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds [200 x i8], ptr %81, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %82)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %83, i32 0, i32 2
  store i32 0, ptr %84, align 4, !tbaa !16
  br label %85

85:                                               ; preds = %79, %73
  %86 = load i64, ptr %6, align 8, !tbaa !9
  %87 = load i64, ptr %7, align 8, !tbaa !9
  %88 = sub i64 %86, %87
  %89 = trunc i64 %88 to i32
  store i32 %89, ptr %9, align 4, !tbaa !14
  %90 = load i32, ptr %9, align 4, !tbaa !14
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %92, align 4, !tbaa !16
  %94 = add i32 %90, %93
  %95 = load i32, ptr %10, align 4, !tbaa !14
  %96 = icmp ugt i32 %94, %95
  br i1 %96, label %97, label %103

97:                                               ; preds = %85
  %98 = load i32, ptr %10, align 4, !tbaa !14
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %99, i32 0, i32 2
  %101 = load i32, ptr %100, align 4, !tbaa !16
  %102 = sub i32 %98, %101
  store i32 %102, ptr %9, align 4, !tbaa !14
  br label %103

103:                                              ; preds = %97, %85
  %104 = load i32, ptr %9, align 4, !tbaa !14
  %105 = zext i32 %104 to i64
  %106 = load i64, ptr %7, align 8, !tbaa !9
  %107 = add i64 %106, %105
  store i64 %107, ptr %7, align 8, !tbaa !9
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %108, i32 0, i32 0
  %110 = getelementptr inbounds [200 x i8], ptr %109, i64 0, i64 0
  %111 = load ptr, ptr %11, align 8, !tbaa !5
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %112, i32 0, i32 2
  %114 = load i32, ptr %113, align 4, !tbaa !16
  %115 = load i32, ptr %9, align 4, !tbaa !14
  call void @KeccakP1600_ExtractBytes(ptr noundef %110, ptr noundef %111, i32 noundef %114, i32 noundef %115)
  %116 = load i32, ptr %9, align 4, !tbaa !14
  %117 = load ptr, ptr %11, align 8, !tbaa !5
  %118 = zext i32 %116 to i64
  %119 = getelementptr inbounds i8, ptr %117, i64 %118
  store ptr %119, ptr %11, align 8, !tbaa !5
  %120 = load i32, ptr %9, align 4, !tbaa !14
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %121, i32 0, i32 2
  %123 = load i32, ptr %122, align 4, !tbaa !16
  %124 = add i32 %123, %120
  store i32 %124, ptr %122, align 4, !tbaa !16
  br label %125

125:                                              ; preds = %103, %69
  br label %25, !llvm.loop !19

126:                                              ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 0
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 200}
!12 = !{!"KeccakWidth1600_12rounds_SpongeInstanceStruct", !7, i64 0, !13, i64 200, !13, i64 204, !13, i64 208}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 208}
!16 = !{!12, !13, i64 204}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

declare void @KeccakP1600_ExtractBytes(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @KeccakP1600_Permute_12rounds(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @KeccakWidth1600_12rounds_SpongeAbsorbLastFewBits(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @KeccakWidth1600_12rounds_SpongeSqueeze(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 200
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = lshr i32 %5, 3
  %7 = getelementptr inbounds i8, ptr %0, i64 208
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %11

9:                                                ; preds = %3
  %10 = tail call i32 @KeccakWidth1600_12rounds_SpongeAbsorbLastFewBits(ptr noundef nonnull %0, i8 noundef zeroext 1)
  br label %11

11:                                               ; preds = %9, %3
  %.not64 = icmp eq i64 %2, 0
  br i1 %.not64, label %._crit_edge63, label %.lr.ph62

.lr.ph62:                                         ; preds = %11
  %12 = getelementptr inbounds i8, ptr %0, i64 204
  %13 = zext nneg i32 %6 to i64
  br label %14

14:                                               ; preds = %.lr.ph62, %37
  %.060 = phi ptr [ %1, %.lr.ph62 ], [ %.2, %37 ]
  %.04559 = phi i64 [ 0, %.lr.ph62 ], [ %.146, %37 ]
  %15 = load i32, ptr %12, align 4, !tbaa !11
  %16 = icmp eq i32 %15, %6
  br i1 %16, label %17, label %25

17:                                               ; preds = %14
  %18 = add i64 %.04559, %13
  %.not53 = icmp ugt i64 %18, %2
  br i1 %.not53, label %24, label %19

19:                                               ; preds = %17
  %20 = sub i64 %2, %.04559
  %.not5455 = icmp ult i64 %20, %13
  br i1 %.not5455, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.157 = phi ptr [ %21, %.lr.ph ], [ %.060, %19 ]
  %.04856 = phi i64 [ %22, %.lr.ph ], [ %20, %19 ]
  tail call void @KeccakP1600_Permute_12rounds(ptr noundef %0) #2
  tail call void @KeccakP1600_ExtractBytes(ptr noundef %0, ptr noundef %.157, i32 noundef 0, i32 noundef %6) #2
  %21 = getelementptr inbounds i8, ptr %.157, i64 %13
  %22 = sub i64 %.04856, %13
  %.not54 = icmp ult i64 %22, %13
  br i1 %.not54, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %19
  %.048.lcssa = phi i64 [ %20, %19 ], [ %22, %.lr.ph ]
  %.1.lcssa = phi ptr [ %.060, %19 ], [ %21, %.lr.ph ]
  %23 = sub i64 %2, %.048.lcssa
  br label %37

24:                                               ; preds = %17
  tail call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %0) #2
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %14, %24
  %26 = phi i32 [ %15, %14 ], [ 0, %24 ]
  %27 = sub i64 %2, %.04559
  %28 = trunc i64 %27 to i32
  %29 = add i32 %26, %28
  %30 = icmp ugt i32 %29, %6
  %31 = sub i32 %6, %26
  %spec.select = select i1 %30, i32 %31, i32 %28
  %32 = zext i32 %spec.select to i64
  %33 = add i64 %.04559, %32
  tail call void @KeccakP1600_ExtractBytes(ptr noundef nonnull %0, ptr noundef %.060, i32 noundef %26, i32 noundef %spec.select) #2
  %34 = getelementptr inbounds i8, ptr %.060, i64 %32
  %35 = load i32, ptr %12, align 4, !tbaa !11
  %36 = add i32 %spec.select, %35
  store i32 %36, ptr %12, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %25, %._crit_edge
  %.146 = phi i64 [ %23, %._crit_edge ], [ %33, %25 ]
  %.2 = phi ptr [ %.1.lcssa, %._crit_edge ], [ %34, %25 ]
  %38 = icmp ult i64 %.146, %2
  br i1 %38, label %14, label %._crit_edge63, !llvm.loop !14

._crit_edge63:                                    ; preds = %37, %11
  ret i32 0
}

attributes #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 = { 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 = { 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, !9, i64 200}
!6 = !{!"KeccakWidth1600_12rounds_SpongeInstanceStruct", !7, i64 0, !9, i64 200, !9, i64 204, !9, i64 208}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 208}
!11 = !{!6, !9, i64 204}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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