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

; 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

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

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

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

39:                                               ; preds = %25, %13
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 65, ptr %7) #3
  ret ptr %40
}

declare noundef ptr @_Z5tohexPci(ptr noundef, i32 noundef) #1

declare noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16)) #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

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

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

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

12:                                               ; preds = %8, %5
  %.sink8.sroa.phi = phi ptr [ %.sink8.sroa.gep, %8 ], [ %.sink8.sroa.gep9, %5 ]
  %.sink6 = phi ptr [ %2, %8 ], [ %7, %5 ]
  %.sink = phi i32 [ 33, %8 ], [ 65, %5 ]
  call void @_ZN3Int10Get32BytesEPh(ptr noundef nonnull align 8 dereferenceable(16) %.sink6, ptr noundef nonnull %.sink8.sroa.phi)
  %13 = call noundef ptr @_Z5tohexPci(ptr noundef nonnull %4, i32 noundef %.sink)
  call void @llvm.lifetime.end.p0(i64 65, ptr nonnull %4) #3
  ret ptr %13
}

declare noundef ptr @_Z5tohexPci(ptr noundef, i32 noundef) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN3Int6IsEvenEv(ptr noundef nonnull align 8 dereferenceable(16)) 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