; LLVM IR from cryspen/libcrux :: sys/hacl/c/src (Hacl_Hash_SHA3)

; 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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_len(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA3_absorb_inner(i32 noundef, ptr noundef, ptr 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 void @Hacl_Hash_SHA3_update_last_sha3(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca [200 x i8], align 16
  %12 = alloca ptr, align 8
  %13 = alloca [200 x i8], align 16
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca [200 x i8], align 16
  %17 = alloca ptr, align 8
  %18 = alloca [200 x i8], align 16
  %19 = alloca ptr, align 8
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store ptr %2, ptr %7, align 8, !tbaa !8
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %20 = load i8, ptr %5, align 1, !tbaa !5
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 12
  br i1 %22, label %27, label %23

23:                                               ; preds = %4
  %24 = load i8, ptr %5, align 1, !tbaa !5
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 13
  br i1 %26, label %27, label %28

27:                                               ; preds = %23, %4
  store i8 31, ptr %9, align 1, !tbaa !5
  br label %29

28:                                               ; preds = %23
  store i8 6, ptr %9, align 1, !tbaa !5
  br label %29

29:                                               ; preds = %28, %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %30 = load i8, ptr %5, align 1, !tbaa !5
  %31 = call i32 @block_len(i8 noundef zeroext %30)
  store i32 %31, ptr %10, align 4, !tbaa !10
  %32 = load i32, ptr %8, align 4, !tbaa !10
  %33 = load i32, ptr %10, align 4, !tbaa !10
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %72

35:                                               ; preds = %29
  %36 = load i32, ptr %10, align 4, !tbaa !10
  %37 = load ptr, ptr %7, align 8, !tbaa !8
  %38 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_absorb_inner(i32 noundef %36, ptr noundef %37, ptr noundef %38)
  call void @llvm.lifetime.start.p0(i64 200, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %39 = getelementptr inbounds [200 x i8], ptr %11, i64 0, i64 0
  store ptr %39, ptr %12, align 8, !tbaa !8
  %40 = load ptr, ptr %12, align 8, !tbaa !8
  %41 = load ptr, ptr %7, align 8, !tbaa !8
  %42 = load i32, ptr %8, align 4, !tbaa !10
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %40, ptr align 1 %44, i64 0, i1 false)
  %45 = load i8, ptr %9, align 1, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !8
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  store i8 %45, ptr %47, align 1, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !10
  %49 = load ptr, ptr %12, align 8, !tbaa !8
  %50 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %48, ptr noundef %49, ptr noundef %50)
  %51 = load i8, ptr %9, align 1, !tbaa !5
  %52 = zext i8 %51 to i32
  %53 = and i32 %52, 128
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %61, label %55

55:                                               ; preds = %35
  %56 = load i32, ptr %10, align 4, !tbaa !10
  %57 = sub i32 %56, 1
  %58 = icmp eq i32 0, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  %60 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %60)
  br label %61

61:                                               ; preds = %59, %55, %35
  call void @llvm.lifetime.start.p0(i64 200, ptr %13) #4
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %62 = getelementptr inbounds [200 x i8], ptr %13, i64 0, i64 0
  store ptr %62, ptr %14, align 8, !tbaa !8
  %63 = load ptr, ptr %14, align 8, !tbaa !8
  %64 = load i32, ptr %10, align 4, !tbaa !10
  %65 = sub i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds i8, ptr %63, i64 %66
  store i8 -128, ptr %67, align 1, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !10
  %69 = load ptr, ptr %14, align 8, !tbaa !8
  %70 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %68, ptr noundef %69, ptr noundef %70)
  %71 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %71)
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %11) #4
  br label %109

72:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 200, ptr %16) #4
  call void @llvm.memset.p0.i64(ptr align 16 %16, i8 0, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %73 = getelementptr inbounds [200 x i8], ptr %16, i64 0, i64 0
  store ptr %73, ptr %17, align 8, !tbaa !8
  %74 = load ptr, ptr %17, align 8, !tbaa !8
  %75 = load ptr, ptr %7, align 8, !tbaa !8
  %76 = load i32, ptr %8, align 4, !tbaa !10
  %77 = zext i32 %76 to i64
  %78 = mul i64 %77, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %74, ptr align 1 %75, i64 %78, i1 false)
  %79 = load i8, ptr %9, align 1, !tbaa !5
  %80 = load ptr, ptr %17, align 8, !tbaa !8
  %81 = load i32, ptr %8, align 4, !tbaa !10
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  store i8 %79, ptr %83, align 1, !tbaa !5
  %84 = load i32, ptr %10, align 4, !tbaa !10
  %85 = load ptr, ptr %17, align 8, !tbaa !8
  %86 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %84, ptr noundef %85, ptr noundef %86)
  %87 = load i8, ptr %9, align 1, !tbaa !5
  %88 = zext i8 %87 to i32
  %89 = and i32 %88, 128
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %98, label %91

91:                                               ; preds = %72
  %92 = load i32, ptr %8, align 4, !tbaa !10
  %93 = load i32, ptr %10, align 4, !tbaa !10
  %94 = sub i32 %93, 1
  %95 = icmp eq i32 %92, %94
  br i1 %95, label %96, label %98

96:                                               ; preds = %91
  %97 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %97)
  br label %98

98:                                               ; preds = %96, %91, %72
  call void @llvm.lifetime.start.p0(i64 200, ptr %18) #4
  call void @llvm.memset.p0.i64(ptr align 16 %18, i8 0, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %99 = getelementptr inbounds [200 x i8], ptr %18, i64 0, i64 0
  store ptr %99, ptr %19, align 8, !tbaa !8
  %100 = load ptr, ptr %19, align 8, !tbaa !8
  %101 = load i32, ptr %10, align 4, !tbaa !10
  %102 = sub i32 %101, 1
  %103 = zext i32 %102 to i64
  %104 = getelementptr inbounds i8, ptr %100, i64 %103
  store i8 -128, ptr %104, align 1, !tbaa !5
  %105 = load i32, ptr %10, align 4, !tbaa !10
  %106 = load ptr, ptr %19, align 8, !tbaa !8
  %107 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %105, ptr noundef %106, ptr noundef %107)
  %108 = load ptr, ptr %6, align 8, !tbaa !8
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %108)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %16) #4
  store i32 0, ptr %15, align 4
  br label %109

109:                                              ; preds = %98, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  %110 = load i32, ptr %15, align 4
  switch i32 %110, label %112 [
    i32 0, label %111
    i32 1, label %111
  ]

111:                                              ; preds = %109, %109
  ret void

112:                                              ; preds = %109
  unreachable
}

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

; 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) #3

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

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

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: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @block_len(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA3_absorb_inner(i32 noundef, ptr noundef, ptr 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 void @Hacl_Hash_SHA3_update_last_sha3(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [200 x i8], align 16
  %6 = alloca [200 x i8], align 16
  %7 = alloca [200 x i8], align 16
  %8 = alloca [200 x i8], align 16
  %9 = and i8 %0, -2
  %or.cond = icmp eq i8 %9, 12
  %. = select i1 %or.cond, i8 31, i8 6
  %10 = tail call i32 @block_len(i8 noundef zeroext %0)
  %11 = icmp eq i32 %10, %3
  br i1 %11, label %12, label %16

12:                                               ; preds = %4
  tail call void @Hacl_Hash_SHA3_absorb_inner(i32 noundef %3, ptr noundef %2, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %5, i8 0, i64 200, i1 false)
  store i8 %., ptr %5, align 16, !tbaa !5
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %3, ptr noundef nonnull %5, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %6, i8 0, i64 200, i1 false)
  %13 = add i32 %3, -1
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %6, i64 %14
  store i8 -128, ptr %15, align 1, !tbaa !5
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %3, ptr noundef nonnull %6, ptr noundef %1)
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %5) #4
  br label %22

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %7, i8 0, i64 200, i1 false)
  %17 = zext i32 %3 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %7, ptr align 1 %2, i64 %17, i1 false)
  %18 = getelementptr inbounds i8, ptr %7, i64 %17
  store i8 %., ptr %18, align 1, !tbaa !5
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %10, ptr noundef nonnull %7, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %8) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %8, i8 0, i64 200, i1 false)
  %19 = add i32 %10, -1
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %8, i64 %20
  store i8 -128, ptr %21, align 1, !tbaa !5
  call void @Hacl_Hash_SHA3_loadState(i32 noundef %10, ptr noundef nonnull %8, ptr noundef %1)
  call void @Hacl_Hash_SHA3_state_permute(ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %7) #4
  br label %22

22:                                               ; preds = %16, %12
  ret void
}

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

; 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) #3

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

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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