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

; 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

; 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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 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: nounwind uwtable
define dso_local ptr @Hacl_Bignum256_new_bn_from_bytes_be(i32 noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %2
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sub i32 %21, 1
  %23 = udiv i32 %22, 8
  %24 = add i32 %23, 1
  %25 = icmp ule i32 %24, 536870911
  br i1 %25, label %27, label %26

26:                                               ; preds = %20, %2
  store ptr null, ptr %3, align 8
  br label %114

27:                                               ; preds = %20
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sub i32 %29, 1
  %31 = udiv i32 %30, 8
  %32 = add i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = icmp ugt i64 %33, 2305843009213693951
  br i1 %34, label %35, label %37

35:                                               ; preds = %28
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1241)
  call void @exit(i32 noundef 253) #9
  unreachable

37:                                               ; preds = %28
  br label %38

38:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #10
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sub i32 %39, 1
  %41 = udiv i32 %40, 8
  %42 = add i32 %41, 1
  %43 = zext i32 %42 to i64
  %44 = call noalias ptr @calloc(i64 noundef %43, i64 noundef 8) #11
  store ptr %44, ptr %6, align 8, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %38
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %48, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %113

49:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #10
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %50, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #10
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %51, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #10
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sub i32 %52, 1
  %54 = udiv i32 %53, 8
  %55 = add i32 %54, 1
  store i32 %55, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #10
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = mul i32 8, %56
  store i32 %57, ptr %11, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %49
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = zext i32 %59 to i64
  %61 = icmp ugt i64 %60, -1
  br i1 %61, label %62, label %64

62:                                               ; preds = %58
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1251)
  call void @exit(i32 noundef 253) #9
  unreachable

64:                                               ; preds = %58
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = zext i32 %67 to i64
  %69 = call ptr @llvm.stacksave.p0()
  store ptr %69, ptr %12, align 8
  %70 = alloca i8, i64 %68, align 16
  store i64 %68, ptr %13, align 8
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = zext i32 %71 to i64
  %73 = mul i64 %72, 1
  call void @llvm.memset.p0.i64(ptr align 16 %70, i8 0, i64 %73, i1 false)
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %70, i64 %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = zext i32 %77 to i64
  %79 = sub i64 0, %78
  %80 = getelementptr inbounds i8, ptr %76, i64 %79
  %81 = load ptr, ptr %5, align 8, !tbaa !9
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = zext i32 %82 to i64
  %84 = mul i64 %83, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %80, ptr align 1 %81, i64 %84, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #10
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %107, %66
  %86 = load i32, ptr %14, align 4, !tbaa !5
  %87 = load i32, ptr %10, align 4, !tbaa !5
  %88 = icmp ult i32 %86, %87
  br i1 %88, label %90, label %89

89:                                               ; preds = %85
  store i32 6, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #10
  br label %110

90:                                               ; preds = %85
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #10
  %91 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %91, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #10
  %92 = load i32, ptr %10, align 4, !tbaa !5
  %93 = load i32, ptr %14, align 4, !tbaa !5
  %94 = sub i32 %92, %93
  %95 = sub i32 %94, 1
  %96 = mul i32 %95, 8
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %70, i64 %97
  %99 = call i64 @load64(ptr noundef %98)
  %100 = call i64 @__bswap_64(i64 noundef %99)
  store i64 %100, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #10
  %101 = load i64, ptr %16, align 8, !tbaa !11
  store i64 %101, ptr %17, align 8, !tbaa !11
  %102 = load i64, ptr %17, align 8, !tbaa !11
  %103 = load ptr, ptr %15, align 8, !tbaa !9
  %104 = load i32, ptr %14, align 4, !tbaa !5
  %105 = zext i32 %104 to i64
  %106 = getelementptr inbounds i64, ptr %103, i64 %105
  store i64 %102, ptr %106, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #10
  br label %107

107:                                              ; preds = %90
  %108 = load i32, ptr %14, align 4, !tbaa !5
  %109 = add i32 %108, 1
  store i32 %109, ptr %14, align 4, !tbaa !5
  br label %85, !llvm.loop !13

110:                                              ; preds = %89
  %111 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %111, ptr %3, align 8
  store i32 1, ptr %7, align 4
  %112 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %112)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #10
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #10
  br label %113

113:                                              ; preds = %110, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #10
  br label %114

114:                                              ; preds = %113, %26
  %115 = load ptr, ptr %3, align 8
  ret ptr %115
}

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__bswap_64(i64 noundef) #8

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @load64(ptr noundef) #8

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind allocsize(0,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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 #7 = { nocallback nofree nosync nounwind willreturn }
attributes #8 = { 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 #9 = { noreturn nounwind }
attributes #10 = { nounwind }
attributes #11 = { nounwind allocsize(0,1) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #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: nounwind uwtable
define dso_local noalias noundef ptr @Hacl_Bignum256_new_bn_from_bytes_be(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %31, label %4

4:                                                ; preds = %2
  %5 = add i32 %0, -1
  %6 = lshr i32 %5, 3
  %7 = add nuw nsw i32 %6, 1
  %.not = icmp eq i32 %6, 536870911
  br i1 %.not, label %31, label %8

8:                                                ; preds = %4
  %9 = zext nneg i32 %7 to i64
  %10 = tail call noalias ptr @calloc(i64 noundef %9, i64 noundef 8) #6
  %11 = icmp eq ptr %10, null
  br i1 %11, label %31, label %12

12:                                               ; preds = %8
  %13 = shl nuw i32 %7, 3
  %14 = zext i32 %13 to i64
  %15 = tail call ptr @llvm.stacksave.p0()
  %16 = alloca i8, i64 %14, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %16, i8 0, i64 %14, i1 false)
  %17 = getelementptr inbounds i8, ptr %16, i64 %14
  %18 = zext i32 %0 to i64
  %19 = sub nsw i64 0, %18
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %20, ptr align 1 %1, i64 %18, i1 false)
  br label %22

21:                                               ; preds = %22
  call void @llvm.stackrestore.p0(ptr %15)
  br label %31

22:                                               ; preds = %12, %22
  %indvars.iv = phi i64 [ 0, %12 ], [ %indvars.iv.next, %22 ]
  %23 = trunc i64 %indvars.iv to i32
  %24 = sub i32 %6, %23
  %25 = shl i32 %24, 3
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %16, i64 %26
  %28 = call i64 @load64(ptr noundef nonnull %27)
  %29 = call i64 @__bswap_64(i64 noundef %28)
  %30 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  store i64 %29, ptr %30, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %21, label %22, !llvm.loop !9

31:                                               ; preds = %21, %8, %2, %4
  %.1 = phi ptr [ null, %4 ], [ null, %2 ], [ null, %8 ], [ %10, %21 ]
  ret ptr %.1
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__bswap_64(i64 noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @load64(ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #5 = { 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 #6 = { nounwind allocsize(0,1) }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass