; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (hash)

; 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.HashCtx_st = type { ptr, i32, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [14 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare i32 @gost34311_update(ptr noundef, ptr noundef) #2

declare i32 @gost34311_final(ptr noundef, ptr noundef) #2

declare void @gost34311_free(ptr noundef) #2

declare i64 @gost34311_get_block_size(ptr noundef) #2

declare ptr @gost34311_copy_with_alloc(ptr 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: nounwind uwtable
define dso_local ptr @hash_alloc_gost34311_with_sbox(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %1
  %6 = call noalias ptr @malloc(i64 noundef 56) #6
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr null, %6
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  store i32 1, ptr %3, align 4, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 305, i32 noundef %9, ptr noundef null)
  br label %36

10:                                               ; preds = %5
  br label %11

11:                                               ; preds = %10
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HashCtx_st, ptr %13, i32 0, i32 1
  store i32 4, ptr %14, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call ptr @gost34311_alloc_user_sbox(ptr noundef %16, ptr noundef null)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.HashCtx_st, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !13
  %20 = icmp eq ptr null, %17
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  store i32 2, ptr %3, align 4, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 308, i32 noundef %22)
  br label %36

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.HashCtx_st, ptr %26, i32 0, i32 2
  store ptr @gost34311_update, ptr %27, align 8, !tbaa !14
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.HashCtx_st, ptr %28, i32 0, i32 3
  store ptr @gost34311_final, ptr %29, align 8, !tbaa !15
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HashCtx_st, ptr %30, i32 0, i32 4
  store ptr @gost34311_free, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.HashCtx_st, ptr %32, i32 0, i32 5
  store ptr @gost34311_get_block_size, ptr %33, align 8, !tbaa !17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HashCtx_st, ptr %34, i32 0, i32 6
  store ptr @gost34311_copy_with_alloc, ptr %35, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %25, %21, %8
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %40) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39, %36
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr %42
}

declare ptr @gost34311_alloc_user_sbox(ptr noundef, ptr noundef) #2

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

!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, !10, i64 8}
!12 = !{!"HashCtx_st", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !6, i64 48}


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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

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

declare void @gost34311_free(ptr noundef) #1

declare i64 @gost34311_get_block_size(ptr noundef) #1

declare ptr @gost34311_copy_with_alloc(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @hash_alloc_gost34311_with_sbox(ptr noundef %0) local_unnamed_addr #3 {
  %2 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #4
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 305, i32 noundef 1, ptr noundef null) #5
  br label %.critedge

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 4, ptr %6, align 8, !tbaa !5
  %7 = tail call ptr @gost34311_alloc_user_sbox(ptr noundef %0, ptr noundef null) #5
  store ptr %7, ptr %2, align 8, !tbaa !11
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 308, i32 noundef 2) #5
  br label %.critedge

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr @gost34311_update, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr @gost34311_final, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr @gost34311_free, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr @gost34311_get_block_size, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %2, i64 48
  store ptr @gost34311_copy_with_alloc, ptr %15, align 8, !tbaa !16
  br label %16

.critedge:                                        ; preds = %9, %4
  tail call void @free(ptr noundef %2) #5
  br label %16

16:                                               ; preds = %10, %.critedge
  %.0 = phi ptr [ null, %.critedge ], [ %2, %10 ]
  ret ptr %.0
}

declare ptr @gost34311_alloc_user_sbox(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 allocsize(0) }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"HashCtx_st", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 24}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !7, i64 48}


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