; LLVM IR from albertobsd/keyhunt :: gmp256k1/GMP256K1.ll (ZN9Secp256K115GetPublicKeyHexEbR5PointPc)

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

%class.Point = type { %class.Int, %class.Int, %class.Int }
%class.Int = type { [1 x %struct.__mpz_struct] }
%struct.__mpz_struct = type { i32, i32, ptr }

; 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

declare void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #1

declare noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16)) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9Secp256K115GetPublicKeyHexEbR5PointPc(ptr noundef nonnull align 8 dereferenceable(393296) %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(48) %2, ptr noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [65 x i8], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 65, ptr %9) #3
  %12 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %13 = trunc i8 %12 to i1
  br i1 %13, label %26, label %14

14:                                               ; preds = %4
  %15 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  store i8 4, ptr %15, align 16, !tbaa !13
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.Point, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  %19 = getelementptr inbounds i8, ptr %18, i64 1
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef %19)
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.Point, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  %23 = getelementptr inbounds i8, ptr %22, i64 33
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %21, ptr noundef %23)
  %24 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_Z9tohex_dstPciS_(ptr noundef %24, i32 noundef 65, ptr noundef %25)
  br label %40

26:                                               ; preds = %4
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.Point, ptr %27, i32 0, i32 1
  %29 = call noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16) %28)
  %30 = zext i1 %29 to i64
  %31 = select i1 %29, i32 2, i32 3
  %32 = trunc i32 %31 to i8
  %33 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  store i8 %32, ptr %33, align 16, !tbaa !13
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.Point, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  %37 = getelementptr inbounds i8, ptr %36, i64 1
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %35, ptr noundef %37)
  %38 = getelementptr inbounds [65 x i8], ptr %9, i64 0, i64 0
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_Z9tohex_dstPciS_(ptr noundef %38, i32 noundef 33, ptr noundef %39)
  br label %40

40:                                               ; preds = %26, %14
  call void @llvm.lifetime.end.p0(i64 65, ptr %9) #3
  ret void
}

declare void @_Z9tohex_dstPciS_(ptr noundef, i32 noundef, ptr 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 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !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"

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9Secp256K115GetPublicKeyHexEbR5PointPc(ptr nocapture noundef nonnull readnone align 8 dereferenceable(393296) %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(48) %2, ptr noundef %3) local_unnamed_addr #2 align 2 {
  %5 = alloca [65 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 65, ptr nonnull %5) #3
  br i1 %1, label %9, label %6

6:                                                ; preds = %4
  %.sink9.sroa.gep10 = getelementptr inbounds i8, ptr %5, i64 33
  store i8 4, ptr %5, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 1
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull %7)
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  br label %13

9:                                                ; preds = %4
  %.sink9.sroa.gep = getelementptr inbounds i8, ptr %5, i64 1
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = tail call noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  %12 = select i1 %11, i8 2, i8 3
  store i8 %12, ptr %5, align 16, !tbaa !5
  br label %13

13:                                               ; preds = %9, %6
  %.sink9.sroa.phi = phi ptr [ %.sink9.sroa.gep, %9 ], [ %.sink9.sroa.gep10, %6 ]
  %.sink7 = phi ptr [ %2, %9 ], [ %8, %6 ]
  %.sink = phi i32 [ 33, %9 ], [ 65, %6 ]
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %.sink7, ptr noundef nonnull %.sink9.sroa.phi)
  call void @_Z9tohex_dstPciS_(ptr noundef nonnull %5, i32 noundef %.sink, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 65, ptr nonnull %5) #3
  ret void
}

declare void @_Z9tohex_dstPciS_(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress 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 = { 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++ TBAA"}


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