; LLVM IR from vergecurrency/verge :: src/secp256k1/contrib (lax_der_privatekey_parsing)

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

%struct.secp256k1_pubkey = type { [64 x i8] }

@ec_privkey_export_der.begin = external hidden constant [8 x i8], align 1
@ec_privkey_export_der.middle = external hidden constant [141 x i8], align 16
@ec_privkey_export_der.begin.1 = external hidden constant [9 x i8], align 1
@ec_privkey_export_der.middle.2 = external hidden constant [173 x i8], 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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
define dso_local i32 @ec_privkey_export_der(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.secp256k1_pubkey, align 1
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = call i32 @secp256k1_ec_pubkey_create(ptr noundef %17, ptr noundef %12, ptr noundef %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %23, label %21

21:                                               ; preds = %5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %22, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %75

23:                                               ; preds = %5
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %50

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %27, ptr %15, align 8, !tbaa !5
  %28 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %28, ptr align 1 @ec_privkey_export_der.begin, i64 8, i1 false)
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %30, ptr %15, align 8, !tbaa !5
  %31 = load ptr, ptr %15, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr align 1 %32, i64 32, i1 false)
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 32
  store ptr %34, ptr %15, align 8, !tbaa !5
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %35, ptr align 16 @ec_privkey_export_der.middle, i64 141, i1 false)
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 141
  store ptr %37, ptr %15, align 8, !tbaa !5
  store i64 33, ptr %13, align 8, !tbaa !11
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = call i32 @secp256k1_ec_pubkey_serialize(ptr noundef %38, ptr noundef %39, ptr noundef %13, ptr noundef %12, i32 noundef 258)
  %41 = load i64, ptr %13, align 8, !tbaa !11
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 %41
  store ptr %43, ptr %15, align 8, !tbaa !5
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = ptrtoint ptr %44 to i64
  %47 = ptrtoint ptr %45 to i64
  %48 = sub i64 %46, %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %48, ptr %49, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %74

50:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %51, ptr %16, align 8, !tbaa !5
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 1 @ec_privkey_export_der.begin.1, i64 9, i1 false)
  %53 = load ptr, ptr %16, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 9
  store ptr %54, ptr %16, align 8, !tbaa !5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %55, ptr align 1 %56, i64 32, i1 false)
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 32
  store ptr %58, ptr %16, align 8, !tbaa !5
  %59 = load ptr, ptr %16, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 16 @ec_privkey_export_der.middle.2, i64 173, i1 false)
  %60 = load ptr, ptr %16, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 173
  store ptr %61, ptr %16, align 8, !tbaa !5
  store i64 65, ptr %13, align 8, !tbaa !11
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %16, align 8, !tbaa !5
  %64 = call i32 @secp256k1_ec_pubkey_serialize(ptr noundef %62, ptr noundef %63, ptr noundef %13, ptr noundef %12, i32 noundef 2)
  %65 = load i64, ptr %13, align 8, !tbaa !11
  %66 = load ptr, ptr %16, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 %65
  store ptr %67, ptr %16, align 8, !tbaa !5
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = ptrtoint ptr %68 to i64
  %71 = ptrtoint ptr %69 to i64
  %72 = sub i64 %70, %71
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %72, ptr %73, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %74

74:                                               ; preds = %50, %26
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %75

75:                                               ; preds = %74, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #4
  %76 = load i32, ptr %6, align 4
  ret i32 %76
}

declare i32 @secp256k1_ec_pubkey_create(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @secp256k1_ec_pubkey_serialize(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


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

%struct.secp256k1_pubkey = type { [64 x i8] }

@ec_privkey_export_der.begin = external hidden local_unnamed_addr constant [8 x i8], align 1
@ec_privkey_export_der.middle = external hidden local_unnamed_addr constant [141 x i8], align 16
@ec_privkey_export_der.begin.1 = external hidden local_unnamed_addr constant [9 x i8], align 1
@ec_privkey_export_der.middle.2 = external hidden local_unnamed_addr constant [173 x i8], 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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
define dso_local range(i32 0, 2) i32 @ec_privkey_export_der(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr nocapture noundef nonnull writeonly %2, ptr noundef nonnull %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.secp256k1_pubkey, align 1
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %8 = call i32 @secp256k1_ec_pubkey_create(ptr noundef nonnull %0, ptr noundef nonnull %6, ptr noundef nonnull %3) #4
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %31, label %9

9:                                                ; preds = %5
  %.not32 = icmp eq i32 %4, 0
  br i1 %.not32, label %21, label %10

10:                                               ; preds = %9
  %11 = load i64, ptr @ec_privkey_export_der.begin, align 1
  store i64 %11, ptr %1, align 1
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %12, ptr noundef nonnull align 1 dereferenceable(32) %3, i64 32, i1 false)
  %13 = getelementptr inbounds i8, ptr %1, i64 40
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(141) %13, ptr noundef nonnull align 16 dereferenceable(141) @ec_privkey_export_der.middle, i64 141, i1 false)
  %14 = getelementptr inbounds i8, ptr %1, i64 181
  store i64 33, ptr %7, align 8, !tbaa !5
  %15 = call i32 @secp256k1_ec_pubkey_serialize(ptr noundef nonnull %0, ptr noundef nonnull %14, ptr noundef nonnull %7, ptr noundef nonnull %6, i32 noundef 258) #4
  %16 = load i64, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = ptrtoint ptr %17 to i64
  %19 = ptrtoint ptr %1 to i64
  %20 = sub i64 %18, %19
  br label %31

21:                                               ; preds = %9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %1, ptr noundef nonnull align 1 dereferenceable(9) @ec_privkey_export_der.begin.1, i64 9, i1 false)
  %22 = getelementptr inbounds i8, ptr %1, i64 9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %22, ptr noundef nonnull align 1 dereferenceable(32) %3, i64 32, i1 false)
  %23 = getelementptr inbounds i8, ptr %1, i64 41
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(173) %23, ptr noundef nonnull align 16 dereferenceable(173) @ec_privkey_export_der.middle.2, i64 173, i1 false)
  %24 = getelementptr inbounds i8, ptr %1, i64 214
  store i64 65, ptr %7, align 8, !tbaa !5
  %25 = call i32 @secp256k1_ec_pubkey_serialize(ptr noundef nonnull %0, ptr noundef nonnull %24, ptr noundef nonnull %7, ptr noundef nonnull %6, i32 noundef 2) #4
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = ptrtoint ptr %27 to i64
  %29 = ptrtoint ptr %1 to i64
  %30 = sub i64 %28, %29
  br label %31

31:                                               ; preds = %10, %21, %5
  %storemerge33 = phi i64 [ 0, %5 ], [ %30, %21 ], [ %20, %10 ]
  %.0 = phi i32 [ 0, %5 ], [ 1, %21 ], [ 1, %10 ]
  store i64 %storemerge33, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %6) #4
  ret i32 %.0
}

declare i32 @secp256k1_ec_pubkey_create(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @secp256k1_ec_pubkey_serialize(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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


; Effective O3 passes: DSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass