; LLVM IR from IntersectMBO/cardano-crypto :: cbits (encrypted_sign)

; 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.HMAC_sha512_ctx = type { %struct.sha512_ctx, %struct.sha512_ctx }
%struct.sha512_ctx = type { [2 x i64], [128 x i8], [8 x i64] }

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @serialize_index32(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_init(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @index_is_hardened(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_update(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_final(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @wallet_encrypted_derive_public(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca %struct.HMAC_sha512_ctx, align 8
  %15 = alloca [4 x i8], align 1
  %16 = alloca [64 x i8], align 16
  %17 = alloca [64 x i8], align 16
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 416, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %17) #4
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = call i32 @index_is_hardened(i32 noundef %19)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %6
  store i32 1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %42

23:                                               ; preds = %6
  %24 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 0
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %13, align 4, !tbaa !9
  call void @serialize_index32(ptr noundef %24, i32 noundef %25, i32 noundef %26)
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  call void @HMAC_sha512_init(ptr noundef %14, ptr noundef %27, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef @.str.1, i64 noundef 1)
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef %28, i64 noundef 32)
  %29 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 0
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef %29, i64 noundef 4)
  %30 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  call void @HMAC_sha512_final(ptr noundef %14, ptr noundef %30)
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %13, align 4, !tbaa !9
  call void @add_left_public(ptr noundef %31, ptr noundef %32, ptr noundef %33, i32 noundef %34)
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  call void @HMAC_sha512_init(ptr noundef %14, ptr noundef %35, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef @.str.3, i64 noundef 1)
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef %36, i64 noundef 32)
  %37 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 0
  call void @HMAC_sha512_update(ptr noundef %14, ptr noundef %37, i64 noundef 4)
  %38 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  call void @HMAC_sha512_final(ptr noundef %14, ptr noundef %38)
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %41 = getelementptr inbounds i8, ptr %40, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 1 %41, i64 32, i1 false)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %42

42:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 64, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 416, ptr %14) #4
  %43 = load i32, ptr %7, align 4
  ret i32 %43
}

; Function Attrs: nounwind uwtable
declare hidden void @add_left_public(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

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 = { 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 #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}


; 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.HMAC_sha512_ctx = type { %struct.sha512_ctx, %struct.sha512_ctx }
%struct.sha512_ctx = type { [2 x i64], [128 x i8], [8 x i64] }

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; 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

; 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: nounwind uwtable
declare hidden void @serialize_index32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @index_is_hardened(i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @HMAC_sha512_final(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @wallet_encrypted_derive_public(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr nocapture noundef writeonly %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = alloca %struct.HMAC_sha512_ctx, align 8
  %8 = alloca [4 x i8], align 1
  %9 = alloca [64 x i8], align 16
  %10 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 416, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %10) #4
  %11 = tail call i32 @index_is_hardened(i32 noundef %2)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %14

12:                                               ; preds = %6
  call void @serialize_index32(ptr noundef nonnull %8, i32 noundef %2, i32 noundef %5)
  call void @HMAC_sha512_init(ptr noundef nonnull %7, ptr noundef %1, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef nonnull @.str.1, i64 noundef 1)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef %0, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef nonnull %8, i64 noundef 4)
  call void @HMAC_sha512_final(ptr noundef nonnull %7, ptr noundef nonnull %9)
  call void @add_left_public(ptr noundef %3, ptr noundef nonnull %9, ptr noundef %0, i32 noundef %5)
  call void @HMAC_sha512_init(ptr noundef nonnull %7, ptr noundef %1, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef nonnull @.str.3, i64 noundef 1)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef %0, i64 noundef 32)
  call void @HMAC_sha512_update(ptr noundef nonnull %7, ptr noundef nonnull %8, i64 noundef 4)
  call void @HMAC_sha512_final(ptr noundef nonnull %7, ptr noundef nonnull %10)
  %13 = getelementptr inbounds i8, ptr %10, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %4, ptr noundef nonnull align 16 dereferenceable(32) %13, i64 32, i1 false)
  br label %14

14:                                               ; preds = %6, %12
  %.0 = phi i32 [ 0, %12 ], [ 1, %6 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 416, ptr nonnull %7) #4
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @add_left_public(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { 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 #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)"}


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