; 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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @Hacl_Bignum256_new_bn_from_bytes_le(i32 noundef %0, ptr noundef %1) #8 {
  %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 ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %28, label %22

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

28:                                               ; preds = %22, %2
  store ptr null, ptr %3, align 8
  br label %111

29:                                               ; preds = %22
  br label %30

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

37:                                               ; preds = %30
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1282)
  call void @exit(i32 noundef 253) #9
  unreachable

39:                                               ; preds = %30
  br label %40

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

49:                                               ; preds = %40
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %50, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %110

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

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

64:                                               ; preds = %60
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1292)
  call void @exit(i32 noundef 253) #9
  unreachable

66:                                               ; preds = %60
  br label %67

67:                                               ; preds = %66
  br label %68

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

80:                                               ; preds = %104, %68
  %81 = load i32, ptr %14, align 4, !tbaa !5
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = sub i32 %82, 1
  %84 = udiv i32 %83, 8
  %85 = add i32 %84, 1
  %86 = icmp ult i32 %81, %85
  br i1 %86, label %88, label %87

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

88:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #10
  %89 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %89, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #10
  %90 = load i32, ptr %14, align 4, !tbaa !5
  %91 = mul i32 %90, 8
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %72, i64 %92
  store ptr %93, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #10
  %94 = load ptr, ptr %16, align 8, !tbaa !9
  %95 = call i64 @load64(ptr noundef %94)
  %96 = call i64 @__uint64_identity(i64 noundef %95)
  store i64 %96, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #10
  %97 = load i64, ptr %17, align 8, !tbaa !11
  store i64 %97, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #10
  %98 = load i64, ptr %18, align 8, !tbaa !11
  store i64 %98, ptr %19, align 8, !tbaa !11
  %99 = load i64, ptr %19, align 8, !tbaa !11
  %100 = load ptr, ptr %15, align 8, !tbaa !9
  %101 = load i32, ptr %14, align 4, !tbaa !5
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds i64, ptr %100, i64 %102
  store i64 %99, ptr %103, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #10
  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 %104

104:                                              ; preds = %88
  %105 = load i32, ptr %14, align 4, !tbaa !5
  %106 = add i32 %105, 1
  store i32 %106, ptr %14, align 4, !tbaa !5
  br label %80, !llvm.loop !13

107:                                              ; preds = %87
  %108 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %108, ptr %3, align 8
  store i32 1, ptr %7, align 4
  %109 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %109)
  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 %110

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

111:                                              ; preds = %110, %28
  %112 = load ptr, ptr %3, align 8
  ret ptr %112
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__uint64_identity(i64 noundef) #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 = { "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 = { 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 #6 = { nocallback nofree nosync nounwind willreturn }
attributes #7 = { 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 #8 = { 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: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @Hacl_Bignum256_new_bn_from_bytes_le(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #5 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %28, 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 %28, 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 %28, 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
  %17 = zext i32 %0 to i64
  %.not34 = icmp ugt i32 %13, %0
  %18 = sub nsw i64 %14, %17
  %19 = select i1 %.not34, i64 %18, i64 0
  %20 = getelementptr i8, ptr %16, i64 %17
  call void @llvm.memset.p0.i64(ptr align 1 %20, i8 0, i64 %19, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %16, ptr align 1 %1, i64 %17, i1 false)
  br label %22

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

22:                                               ; preds = %12, %22
  %indvars.iv = phi i64 [ 0, %12 ], [ %indvars.iv.next, %22 ]
  %23 = shl nuw i64 %indvars.iv, 3
  %24 = getelementptr inbounds i8, ptr %16, i64 %23
  %25 = call i64 @load64(ptr noundef nonnull %24)
  %26 = call i64 @__uint64_identity(i64 noundef %25)
  %27 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  store i64 %26, ptr %27, 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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__uint64_identity(i64 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 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,MemCpyOptPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass