; LLVM IR from gost-engine/engine :: gost_gost2015 (gost2015_get_asn1_params)

; 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.asn1_type_st = type { i32, %union.anon }
%union.anon = type { ptr }
%struct.asn1_string_st = type { i32, i32, ptr, i64 }
%struct.GOST2015_CIPHER_PARAMS = type { ptr }

@.str = external hidden unnamed_addr constant [68 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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 i32 @gost2015_get_asn1_params(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 16, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store ptr null, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store ptr null, ptr %14, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = load i32, ptr %12, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %16, i8 0, i64 %18, i1 false)
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call i32 @ASN1_TYPE_get(ptr noundef %19)
  %21 = icmp ne i32 %20, 16
  br i1 %21, label %22, label %23

22:                                               ; preds = %5
  call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef @.str, i32 noundef 64)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %67

23:                                               ; preds = %5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.asn1_type_st, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %struct.asn1_string_st, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  store ptr %28, ptr %14, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.asn1_type_st, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.asn1_string_st, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = sext i32 %33 to i64
  %35 = call ptr @d2i_GOST2015_CIPHER_PARAMS(ptr noundef null, ptr noundef %14, i64 noundef %34)
  store ptr %35, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %23
  call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef @.str, i32 noundef 72)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %67

39:                                               ; preds = %23
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.GOST2015_CIPHER_PARAMS, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = getelementptr inbounds %struct.asn1_string_st, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = trunc i64 %45 to i32
  %47 = icmp ne i32 %44, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %39
  call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef @.str, i32 noundef 78)
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef %49)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %67

50:                                               ; preds = %39
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.GOST2015_CIPHER_PARAMS, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = getelementptr inbounds %struct.asn1_string_st, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 1 %56, i64 %57, i1 false)
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.GOST2015_CIPHER_PARAMS, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = getelementptr inbounds %struct.asn1_string_st, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %58, ptr align 1 %65, i64 8, i1 false)
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef %66)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %67

67:                                               ; preds = %50, %48, %38, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %68 = load i32, ptr %6, align 4
  ret i32 %68
}

declare i32 @ASN1_TYPE_get(ptr noundef) #3

declare void @ERR_GOST_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #3

declare ptr @d2i_GOST2015_CIPHER_PARAMS(ptr noundef, ptr noundef, i64 noundef) #3

declare void @GOST2015_CIPHER_PARAMS_free(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"asn1_string_st", !12, i64 0, !12, i64 4, !6, i64 8, !10, i64 16}
!16 = !{!15, !12, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, 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"

@.str = external hidden unnamed_addr constant [68 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress 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 range(i32 0, 2) i32 @gost2015_get_asn1_params(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, i64 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %7 = tail call i32 @ASN1_TYPE_get(ptr noundef %0) #5
  %.not = icmp eq i32 %7, 16
  br i1 %.not, label %9, label %8

8:                                                ; preds = %5
  tail call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef nonnull @.str, i32 noundef 64) #5
  br label %32

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !8
  store ptr %13, ptr %6, align 8, !tbaa !13
  %14 = load i32, ptr %11, align 8, !tbaa !14
  %15 = sext i32 %14 to i64
  %16 = call ptr @d2i_GOST2015_CIPHER_PARAMS(ptr noundef null, ptr noundef nonnull %6, i64 noundef %15) #5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %9
  call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef nonnull @.str, i32 noundef 72) #5
  br label %32

19:                                               ; preds = %9
  %20 = load ptr, ptr %16, align 8, !tbaa !15
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = trunc i64 %1 to i32
  %.not17 = icmp eq i32 %21, %22
  br i1 %.not17, label %24, label %23

23:                                               ; preds = %19
  call void @ERR_GOST_error(i32 noundef 158, i32 noundef 110, ptr noundef nonnull @.str, i32 noundef 78) #5
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef nonnull %16) #5
  br label %32

24:                                               ; preds = %19
  %25 = getelementptr inbounds i8, ptr %20, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !8
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %2, ptr align 1 %26, i64 %3, i1 false)
  %27 = load ptr, ptr %16, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !8
  %30 = getelementptr inbounds i8, ptr %29, i64 %3
  %31 = load i64, ptr %30, align 1
  store i64 %31, ptr %4, align 1
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef nonnull %16) #5
  br label %32

32:                                               ; preds = %24, %23, %18, %8
  %.0 = phi i32 [ 0, %8 ], [ 0, %18 ], [ 0, %23 ], [ 1, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  ret i32 %.0
}

declare i32 @ASN1_TYPE_get(ptr noundef) local_unnamed_addr #3

declare void @ERR_GOST_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @d2i_GOST2015_CIPHER_PARAMS(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @GOST2015_CIPHER_PARAMS_free(ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 8}
!9 = !{!"asn1_string_st", !10, i64 0, !10, i64 4, !11, i64 8, !12, i64 16}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!9, !10, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"", !11, i64 0}


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