; LLVM IR from cryspen/libcrux :: sys/hacl/c/src/msvc (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 [81 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; 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_HKDF_expand_blake2b_32(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #5 {
  %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 ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = 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) #6
  store i32 64, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = load i32, ptr %13, align 4, !tbaa !9
  %24 = udiv i32 %22, %23
  store i32 %24, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %25, ptr %15, align 8, !tbaa !5
  br label %26

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

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

35:                                               ; preds = %26
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = add i32 %38, %39
  %41 = add i32 %40, 1
  %42 = zext i32 %41 to i64
  %43 = mul i64 %42, 1
  %44 = alloca i8, i64 %43, align 16
  store ptr %44, ptr %16, align 8, !tbaa !5
  %45 = load ptr, ptr %16, align 8, !tbaa !5
  %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 1 %45, i8 0, i64 %51, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  store ptr %55, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %56 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %56, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  store ptr %63, ptr %19, align 8, !tbaa !5
  %64 = load ptr, ptr %16, align 8, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds i8, ptr %64, i64 %66
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = mul i64 %70, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %67, ptr align 1 %68, i64 %71, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #6
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %112, %37
  %73 = load i32, ptr %20, align 4, !tbaa !9
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = icmp ult i32 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #6
  br label %115

77:                                               ; preds = %72
  %78 = load i32, ptr %20, align 4, !tbaa !9
  %79 = add i32 %78, 1
  %80 = trunc i32 %79 to i8
  %81 = load ptr, ptr %19, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 0
  store i8 %80, ptr %82, align 1, !tbaa !11
  %83 = load i32, ptr %20, align 4, !tbaa !9
  %84 = icmp eq i32 %83, 0
  br i1 %84, label %85, label %92

85:                                               ; preds = %77
  %86 = load ptr, ptr %18, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = load ptr, ptr %17, align 8, !tbaa !5
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = add i32 %90, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %86, ptr noundef %87, i32 noundef %88, ptr noundef %89, i32 noundef %91)
  br label %101

92:                                               ; preds = %77
  %93 = load ptr, ptr %18, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = load ptr, ptr %16, align 8, !tbaa !5
  %97 = load i32, ptr %13, align 4, !tbaa !9
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = add i32 %97, %98
  %100 = add i32 %99, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %93, ptr noundef %94, i32 noundef %95, ptr noundef %96, i32 noundef %100)
  br label %101

101:                                              ; preds = %92, %85
  %102 = load ptr, ptr %15, align 8, !tbaa !5
  %103 = load i32, ptr %20, align 4, !tbaa !9
  %104 = load i32, ptr %13, align 4, !tbaa !9
  %105 = mul i32 %103, %104
  %106 = zext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr %102, i64 %106
  %108 = load ptr, ptr %18, align 8, !tbaa !5
  %109 = load i32, ptr %13, align 4, !tbaa !9
  %110 = zext i32 %109 to i64
  %111 = mul i64 %110, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %107, ptr align 1 %108, i64 %111, i1 false)
  br label %112

112:                                              ; preds = %101
  %113 = load i32, ptr %20, align 4, !tbaa !9
  %114 = add i32 %113, 1
  store i32 %114, ptr %20, align 4, !tbaa !9
  br label %72, !llvm.loop !12

115:                                              ; preds = %76
  %116 = load i32, ptr %14, align 4, !tbaa !9
  %117 = load i32, ptr %13, align 4, !tbaa !9
  %118 = mul i32 %116, %117
  %119 = load i32, ptr %12, align 4, !tbaa !9
  %120 = icmp ult i32 %118, %119
  br i1 %120, label %121, label %161

121:                                              ; preds = %115
  %122 = load i32, ptr %14, align 4, !tbaa !9
  %123 = add i32 %122, 1
  %124 = trunc i32 %123 to i8
  %125 = load ptr, ptr %19, align 8, !tbaa !5
  %126 = getelementptr inbounds i8, ptr %125, i64 0
  store i8 %124, ptr %126, align 1, !tbaa !11
  %127 = load i32, ptr %14, align 4, !tbaa !9
  %128 = icmp eq i32 %127, 0
  br i1 %128, label %129, label %136

129:                                              ; preds = %121
  %130 = load ptr, ptr %18, align 8, !tbaa !5
  %131 = load ptr, ptr %8, align 8, !tbaa !5
  %132 = load i32, ptr %9, align 4, !tbaa !9
  %133 = load ptr, ptr %17, align 8, !tbaa !5
  %134 = load i32, ptr %11, align 4, !tbaa !9
  %135 = add i32 %134, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %130, ptr noundef %131, i32 noundef %132, ptr noundef %133, i32 noundef %135)
  br label %145

136:                                              ; preds = %121
  %137 = load ptr, ptr %18, align 8, !tbaa !5
  %138 = load ptr, ptr %8, align 8, !tbaa !5
  %139 = load i32, ptr %9, align 4, !tbaa !9
  %140 = load ptr, ptr %16, align 8, !tbaa !5
  %141 = load i32, ptr %13, align 4, !tbaa !9
  %142 = load i32, ptr %11, align 4, !tbaa !9
  %143 = add i32 %141, %142
  %144 = add i32 %143, 1
  call void @Hacl_HMAC_compute_blake2b_32(ptr noundef %137, ptr noundef %138, i32 noundef %139, ptr noundef %140, i32 noundef %144)
  br label %145

145:                                              ; preds = %136, %129
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #6
  %146 = load ptr, ptr %7, align 8, !tbaa !5
  %147 = load i32, ptr %14, align 4, !tbaa !9
  %148 = load i32, ptr %13, align 4, !tbaa !9
  %149 = mul i32 %147, %148
  %150 = zext i32 %149 to i64
  %151 = getelementptr inbounds i8, ptr %146, i64 %150
  store ptr %151, ptr %21, align 8, !tbaa !5
  %152 = load ptr, ptr %21, align 8, !tbaa !5
  %153 = load ptr, ptr %18, align 8, !tbaa !5
  %154 = load i32, ptr %12, align 4, !tbaa !9
  %155 = load i32, ptr %14, align 4, !tbaa !9
  %156 = load i32, ptr %13, align 4, !tbaa !9
  %157 = mul i32 %155, %156
  %158 = sub i32 %154, %157
  %159 = zext i32 %158 to i64
  %160 = mul i64 %159, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %152, ptr align 1 %153, i64 %160, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #6
  br label %161

161:                                              ; preds = %145, %115
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  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 nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { 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)
  %.not70 = icmp ult i32 %5, 64
  br i1 %.not70, label %._crit_edge.thread74, 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.thread74:                             ; preds = %6
  %.not75 = icmp eq i32 %5, 0
  br i1 %.not75, label %34, label %.thread76

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

._crit_edge.thread:                               ; preds = %14
  %.not73 = icmp eq i32 %5, 64
  br i1 %.not73, 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 %.not70, label %23, label %26

23:                                               ; preds = %.thread76, %20
  %24 = phi i32 [ 0, %.thread76 ], [ %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.thread74, %._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