; 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_AddByte(ptr noundef, i8 noundef zeroext, 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
define dso_local i32 @KeccakWidth1600_12rounds_SpongeAbsorbLastFewBits(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = udiv i32 %10, 8
  store i32 %11, ptr %6, align 4, !tbaa !13
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %57

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %57

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [200 x i8], ptr %24, i64 0, i64 0
  %26 = load i8, ptr %5, align 1, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !15
  call void @KeccakP1600_AddByte(ptr noundef %25, i8 noundef zeroext %26, i32 noundef %29)
  %30 = load i8, ptr %5, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = icmp sge i32 %31, 128
  br i1 %32, label %33, label %44

33:                                               ; preds = %22
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = load i32, ptr %6, align 4, !tbaa !13
  %38 = sub i32 %37, 1
  %39 = icmp eq i32 %36, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %33
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [200 x i8], ptr %42, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %43)
  br label %44

44:                                               ; preds = %40, %33, %22
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [200 x i8], ptr %46, i64 0, i64 0
  %48 = load i32, ptr %6, align 4, !tbaa !13
  %49 = sub i32 %48, 1
  call void @KeccakP1600_AddByte(ptr noundef %47, i8 noundef zeroext -128, i32 noundef %49)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [200 x i8], ptr %51, i64 0, i64 0
  call void @KeccakP1600_Permute_12rounds(ptr noundef %52)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %53, i32 0, i32 2
  store i32 0, ptr %54, align 4, !tbaa !15
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.KeccakWidth1600_12rounds_SpongeInstanceStruct, ptr %55, i32 0, i32 3
  store i32 1, ptr %56, align 8, !tbaa !14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %57

57:                                               ; preds = %44, %21, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %58 = load i32, ptr %3, align 4
  ret i32 %58
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 200}
!11 = !{!"KeccakWidth1600_12rounds_SpongeInstanceStruct", !7, i64 0, !12, i64 200, !12, i64 204, !12, i64 208}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !12, i64 208}
!15 = !{!11, !12, i64 204}


; 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_AddByte(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

declare void @KeccakP1600_Permute_12rounds(ptr noundef) local_unnamed_addr #0

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

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 208
  %9 = load i32, ptr %8, align 8, !tbaa !10
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %20

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 204
  %12 = load i32, ptr %11, align 4, !tbaa !11
  tail call void @KeccakP1600_AddByte(ptr noundef nonnull %0, i8 noundef zeroext %1, i32 noundef %12) #2
  %13 = icmp slt i8 %1, 0
  br i1 %13, label %14, label %._crit_edge

._crit_edge:                                      ; preds = %10
  %.pre = add nsw i32 %5, -1
  br label %19

14:                                               ; preds = %10
  %15 = load i32, ptr %11, align 4, !tbaa !11
  %16 = add nsw i32 %5, -1
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  tail call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %0) #2
  br label %19

19:                                               ; preds = %._crit_edge, %18, %14
  %.pre-phi = phi i32 [ %.pre, %._crit_edge ], [ %16, %18 ], [ %16, %14 ]
  tail call void @KeccakP1600_AddByte(ptr noundef nonnull %0, i8 noundef zeroext -128, i32 noundef %.pre-phi) #2
  tail call void @KeccakP1600_Permute_12rounds(ptr noundef nonnull %0) #2
  store i32 0, ptr %11, align 4, !tbaa !11
  store i32 1, ptr %8, align 8, !tbaa !10
  br label %20

20:                                               ; preds = %7, %2, %19
  %.0 = phi i32 [ 0, %19 ], [ 1, %2 ], [ 1, %7 ]
  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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass