; LLVM IR from gost-engine/engine :: gost_gost2015 (gost2015_set_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.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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare void @GOST2015_CIPHER_PARAMS_free(ptr noundef) #1

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

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

20:                                               ; preds = %4
  call void @ERR_GOST_error(i32 noundef 159, i32 noundef 786688, ptr noundef @.str, i32 noundef 101)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %69

21:                                               ; preds = %4
  %22 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %22, ptr align 1 %23, i64 %24, i1 false)
  %25 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %27, ptr align 1 %28, i64 8, i1 false)
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.GOST2015_CIPHER_PARAMS, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = add i64 %33, 8
  %35 = trunc i64 %34 to i32
  %36 = call i32 @ASN1_STRING_set(ptr noundef %31, ptr noundef %32, i32 noundef %35)
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %21
  call void @ERR_GOST_error(i32 noundef 159, i32 noundef 786688, ptr noundef @.str, i32 noundef 109)
  br label %57

39:                                               ; preds = %21
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call i32 @i2d_GOST2015_CIPHER_PARAMS(ptr noundef %40, ptr noundef %15)
  store i32 %41, ptr %12, align 4, !tbaa !11
  %42 = load i32, ptr %12, align 4, !tbaa !11
  %43 = icmp sle i32 %42, 0
  br i1 %43, label %53, label %44

44:                                               ; preds = %39
  %45 = call ptr @ASN1_OCTET_STRING_new()
  store ptr %45, ptr %13, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %53, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !11
  %51 = call i32 @ASN1_OCTET_STRING_set(ptr noundef %48, ptr noundef %49, i32 noundef %50)
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %47, %44, %39
  br label %57

54:                                               ; preds = %47
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  call void @ASN1_TYPE_set(ptr noundef %55, i32 noundef 16, ptr noundef %56)
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %54, %53, %38
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %58, ptr noundef @.str, i32 noundef 125)
  %59 = load i32, ptr %11, align 4, !tbaa !11
  %60 = icmp sle i32 %59, 0
  br i1 %60, label %61, label %66

61:                                               ; preds = %57
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %66

64:                                               ; preds = %61
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  call void @ASN1_OCTET_STRING_free(ptr noundef %65)
  br label %66

66:                                               ; preds = %64, %61, %57
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef %67)
  %68 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %68, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %69

69:                                               ; preds = %66, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %70 = load i32, ptr %5, align 4
  ret i32 %70
}

declare ptr @GOST2015_CIPHER_PARAMS_new() #1

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

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

declare ptr @ASN1_OCTET_STRING_new() #1

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

declare void @ASN1_TYPE_set(ptr noundef, i32 noundef, ptr noundef) #1

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) #1

declare void @ASN1_OCTET_STRING_free(ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!14, !6, i64 0}
!14 = !{!"", !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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare void @GOST2015_CIPHER_PARAMS_free(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @gost2015_set_asn1_params(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #3 {
  %5 = alloca [16 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = tail call ptr @GOST2015_CIPHER_PARAMS_new() #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %4
  tail call void @ERR_GOST_error(i32 noundef 159, i32 noundef 786688, ptr noundef nonnull @.str, i32 noundef 101) #4
  br label %36

10:                                               ; preds = %4
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr align 1 %1, i64 %2, i1 false)
  %11 = getelementptr inbounds i8, ptr %5, i64 %2
  %12 = load i64, ptr %3, align 1
  store i64 %12, ptr %11, align 1
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = trunc i64 %2 to i32
  %15 = add i32 %14, 8
  %16 = call i32 @ASN1_STRING_set(ptr noundef %13, ptr noundef nonnull %5, i32 noundef %15) #4
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  call void @ERR_GOST_error(i32 noundef 159, i32 noundef 786688, ptr noundef nonnull @.str, i32 noundef 109) #4
  br label %30

19:                                               ; preds = %10
  %20 = call i32 @i2d_GOST2015_CIPHER_PARAMS(ptr noundef nonnull %7, ptr noundef nonnull %6) #4
  %21 = icmp slt i32 %20, 1
  br i1 %21, label %30, label %22

22:                                               ; preds = %19
  %23 = call ptr @ASN1_OCTET_STRING_new() #4
  %24 = icmp eq ptr %23, null
  br i1 %24, label %30, label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i32 @ASN1_OCTET_STRING_set(ptr noundef nonnull %23, ptr noundef %26, i32 noundef %20) #4
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @ASN1_TYPE_set(ptr noundef %0, i32 noundef 16, ptr noundef nonnull %23) #4
  br label %30

30:                                               ; preds = %19, %22, %25, %29, %18
  %31 = phi i1 [ true, %18 ], [ true, %19 ], [ true, %22 ], [ true, %25 ], [ false, %29 ]
  %.019 = phi i32 [ 0, %18 ], [ 0, %19 ], [ 0, %22 ], [ 0, %25 ], [ 1, %29 ]
  %.0 = phi ptr [ null, %18 ], [ null, %19 ], [ null, %22 ], [ %23, %25 ], [ %23, %29 ]
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %32, ptr noundef nonnull @.str, i32 noundef 125) #4
  %33 = icmp ne ptr %.0, null
  %or.cond = and i1 %31, %33
  br i1 %or.cond, label %34, label %35

34:                                               ; preds = %30
  call void @ASN1_OCTET_STRING_free(ptr noundef nonnull %.0) #4
  br label %35

35:                                               ; preds = %34, %30
  call void @GOST2015_CIPHER_PARAMS_free(ptr noundef nonnull %7) #4
  br label %36

36:                                               ; preds = %35, %9
  %.020 = phi i32 [ 0, %9 ], [ %.019, %35 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  ret i32 %.020
}

declare ptr @GOST2015_CIPHER_PARAMS_new() local_unnamed_addr #1

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

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

declare ptr @ASN1_OCTET_STRING_new() local_unnamed_addr #1

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

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

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

declare void @ASN1_OCTET_STRING_free(ptr noundef) 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !6, i64 0}
!10 = !{!"", !6, i64 0}


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