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

; 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: inlinehint nounwind uwtable
declare hidden void @sha512_update(ptr noundef, ptr noundef) #3

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

36:                                               ; preds = %5
  store i32 1, ptr %11, align 4, !tbaa !9
  br label %38

37:                                               ; preds = %5
  store i32 2, ptr %11, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %37, %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = mul i32 %39, 128
  store i32 %40, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 256, ptr %13) #5
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %41 = load i128, ptr %7, align 16, !tbaa !5
  store i128 %41, ptr %16, align 16, !tbaa !5
  %42 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 0
  %43 = load i64, ptr %42, align 16
  %44 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 1
  %45 = load i64, ptr %44, align 8
  %46 = call { i64, i64 } @FStar_UInt128_shift_left(i64 noundef %43, i64 noundef %45, i32 noundef 3)
  %47 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %48 = extractvalue { i64, i64 } %46, 0
  store i64 %48, ptr %47, align 16
  %49 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %50 = extractvalue { i64, i64 } %46, 1
  store i64 %50, ptr %49, align 8
  %51 = load i128, ptr %17, align 16, !tbaa !5
  store i128 %51, ptr %15, align 16, !tbaa !5
  %52 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %53 = load i128, ptr %15, align 16, !tbaa !5
  store i128 %53, ptr %18, align 16, !tbaa !5
  %54 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 0
  %55 = load i64, ptr %54, align 16
  %56 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 1
  %57 = load i64, ptr %56, align 8
  call void @store128_be(ptr noundef %52, i64 noundef %55, i64 noundef %57)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %58 = load ptr, ptr %9, align 8, !tbaa !11
  store ptr %58, ptr %19, align 8, !tbaa !11
  %59 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 0
  %60 = load ptr, ptr %19, align 8, !tbaa !11
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = mul i64 %62, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %59, ptr align 1 %60, i64 %63, i1 false)
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %65
  store i8 -128, ptr %66, align 1, !tbaa !13
  %67 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 0
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  %71 = getelementptr inbounds i8, ptr %70, i64 -16
  %72 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %71, ptr align 16 %72, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %73 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 0
  store ptr %73, ptr %20, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %74 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 0
  %75 = getelementptr inbounds i8, ptr %74, i64 128
  store ptr %75, ptr %21, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %76 = load ptr, ptr %20, align 8, !tbaa !11
  store ptr %76, ptr %22, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %77 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %77, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #5
  %78 = load ptr, ptr %22, align 8, !tbaa !11
  store ptr %78, ptr %24, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #5
  %79 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr %79, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #5
  %80 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %80, ptr %26, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #5
  %81 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %81, ptr %27, align 8, !tbaa !11
  %82 = load ptr, ptr %26, align 8, !tbaa !11
  %83 = load ptr, ptr %10, align 8, !tbaa !11
  call void @sha512_update(ptr noundef %82, ptr noundef %83)
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = icmp ugt i32 %84, 1
  br i1 %85, label %86, label %89

86:                                               ; preds = %38
  %87 = load ptr, ptr %27, align 8, !tbaa !11
  %88 = load ptr, ptr %10, align 8, !tbaa !11
  call void @sha512_update(ptr noundef %87, ptr noundef %88)
  store i32 1, ptr %28, align 4
  br label %90

89:                                               ; preds = %38
  store i32 0, ptr %28, align 4
  br label %90

90:                                               ; preds = %89, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 256, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %91 = load i32, ptr %28, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

92:                                               ; preds = %90, %90
  ret void

93:                                               ; preds = %90
  unreachable
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store128_be(ptr noundef, i64 noundef, i64 noundef) #3

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 = { 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 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 = !{!"__int128", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sha512_update(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_Hash_SHA2_sha512_update_last(i64 noundef %0, i64 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #4 {
  %6 = alloca [256 x i8], align 16
  %7 = alloca [16 x i8], align 16
  %8 = add i32 %2, -112
  %9 = icmp ult i32 %8, -129
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %6, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  %10 = tail call { i64, i64 } @FStar_UInt128_shift_left(i64 noundef %0, i64 noundef %1, i32 noundef 3)
  %11 = extractvalue { i64, i64 } %10, 0
  %12 = extractvalue { i64, i64 } %10, 1
  call void @store128_be(ptr noundef nonnull %7, i64 noundef %11, i64 noundef %12)
  %13 = zext i32 %2 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr align 1 %3, i64 %13, i1 false)
  %14 = getelementptr inbounds [256 x i8], ptr %6, i64 0, i64 %13
  store i8 -128, ptr %14, align 1, !tbaa !5
  %..sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel.v = select i1 %9, i64 240, i64 112
  %..sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel = getelementptr inbounds i8, ptr %6, i64 %..sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel.v
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %..sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel, ptr noundef nonnull align 16 dereferenceable(16) %7, i64 16, i1 false)
  call void @sha512_update(ptr noundef nonnull %6, ptr noundef %4)
  br i1 %9, label %15, label %16

15:                                               ; preds = %5
  %.sroa.gep25 = getelementptr inbounds i8, ptr %6, i64 128
  call void @sha512_update(ptr noundef nonnull %.sroa.gep25, ptr noundef %4)
  br label %16

16:                                               ; preds = %5, %15
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %6) #5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store128_be(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass