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

; 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.Hacl_Streaming_MD_state_64_s = type { ptr, ptr, 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 void @Hacl_Hash_SHA2_sha384_update_nblocks(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA2_sha384_update_last(i64 noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA2_sha384_finish(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_add(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_Hash_SHA2_digest_384(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Hacl_Streaming_MD_state_64_s, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca [8 x i64], align 16
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i128, align 16
  %17 = alloca i128, align 16
  %18 = alloca i128, align 16
  %19 = alloca i128, align 16
  %20 = alloca i128, align 16
  %21 = alloca i128, align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %22, i64 24, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %23 = getelementptr inbounds %struct.Hacl_Streaming_MD_state_64_s, ptr %5, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  store ptr %24, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %25 = getelementptr inbounds %struct.Hacl_Streaming_MD_state_64_s, ptr %5, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %27 = getelementptr inbounds %struct.Hacl_Streaming_MD_state_64_s, ptr %5, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !15
  store i64 %28, ptr %8, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %29 = load i64, ptr %8, align 8, !tbaa !10
  %30 = urem i64 %29, 128
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %36

32:                                               ; preds = %2
  %33 = load i64, ptr %8, align 8, !tbaa !10
  %34 = icmp ugt i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i32 128, ptr %9, align 4, !tbaa !16
  br label %40

36:                                               ; preds = %32, %2
  %37 = load i64, ptr %8, align 8, !tbaa !10
  %38 = urem i64 %37, 128
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %9, align 4, !tbaa !16
  br label %40

40:                                               ; preds = %36, %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %41, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #5
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 64, i1 false)
  %42 = getelementptr inbounds [8 x i64], ptr %11, i64 0, i64 0
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %42, ptr align 8 %43, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %44 = load i32, ptr %9, align 4, !tbaa !16
  %45 = urem i32 %44, 128
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %51

47:                                               ; preds = %40
  %48 = load i32, ptr %9, align 4, !tbaa !16
  %49 = icmp ugt i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store i32 128, ptr %12, align 4, !tbaa !16
  br label %54

51:                                               ; preds = %47, %40
  %52 = load i32, ptr %9, align 4, !tbaa !16
  %53 = urem i32 %52, 128
  store i32 %53, ptr %12, align 4, !tbaa !16
  br label %54

54:                                               ; preds = %51, %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !16
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i32, ptr %12, align 4, !tbaa !16
  %60 = zext i32 %59 to i64
  %61 = sub i64 0, %60
  %62 = getelementptr inbounds i8, ptr %58, i64 %61
  store ptr %62, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %63, ptr %14, align 8, !tbaa !5
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds [8 x i64], ptr %11, i64 0, i64 0
  call void @Hacl_Hash_SHA2_sha384_update_nblocks(i32 noundef 0, ptr noundef %64, ptr noundef %65)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %66 = load i64, ptr %8, align 8, !tbaa !10
  %67 = load i32, ptr %9, align 4, !tbaa !16
  %68 = zext i32 %67 to i64
  %69 = sub i64 %66, %68
  store i64 %69, ptr %15, align 8, !tbaa !10
  %70 = load i64, ptr %15, align 8, !tbaa !10
  %71 = call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef %70)
  %72 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 0
  %73 = extractvalue { i64, i64 } %71, 0
  store i64 %73, ptr %72, align 16
  %74 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 1
  %75 = extractvalue { i64, i64 } %71, 1
  store i64 %75, ptr %74, align 8
  %76 = load i128, ptr %16, align 16, !tbaa !18
  %77 = load i32, ptr %9, align 4, !tbaa !16
  %78 = zext i32 %77 to i64
  %79 = call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef %78)
  %80 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %81 = extractvalue { i64, i64 } %79, 0
  store i64 %81, ptr %80, align 16
  %82 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %83 = extractvalue { i64, i64 } %79, 1
  store i64 %83, ptr %82, align 8
  %84 = load i128, ptr %17, align 16, !tbaa !18
  store i128 %76, ptr %18, align 16, !tbaa !18
  %85 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 0
  %86 = load i64, ptr %85, align 16
  %87 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 1
  %88 = load i64, ptr %87, align 8
  store i128 %84, ptr %19, align 16, !tbaa !18
  %89 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 0
  %90 = load i64, ptr %89, align 16
  %91 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 1
  %92 = load i64, ptr %91, align 8
  %93 = call { i64, i64 } @FStar_UInt128_add(i64 noundef %86, i64 noundef %88, i64 noundef %90, i64 noundef %92)
  %94 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 0
  %95 = extractvalue { i64, i64 } %93, 0
  store i64 %95, ptr %94, align 16
  %96 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 1
  %97 = extractvalue { i64, i64 } %93, 1
  store i64 %97, ptr %96, align 8
  %98 = load i128, ptr %20, align 16, !tbaa !18
  %99 = load i32, ptr %9, align 4, !tbaa !16
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  %101 = getelementptr inbounds [8 x i64], ptr %11, i64 0, i64 0
  store i128 %98, ptr %21, align 16, !tbaa !18
  %102 = getelementptr inbounds { i64, i64 }, ptr %21, i32 0, i32 0
  %103 = load i64, ptr %102, align 16
  %104 = getelementptr inbounds { i64, i64 }, ptr %21, i32 0, i32 1
  %105 = load i64, ptr %104, align 8
  call void @Hacl_Hash_SHA2_sha384_update_last(i64 noundef %103, i64 noundef %105, i32 noundef %99, ptr noundef %100, ptr noundef %101)
  %106 = getelementptr inbounds [8 x i64], ptr %11, i64 0, i64 0
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  call void @Hacl_Hash_SHA2_sha384_finish(ptr noundef %106, ptr noundef %107)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint 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 #5 = { 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 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"Hacl_Streaming_MD_state_64_s", !6, i64 0, !6, i64 8, !11, i64 16}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !11, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"__int128", !7, 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 void @Hacl_Hash_SHA2_sha384_update_nblocks(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA2_sha384_update_last(i64 noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Hash_SHA2_sha384_finish(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_add(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_Hash_SHA2_digest_384(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [8 x i64], align 16
  %.sroa.031.0.copyload = load ptr, ptr %0, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.4.0.copyload = load ptr, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.5.0.copyload = load i64, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  %4 = and i64 %.sroa.5.0.copyload, 127
  %5 = icmp eq i64 %4, 0
  %6 = icmp ne i64 %.sroa.5.0.copyload, 0
  %or.cond = and i1 %6, %5
  %7 = trunc nuw nsw i64 %4 to i32
  %.0 = select i1 %or.cond, i32 128, i32 %7
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %3, ptr noundef nonnull align 8 dereferenceable(64) %.sroa.031.0.copyload, i64 64, i1 false)
  %8 = and i32 %.0, 127
  %9 = icmp eq i32 %8, 0
  %10 = icmp ne i32 %.0, 0
  %or.cond3 = and i1 %10, %9
  %11 = zext nneg i32 %8 to i64
  %.034 = select i1 %or.cond3, i64 128, i64 %11
  %12 = zext nneg i32 %.0 to i64
  %13 = getelementptr inbounds i8, ptr %.sroa.4.0.copyload, i64 %12
  %14 = sub nsw i64 0, %.034
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  call void @Hacl_Hash_SHA2_sha384_update_nblocks(i32 noundef 0, ptr noundef %.sroa.4.0.copyload, ptr noundef nonnull %3)
  %16 = sub i64 %.sroa.5.0.copyload, %12
  %17 = call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef %16)
  %18 = extractvalue { i64, i64 } %17, 0
  %19 = extractvalue { i64, i64 } %17, 1
  %20 = call { i64, i64 } @FStar_UInt128_uint64_to_uint128(i64 noundef %12)
  %21 = extractvalue { i64, i64 } %20, 0
  %22 = extractvalue { i64, i64 } %20, 1
  %23 = call { i64, i64 } @FStar_UInt128_add(i64 noundef %18, i64 noundef %19, i64 noundef %21, i64 noundef %22)
  %24 = extractvalue { i64, i64 } %23, 0
  %25 = extractvalue { i64, i64 } %23, 1
  call void @Hacl_Hash_SHA2_sha384_update_last(i64 noundef %24, i64 noundef %25, i32 noundef %.0, ptr noundef %15, ptr noundef nonnull %3)
  call void @Hacl_Hash_SHA2_sha384_finish(ptr noundef nonnull %3, ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #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 = !{!"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}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass