; LLVM IR from xtruan/FlipBIP :: lib/crypto (bip39)

; 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._PBKDF2_HMAC_SHA512_CTX = type { [8 x i64], [8 x i64], [8 x i64], [16 x i64], i8 }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@mnemonic_to_seed.pctx = external hidden global %struct._PBKDF2_HMAC_SHA512_CTX, align 8

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare void @memzero(ptr noundef, i64 noundef) #2

; 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) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @mnemonic_to_seed(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #5 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca [264 x i8], align 16
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #7
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #7
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %10, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 256
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i32 256, ptr %10, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %21, %4
  call void @llvm.lifetime.start.p0(i64 264, ptr %11) #6
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 264, i1 false)
  %23 = getelementptr inbounds [264 x i8], ptr %11, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %23, ptr align 1 @.str, i64 8, i1 false)
  %24 = getelementptr inbounds [264 x i8], ptr %11, i64 0, i64 0
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %26, i64 %28, i1 false)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = getelementptr inbounds [264 x i8], ptr %11, i64 0, i64 0
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = add nsw i32 %32, 8
  call void @pbkdf2_hmac_sha512_Init(ptr noundef @mnemonic_to_seed.pctx, ptr noundef %29, i32 noundef %30, ptr noundef %31, i32 noundef %33, i32 noundef 1)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %38

36:                                               ; preds = %22
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  call void %37(i32 noundef 0, i32 noundef 2048)
  br label %38

38:                                               ; preds = %36, %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %53, %38
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = icmp slt i32 %40, 16
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %56

43:                                               ; preds = %39
  call void @pbkdf2_hmac_sha512_Update(ptr noundef @mnemonic_to_seed.pctx, i32 noundef 128)
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %52

46:                                               ; preds = %43
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = mul nsw i32 %49, 2048
  %51 = sdiv i32 %50, 16
  call void %47(i32 noundef %51, i32 noundef 2048)
  br label %52

52:                                               ; preds = %46, %43
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %12, align 4, !tbaa !9
  br label %39, !llvm.loop !11

56:                                               ; preds = %42
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  call void @pbkdf2_hmac_sha512_Final(ptr noundef @mnemonic_to_seed.pctx, ptr noundef %57)
  %58 = getelementptr inbounds [264 x i8], ptr %11, i64 0, i64 0
  call void @memzero(ptr noundef %58, i64 noundef 264)
  call void @llvm.lifetime.end.p0(i64 264, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  ret void
}

declare void @pbkdf2_hmac_sha512_Init(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #2

declare void @pbkdf2_hmac_sha512_Update(ptr noundef, i32 noundef) #2

declare void @pbkdf2_hmac_sha512_Final(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { nounwind willreturn memory(read) "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 }
attributes #7 = { nounwind willreturn memory(read) }

!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 = distinct !{!11, !12}
!12 = !{!"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"

%struct._PBKDF2_HMAC_SHA512_CTX = type { [8 x i64], [8 x i64], [8 x i64], [16 x i64], i8 }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@mnemonic_to_seed.pctx = external hidden global %struct._PBKDF2_HMAC_SHA512_CTX, align 8

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare void @memzero(ptr noundef, i64 noundef) local_unnamed_addr #2

; 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) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @mnemonic_to_seed(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef readonly %3) local_unnamed_addr #5 {
  %5 = alloca [264 x i8], align 16
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %7 = trunc i64 %6 to i32
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #7
  %9 = trunc i64 %8 to i32
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %9, i32 256)
  call void @llvm.lifetime.start.p0(i64 264, ptr nonnull %5) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(264) %5, i8 0, i64 264, i1 false)
  %10 = load i64, ptr @.str, align 1
  store i64 %10, ptr %5, align 16
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = sext i32 %spec.store.select to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %11, ptr align 1 %1, i64 %12, i1 false)
  %13 = add nsw i32 %spec.store.select, 8
  call void @pbkdf2_hmac_sha512_Init(ptr noundef nonnull @mnemonic_to_seed.pctx, ptr noundef %0, i32 noundef %7, ptr noundef nonnull %5, i32 noundef %13, i32 noundef 1) #8
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.split.us.preheader, label %.split

.split.us.preheader:                              ; preds = %4
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  br label %.split18.us

.split:                                           ; preds = %4
  call void %3(i32 noundef 0, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 128, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 256, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 384, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 512, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 640, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 768, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 896, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1024, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1152, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1280, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1408, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1536, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1664, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1792, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 1920, i32 noundef 2048) #8
  call void @pbkdf2_hmac_sha512_Update(ptr noundef nonnull @mnemonic_to_seed.pctx, i32 noundef 128) #8
  call void %3(i32 noundef 2048, i32 noundef 2048) #8
  br label %.split18.us

.split18.us:                                      ; preds = %.split, %.split.us.preheader
  call void @pbkdf2_hmac_sha512_Final(ptr noundef nonnull @mnemonic_to_seed.pctx, ptr noundef %2) #8
  call void @memzero(ptr noundef nonnull %5, i64 noundef 264) #8
  call void @llvm.lifetime.end.p0(i64 264, ptr nonnull %5) #8
  ret void
}

declare void @pbkdf2_hmac_sha512_Init(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @pbkdf2_hmac_sha512_Update(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @pbkdf2_hmac_sha512_Final(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #6

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass