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

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

@__const.Hacl_K256_ECDSA_ecdh.oneq = external hidden unnamed_addr constant [4 x i64], align 16

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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
declare dso_local void @Hacl_Impl_K256_Point_point_store(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_Impl_K256_PointMul_point_mul(ptr noundef, ptr noundef, ptr noundef) #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: inlinehint nounwind uwtable
declare hidden i64 @load_qelem_check(ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @load_point_vartime(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @Hacl_K256_ECDSA_ecdh(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [34 x i64], align 16
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i64, align 8
  %13 = alloca [4 x i64], align 16
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i64, align 8
  %23 = alloca i64, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i64, align 8
  %26 = alloca i64, align 8
  %27 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 272, ptr %7) #5
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 272, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %28 = getelementptr inbounds [34 x i64], ptr %7, i64 0, i64 0
  store ptr %28, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %29 = getelementptr inbounds [34 x i64], ptr %7, i64 0, i64 0
  %30 = getelementptr inbounds i64, ptr %29, i64 15
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %31 = getelementptr inbounds [34 x i64], ptr %7, i64 0, i64 0
  %32 = getelementptr inbounds i64, ptr %31, i64 30
  store ptr %32, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call zeroext i1 @load_point_vartime(ptr noundef %33, ptr noundef %34)
  %36 = zext i1 %35 to i8
  store i8 %36, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call i64 @load_qelem_check(ptr noundef %37, ptr noundef %38)
  store i64 %39, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %13, ptr align 16 @__const.Hacl_K256_ECDSA_ecdh.oneq, i64 32, i1 false)
  br label %40

40:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %41, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %42 = load i32, ptr %14, align 4, !tbaa !13
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [4 x i64], ptr %13, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !11
  store i64 %45, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %46 = load i64, ptr %16, align 8, !tbaa !11
  %47 = load i64, ptr %12, align 8, !tbaa !11
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i32, ptr %14, align 4, !tbaa !13
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %48, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = load i64, ptr %16, align 8, !tbaa !11
  %54 = xor i64 %52, %53
  %55 = and i64 %47, %54
  %56 = xor i64 %46, %55
  store i64 %56, ptr %17, align 8, !tbaa !11
  %57 = load i64, ptr %17, align 8, !tbaa !11
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !13
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i64, ptr %58, i64 %60
  store i64 %57, ptr %61, align 8, !tbaa !11
  %62 = load i32, ptr %14, align 4, !tbaa !13
  %63 = add i32 %62, 1
  store i32 %63, ptr %14, align 4, !tbaa !13
  %64 = load i32, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %65, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %66 = load i32, ptr %14, align 4, !tbaa !13
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds [4 x i64], ptr %13, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !11
  store i64 %69, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %70 = load i64, ptr %19, align 8, !tbaa !11
  %71 = load i64, ptr %12, align 8, !tbaa !11
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i32, ptr %14, align 4, !tbaa !13
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds i64, ptr %72, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !11
  %77 = load i64, ptr %19, align 8, !tbaa !11
  %78 = xor i64 %76, %77
  %79 = and i64 %71, %78
  %80 = xor i64 %70, %79
  store i64 %80, ptr %20, align 8, !tbaa !11
  %81 = load i64, ptr %20, align 8, !tbaa !11
  %82 = load ptr, ptr %18, align 8, !tbaa !5
  %83 = load i32, ptr %14, align 4, !tbaa !13
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds i64, ptr %82, i64 %84
  store i64 %81, ptr %85, align 8, !tbaa !11
  %86 = load i32, ptr %14, align 4, !tbaa !13
  %87 = add i32 %86, 1
  store i32 %87, ptr %14, align 4, !tbaa !13
  %88 = load i32, ptr %14, align 4, !tbaa !13
  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 8, ptr %18) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %89, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %90 = load i32, ptr %14, align 4, !tbaa !13
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds [4 x i64], ptr %13, i64 0, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !11
  store i64 %93, ptr %22, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %94 = load i64, ptr %22, align 8, !tbaa !11
  %95 = load i64, ptr %12, align 8, !tbaa !11
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  %97 = load i32, ptr %14, align 4, !tbaa !13
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds i64, ptr %96, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !11
  %101 = load i64, ptr %22, align 8, !tbaa !11
  %102 = xor i64 %100, %101
  %103 = and i64 %95, %102
  %104 = xor i64 %94, %103
  store i64 %104, ptr %23, align 8, !tbaa !11
  %105 = load i64, ptr %23, align 8, !tbaa !11
  %106 = load ptr, ptr %21, align 8, !tbaa !5
  %107 = load i32, ptr %14, align 4, !tbaa !13
  %108 = zext i32 %107 to i64
  %109 = getelementptr inbounds i64, ptr %106, i64 %108
  store i64 %105, ptr %109, align 8, !tbaa !11
  %110 = load i32, ptr %14, align 4, !tbaa !13
  %111 = add i32 %110, 1
  store i32 %111, ptr %14, align 4, !tbaa !13
  %112 = load i32, ptr %14, align 4, !tbaa !13
  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.start.p0(i64 8, ptr %24) #5
  %113 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %113, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #5
  %114 = load i32, ptr %14, align 4, !tbaa !13
  %115 = zext i32 %114 to i64
  %116 = getelementptr inbounds [4 x i64], ptr %13, i64 0, i64 %115
  %117 = load i64, ptr %116, align 8, !tbaa !11
  store i64 %117, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #5
  %118 = load i64, ptr %25, align 8, !tbaa !11
  %119 = load i64, ptr %12, align 8, !tbaa !11
  %120 = load ptr, ptr %10, align 8, !tbaa !5
  %121 = load i32, ptr %14, align 4, !tbaa !13
  %122 = zext i32 %121 to i64
  %123 = getelementptr inbounds i64, ptr %120, i64 %122
  %124 = load i64, ptr %123, align 8, !tbaa !11
  %125 = load i64, ptr %25, align 8, !tbaa !11
  %126 = xor i64 %124, %125
  %127 = and i64 %119, %126
  %128 = xor i64 %118, %127
  store i64 %128, ptr %26, align 8, !tbaa !11
  %129 = load i64, ptr %26, align 8, !tbaa !11
  %130 = load ptr, ptr %24, align 8, !tbaa !5
  %131 = load i32, ptr %14, align 4, !tbaa !13
  %132 = zext i32 %131 to i64
  %133 = getelementptr inbounds i64, ptr %130, i64 %132
  store i64 %129, ptr %133, align 8, !tbaa !11
  %134 = load i32, ptr %14, align 4, !tbaa !13
  %135 = add i32 %134, 1
  store i32 %135, ptr %14, align 4, !tbaa !13
  %136 = load i32, ptr %14, align 4, !tbaa !13
  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 4, ptr %14) #5
  br label %137

137:                                              ; preds = %40
  br label %138

138:                                              ; preds = %137
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #5
  %139 = load i64, ptr %12, align 8, !tbaa !11
  store i64 %139, ptr %27, align 8, !tbaa !11
  %140 = load i8, ptr %11, align 1, !tbaa !9, !range !15, !noundef !16
  %141 = trunc i8 %140 to i1
  br i1 %141, label %142, label %148

142:                                              ; preds = %138
  %143 = load ptr, ptr %9, align 8, !tbaa !5
  %144 = load ptr, ptr %10, align 8, !tbaa !5
  %145 = load ptr, ptr %8, align 8, !tbaa !5
  call void @Hacl_Impl_K256_PointMul_point_mul(ptr noundef %143, ptr noundef %144, ptr noundef %145)
  %146 = load ptr, ptr %4, align 8, !tbaa !5
  %147 = load ptr, ptr %9, align 8, !tbaa !5
  call void @Hacl_Impl_K256_Point_point_store(ptr noundef %146, ptr noundef %147)
  br label %148

148:                                              ; preds = %142, %138
  %149 = load i64, ptr %27, align 8, !tbaa !11
  %150 = icmp eq i64 %149, -1
  br i1 %150, label %151, label %154

151:                                              ; preds = %148
  %152 = load i8, ptr %11, align 1, !tbaa !9, !range !15, !noundef !16
  %153 = trunc i8 %152 to i1
  br label %154

154:                                              ; preds = %151, %148
  %155 = phi i1 [ false, %148 ], [ %153, %151 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 272, ptr %7) #5
  ret i1 %155
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


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

@__const.Hacl_K256_ECDSA_ecdh.oneq = external hidden unnamed_addr constant [4 x i64], align 16

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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
declare dso_local void @Hacl_Impl_K256_Point_point_store(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @load_point_vartime(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @Hacl_K256_ECDSA_ecdh(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [34 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 272, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(272) %4, i8 0, i64 272, i1 false)
  %5 = getelementptr inbounds i8, ptr %4, i64 240
  %6 = call zeroext i1 @load_point_vartime(ptr noundef nonnull %4, ptr noundef %1)
  %7 = call i64 @load_qelem_check(ptr noundef nonnull %5, ptr noundef %2)
  %8 = load <2 x i64>, ptr @__const.Hacl_K256_ECDSA_ecdh.oneq, align 16, !tbaa !5
  %9 = load <2 x i64>, ptr %5, align 16, !tbaa !5
  %10 = xor <2 x i64> %9, %8
  %11 = insertelement <2 x i64> poison, i64 %7, i64 0
  %12 = shufflevector <2 x i64> %11, <2 x i64> poison, <2 x i32> zeroinitializer
  %13 = and <2 x i64> %10, %12
  %14 = xor <2 x i64> %13, %8
  store <2 x i64> %14, ptr %5, align 16, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %4, i64 256
  %16 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @__const.Hacl_K256_ECDSA_ecdh.oneq, i64 16), align 16, !tbaa !5
  %17 = load <2 x i64>, ptr %15, align 16, !tbaa !5
  %18 = xor <2 x i64> %17, %16
  %19 = and <2 x i64> %18, %12
  %20 = xor <2 x i64> %19, %16
  store <2 x i64> %20, ptr %15, align 16, !tbaa !5
  br i1 %6, label %21, label %23

21:                                               ; preds = %3
  %22 = getelementptr inbounds i8, ptr %4, i64 120
  call void @Hacl_Impl_K256_PointMul_point_mul(ptr noundef nonnull %22, ptr noundef nonnull %5, ptr noundef nonnull %4)
  call void @Hacl_Impl_K256_Point_point_store(ptr noundef %0, ptr noundef nonnull %22)
  br label %23

23:                                               ; preds = %21, %3
  %24 = icmp eq i64 %7, -1
  %25 = select i1 %24, i1 %6, i1 false
  call void @llvm.lifetime.end.p0(i64 272, ptr nonnull %4) #4
  ret i1 %25
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass