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

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

declare void @KeccakP1600_Initialize(ptr noundef) #1

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

declare void @KeccakP1600_AddByte(ptr noundef, i8 noundef zeroext, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @KeccakWidth1600_12rounds_Sponge(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, i8 noundef zeroext %4, ptr noundef %5, i64 noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca [200 x i8], align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !11
  store i8 %4, ptr %13, align 1, !tbaa !13
  store ptr %5, ptr %14, align 8, !tbaa !9
  store i64 %6, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 200, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %22 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %22, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %23 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %23, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = udiv i32 %24, 8
  store i32 %25, ptr %20, align 4, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = add i32 %26, %27
  %29 = icmp ne i32 %28, 1600
  br i1 %29, label %30, label %31

30:                                               ; preds = %7
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %115

31:                                               ; preds = %7
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = icmp ule i32 %32, 0
  br i1 %33, label %41, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = icmp ugt i32 %35, 1600
  br i1 %36, label %41, label %37

37:                                               ; preds = %34
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = urem i32 %38, 8
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %37, %34, %31
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %115

42:                                               ; preds = %37
  %43 = load i8, ptr %13, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %115

47:                                               ; preds = %42
  %48 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  call void @KeccakP1600_Initialize(ptr noundef %48)
  br label %49

49:                                               ; preds = %54, %47
  %50 = load i64, ptr %12, align 8, !tbaa !11
  %51 = load i32, ptr %20, align 4, !tbaa !5
  %52 = zext i32 %51 to i64
  %53 = icmp uge i64 %50, %52
  br i1 %53, label %54, label %67

54:                                               ; preds = %49
  %55 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %56 = load ptr, ptr %18, align 8, !tbaa !9
  %57 = load i32, ptr %20, align 4, !tbaa !5
  call void @KeccakP1600_AddBytes(ptr noundef %55, ptr noundef %56, i32 noundef 0, i32 noundef %57)
  %58 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %58)
  %59 = load i32, ptr %20, align 4, !tbaa !5
  %60 = load ptr, ptr %18, align 8, !tbaa !9
  %61 = zext i32 %59 to i64
  %62 = getelementptr inbounds i8, ptr %60, i64 %61
  store ptr %62, ptr %18, align 8, !tbaa !9
  %63 = load i32, ptr %20, align 4, !tbaa !5
  %64 = zext i32 %63 to i64
  %65 = load i64, ptr %12, align 8, !tbaa !11
  %66 = sub i64 %65, %64
  store i64 %66, ptr %12, align 8, !tbaa !11
  br label %49, !llvm.loop !14

67:                                               ; preds = %49
  %68 = load i64, ptr %12, align 8, !tbaa !11
  %69 = trunc i64 %68 to i32
  store i32 %69, ptr %17, align 4, !tbaa !5
  %70 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %71 = load ptr, ptr %18, align 8, !tbaa !9
  %72 = load i32, ptr %17, align 4, !tbaa !5
  call void @KeccakP1600_AddBytes(ptr noundef %70, ptr noundef %71, i32 noundef 0, i32 noundef %72)
  %73 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %74 = load i8, ptr %13, align 1, !tbaa !13
  %75 = load i32, ptr %17, align 4, !tbaa !5
  call void @KeccakP1600_AddByte(ptr noundef %73, i8 noundef zeroext %74, i32 noundef %75)
  %76 = load i8, ptr %13, align 1, !tbaa !13
  %77 = zext i8 %76 to i32
  %78 = icmp sge i32 %77, 128
  br i1 %78, label %79, label %86

79:                                               ; preds = %67
  %80 = load i32, ptr %17, align 4, !tbaa !5
  %81 = load i32, ptr %20, align 4, !tbaa !5
  %82 = sub i32 %81, 1
  %83 = icmp eq i32 %80, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %79
  %85 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %85)
  br label %86

86:                                               ; preds = %84, %79, %67
  %87 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %88 = load i32, ptr %20, align 4, !tbaa !5
  %89 = sub i32 %88, 1
  call void @KeccakP1600_AddByte(ptr noundef %87, i8 noundef zeroext -128, i32 noundef %89)
  %90 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %90)
  br label %91

91:                                               ; preds = %96, %86
  %92 = load i64, ptr %15, align 8, !tbaa !11
  %93 = load i32, ptr %20, align 4, !tbaa !5
  %94 = zext i32 %93 to i64
  %95 = icmp ugt i64 %92, %94
  br i1 %95, label %96, label %109

96:                                               ; preds = %91
  %97 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %98 = load ptr, ptr %19, align 8, !tbaa !9
  %99 = load i32, ptr %20, align 4, !tbaa !5
  call void @KeccakP1600_ExtractBytes(ptr noundef %97, ptr noundef %98, i32 noundef 0, i32 noundef %99)
  %100 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %100)
  %101 = load i32, ptr %20, align 4, !tbaa !5
  %102 = load ptr, ptr %19, align 8, !tbaa !9
  %103 = zext i32 %101 to i64
  %104 = getelementptr inbounds i8, ptr %102, i64 %103
  store ptr %104, ptr %19, align 8, !tbaa !9
  %105 = load i32, ptr %20, align 4, !tbaa !5
  %106 = zext i32 %105 to i64
  %107 = load i64, ptr %15, align 8, !tbaa !11
  %108 = sub i64 %107, %106
  store i64 %108, ptr %15, align 8, !tbaa !11
  br label %91, !llvm.loop !16

109:                                              ; preds = %91
  %110 = load i64, ptr %15, align 8, !tbaa !11
  %111 = trunc i64 %110 to i32
  store i32 %111, ptr %17, align 4, !tbaa !5
  %112 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  %113 = load ptr, ptr %19, align 8, !tbaa !9
  %114 = load i32, ptr %17, align 4, !tbaa !5
  call void @KeccakP1600_ExtractBytes(ptr noundef %112, ptr noundef %113, i32 noundef 0, i32 noundef %114)
  store i32 0, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %115

115:                                              ; preds = %109, %46, %41, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 200, ptr %16) #3
  %116 = load i32, ptr %8, align 4
  ret i32 %116
}

declare void @KeccakP1600_Permute_12rounds(ptr noundef) #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 @KeccakP1600_Initialize(ptr noundef) local_unnamed_addr #1

declare void @KeccakP1600_AddBytes(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @KeccakP1600_AddByte(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #1

declare void @KeccakP1600_ExtractBytes(ptr noundef, ptr noundef, i32 noundef, i32 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 range(i32 0, 2) i32 @KeccakWidth1600_12rounds_Sponge(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, i8 noundef zeroext %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #2 {
  %8 = alloca [200 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %8) #3
  %9 = lshr i32 %0, 3
  %10 = add i32 %1, %0
  %.not = icmp eq i32 %10, 1600
  br i1 %.not, label %11, label %30

11:                                               ; preds = %7
  %12 = add i32 %0, -1601
  %or.cond = icmp ult i32 %12, -1600
  %13 = and i32 %0, 7
  %.not45 = icmp ne i32 %13, 0
  %or.cond47.not51 = or i1 %or.cond, %.not45
  %14 = icmp eq i8 %4, 0
  %or.cond50 = or i1 %or.cond47.not51, %14
  br i1 %or.cond50, label %30, label %15

15:                                               ; preds = %11
  call void @KeccakP1600_Initialize(ptr noundef nonnull %8) #3
  %16 = zext nneg i32 %9 to i64
  %.not4652 = icmp ugt i64 %16, %3
  br i1 %.not4652, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.03954 = phi ptr [ %17, %.lr.ph ], [ %2, %15 ]
  %.04153 = phi i64 [ %18, %.lr.ph ], [ %3, %15 ]
  call void @KeccakP1600_AddBytes(ptr noundef nonnull %8, ptr noundef %.03954, i32 noundef 0, i32 noundef %9) #3
  call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %8) #3
  %17 = getelementptr inbounds i8, ptr %.03954, i64 %16
  %18 = sub i64 %.04153, %16
  %.not46 = icmp ult i64 %18, %16
  br i1 %.not46, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %15
  %.041.lcssa = phi i64 [ %3, %15 ], [ %18, %.lr.ph ]
  %.039.lcssa = phi ptr [ %2, %15 ], [ %17, %.lr.ph ]
  %19 = trunc nuw nsw i64 %.041.lcssa to i32
  call void @KeccakP1600_AddBytes(ptr noundef nonnull %8, ptr noundef %.039.lcssa, i32 noundef 0, i32 noundef %19) #3
  call void @KeccakP1600_AddByte(ptr noundef nonnull %8, i8 noundef zeroext %4, i32 noundef %19) #3
  %20 = icmp slt i8 %4, 0
  %21 = add nsw i32 %9, -1
  %22 = icmp eq i32 %21, %19
  %or.cond49 = select i1 %20, i1 %22, i1 false
  br i1 %or.cond49, label %23, label %24

23:                                               ; preds = %._crit_edge
  call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %8) #3
  br label %24

24:                                               ; preds = %23, %._crit_edge
  call void @KeccakP1600_AddByte(ptr noundef nonnull %8, i8 noundef zeroext -128, i32 noundef %21) #3
  call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %8) #3
  %25 = icmp ult i64 %16, %6
  br i1 %25, label %.lr.ph60, label %._crit_edge61

.lr.ph60:                                         ; preds = %24, %.lr.ph60
  %.03858 = phi ptr [ %26, %.lr.ph60 ], [ %5, %24 ]
  %.04057 = phi i64 [ %27, %.lr.ph60 ], [ %6, %24 ]
  call void @KeccakP1600_ExtractBytes(ptr noundef nonnull %8, ptr noundef %.03858, i32 noundef 0, i32 noundef %9) #3
  call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %8) #3
  %26 = getelementptr inbounds i8, ptr %.03858, i64 %16
  %27 = sub i64 %.04057, %16
  %28 = icmp ugt i64 %27, %16
  br i1 %28, label %.lr.ph60, label %._crit_edge61, !llvm.loop !7

._crit_edge61:                                    ; preds = %.lr.ph60, %24
  %.040.lcssa = phi i64 [ %6, %24 ], [ %27, %.lr.ph60 ]
  %.038.lcssa = phi ptr [ %5, %24 ], [ %26, %.lr.ph60 ]
  %29 = trunc nuw nsw i64 %.040.lcssa to i32
  call void @KeccakP1600_ExtractBytes(ptr noundef nonnull %8, ptr noundef %.038.lcssa, i32 noundef 0, i32 noundef %29) #3
  br label %30

30:                                               ; preds = %11, %7, %._crit_edge61
  %.0 = phi i32 [ 0, %._crit_edge61 ], [ 1, %7 ], [ 1, %11 ]
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %8) #3
  ret i32 %.0
}

declare void @KeccakP1600_Permute_12rounds(ptr noundef) local_unnamed_addr #1

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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