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

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

@.str = external hidden unnamed_addr constant [70 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; 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 nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_HKDF_expand_blake2b_32(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #6 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 64, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = udiv i32 %23, %24
  store i32 %25, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %26, ptr %15, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %6
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = add i32 %28, %29
  %31 = add i32 %30, 1
  %32 = zext i32 %31 to i64
  %33 = icmp ugt i64 %32, -1
  br i1 %33, label %34, label %36

34:                                               ; preds = %27
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 371)
  call void @exit(i32 noundef 253) #8
  unreachable

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = add i32 %39, %40
  %42 = add i32 %41, 1
  %43 = zext i32 %42 to i64
  %44 = call ptr @llvm.stacksave.p0()
  store ptr %44, ptr %16, align 8
  %45 = alloca i8, i64 %43, align 16
  store i64 %43, ptr %17, align 8
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = add i32 %46, %47
  %49 = add i32 %48, 1
  %50 = zext i32 %49 to i64
  %51 = mul i64 %50, 1
  call void @llvm.memset.p0.i64(ptr align 16 %45, i8 0, i64 %51, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #7
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %45, i64 %53
  store ptr %54, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #7
  store ptr %45, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #7
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %45, i64 %56
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  store ptr %60, ptr %20, align 8, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %45, i64 %62
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = mul i64 %66, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %63, ptr align 1 %64, i64 %67, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #7
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %107, %38
  %69 = load i32, ptr %21, align 4, !tbaa !9
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = icmp ult i32 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #7
  br label %110

73:                                               ; preds = %68
  %74 = load i32, ptr %21, align 4, !tbaa !9
  %75 = add i32 %74, 1
  %76 = trunc i32 %75 to i8
  %77 = load ptr, ptr %20, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 0
  store i8 %76, ptr %78, align 1, !tbaa !11
  %79 = load i32, ptr %21, align 4, !tbaa !9
  %80 = icmp eq i32 %79, 0
  br i1 %80, label %81, label %88

81:                                               ; preds = %73
  %82 = load ptr, ptr %19, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = load ptr, ptr %18, align 8, !tbaa !5
  %86 = load i32, ptr %11, align 4, !tbaa !9
  %87 = add i32 %86, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %82, ptr noundef %83, i32 noundef %84, ptr noundef %85, i32 noundef %87)
  br label %96

88:                                               ; preds = %73
  %89 = load ptr, ptr %19, align 8, !tbaa !5
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = load i32, ptr %13, align 4, !tbaa !9
  %93 = load i32, ptr %11, align 4, !tbaa !9
  %94 = add i32 %92, %93
  %95 = add i32 %94, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %89, ptr noundef %90, i32 noundef %91, ptr noundef %45, i32 noundef %95)
  br label %96

96:                                               ; preds = %88, %81
  %97 = load ptr, ptr %15, align 8, !tbaa !5
  %98 = load i32, ptr %21, align 4, !tbaa !9
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = mul i32 %98, %99
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds i8, ptr %97, i64 %101
  %103 = load ptr, ptr %19, align 8, !tbaa !5
  %104 = load i32, ptr %13, align 4, !tbaa !9
  %105 = zext i32 %104 to i64
  %106 = mul i64 %105, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %102, ptr align 1 %103, i64 %106, i1 false)
  br label %107

107:                                              ; preds = %96
  %108 = load i32, ptr %21, align 4, !tbaa !9
  %109 = add i32 %108, 1
  store i32 %109, ptr %21, align 4, !tbaa !9
  br label %68, !llvm.loop !12

110:                                              ; preds = %72
  %111 = load i32, ptr %14, align 4, !tbaa !9
  %112 = load i32, ptr %13, align 4, !tbaa !9
  %113 = mul i32 %111, %112
  %114 = load i32, ptr %12, align 4, !tbaa !9
  %115 = icmp ult i32 %113, %114
  br i1 %115, label %116, label %155

116:                                              ; preds = %110
  %117 = load i32, ptr %14, align 4, !tbaa !9
  %118 = add i32 %117, 1
  %119 = trunc i32 %118 to i8
  %120 = load ptr, ptr %20, align 8, !tbaa !5
  %121 = getelementptr inbounds i8, ptr %120, i64 0
  store i8 %119, ptr %121, align 1, !tbaa !11
  %122 = load i32, ptr %14, align 4, !tbaa !9
  %123 = icmp eq i32 %122, 0
  br i1 %123, label %124, label %131

124:                                              ; preds = %116
  %125 = load ptr, ptr %19, align 8, !tbaa !5
  %126 = load ptr, ptr %8, align 8, !tbaa !5
  %127 = load i32, ptr %9, align 4, !tbaa !9
  %128 = load ptr, ptr %18, align 8, !tbaa !5
  %129 = load i32, ptr %11, align 4, !tbaa !9
  %130 = add i32 %129, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %125, ptr noundef %126, i32 noundef %127, ptr noundef %128, i32 noundef %130)
  br label %139

131:                                              ; preds = %116
  %132 = load ptr, ptr %19, align 8, !tbaa !5
  %133 = load ptr, ptr %8, align 8, !tbaa !5
  %134 = load i32, ptr %9, align 4, !tbaa !9
  %135 = load i32, ptr %13, align 4, !tbaa !9
  %136 = load i32, ptr %11, align 4, !tbaa !9
  %137 = add i32 %135, %136
  %138 = add i32 %137, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %132, ptr noundef %133, i32 noundef %134, ptr noundef %45, i32 noundef %138)
  br label %139

139:                                              ; preds = %131, %124
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  %140 = load ptr, ptr %7, align 8, !tbaa !5
  %141 = load i32, ptr %14, align 4, !tbaa !9
  %142 = load i32, ptr %13, align 4, !tbaa !9
  %143 = mul i32 %141, %142
  %144 = zext i32 %143 to i64
  %145 = getelementptr inbounds i8, ptr %140, i64 %144
  store ptr %145, ptr %22, align 8, !tbaa !5
  %146 = load ptr, ptr %22, align 8, !tbaa !5
  %147 = load ptr, ptr %19, align 8, !tbaa !5
  %148 = load i32, ptr %12, align 4, !tbaa !9
  %149 = load i32, ptr %14, align 4, !tbaa !9
  %150 = load i32, ptr %13, align 4, !tbaa !9
  %151 = mul i32 %149, %150
  %152 = sub i32 %148, %151
  %153 = zext i32 %152 to i64
  %154 = mul i64 %153, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %146, ptr align 1 %147, i64 %154, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  br label %155

155:                                              ; preds = %139, %110
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #7
  %156 = load ptr, ptr %16, align 8
  call void @llvm.stackrestore.p0(ptr %156)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  ret void
}

declare void @Hacl_HMAC_compute_blake2b_32(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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
define dso_local void @Hacl_HKDF_expand_blake2b_32(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = lshr i32 %5, 6
  %8 = add i32 %4, 65
  %9 = zext i32 %8 to i64
  %10 = alloca i8, i64 %9, align 16
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %10, i8 0, i64 %9, i1 false)
  %11 = getelementptr inbounds i8, ptr %10, i64 64
  %12 = zext i32 %4 to i64
  %13 = getelementptr inbounds i8, ptr %11, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %11, ptr align 1 %3, i64 %12, i1 false)
  %.not64 = icmp ult i32 %5, 64
  br i1 %.not64, label %._crit_edge.thread68, label %14

14:                                               ; preds = %6
  %wide.trip.count = zext nneg i32 %7 to i64
  store i8 1, ptr %13, align 1, !tbaa !5
  %15 = add i32 %4, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef nonnull %10, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %11, i32 noundef %15) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %0, ptr noundef nonnull align 16 dereferenceable(64) %10, i64 64, i1 false)
  %exitcond.peel.not = icmp eq i32 %7, 1
  br i1 %exitcond.peel.not, label %._crit_edge.thread, label %.peel.next

._crit_edge:                                      ; preds = %.peel.next
  %16 = and i32 %5, -64
  %.not = icmp eq i32 %16, %5
  br i1 %.not, label %34, label %20

._crit_edge.thread68:                             ; preds = %6
  %.not69 = icmp eq i32 %5, 0
  br i1 %.not69, label %34, label %.thread70

.thread70:                                        ; preds = %._crit_edge.thread68
  store i8 1, ptr %13, align 1, !tbaa !5
  br label %23

._crit_edge.thread:                               ; preds = %14
  %.not67 = icmp eq i32 %5, 64
  br i1 %.not67, label %34, label %.thread

.thread:                                          ; preds = %._crit_edge.thread
  store i8 2, ptr %13, align 1, !tbaa !5
  br label %26

.peel.next:                                       ; preds = %14, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ 1, %14 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = trunc i64 %indvars.iv.next to i8
  store i8 %17, ptr %13, align 1, !tbaa !5
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef nonnull %10, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %10, i32 noundef %8) #4
  %18 = shl nuw i64 %indvars.iv, 6
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %19, ptr noundef nonnull align 16 dereferenceable(64) %10, i64 64, i1 false)
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.peel.next, !llvm.loop !8

20:                                               ; preds = %._crit_edge
  %21 = trunc i32 %7 to i8
  %22 = add i8 %21, 1
  store i8 %22, ptr %13, align 1, !tbaa !5
  br i1 %.not64, label %23, label %26

23:                                               ; preds = %.thread70, %20
  %24 = phi i32 [ 0, %.thread70 ], [ %16, %20 ]
  %25 = add i32 %4, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef nonnull %10, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %11, i32 noundef %25) #4
  br label %28

26:                                               ; preds = %.thread, %20
  %27 = phi i32 [ 64, %.thread ], [ %16, %20 ]
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef nonnull %10, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %10, i32 noundef %8) #4
  br label %28

28:                                               ; preds = %26, %23
  %29 = phi i32 [ %27, %26 ], [ %24, %23 ]
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = and i32 %5, 63
  %33 = zext nneg i32 %32 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr nonnull align 16 %10, i64 %33, i1 false)
  br label %34

34:                                               ; preds = %._crit_edge.thread68, %._crit_edge.thread, %28, %._crit_edge
  ret void
}

declare void @Hacl_HMAC_compute_blake2b_32(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass