; LLVM IR from gost-engine/engine :: gost_crypt (get_encryption_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.gost_cipher_info = type { i32, ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@gost_cipher_list = external hidden global [7 x %struct.gost_cipher_info], align 16
@.str.8 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [40 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: nounwind uwtable
define dso_local ptr @get_encryption_params(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %55, label %11

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = call ptr @get_gost_engine_param(i32 noundef 0)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #5
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %44, label %19

19:                                               ; preds = %15, %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %39, %19
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [7 x %struct.gost_cipher_info], ptr @gost_cipher_list, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.gost_cipher_info, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %42

27:                                               ; preds = %20
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [7 x %struct.gost_cipher_info], ptr @gost_cipher_list, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.gost_cipher_info, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = icmp eq i32 %32, 1003
  br i1 %33, label %34, label %38

34:                                               ; preds = %27
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [7 x %struct.gost_cipher_info], ptr @gost_cipher_list, i64 0, i64 %36
  store ptr %37, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %43

38:                                               ; preds = %27
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !13

42:                                               ; preds = %20
  store ptr @gost_cipher_list, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %42, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %52

44:                                               ; preds = %15
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call i32 @OBJ_txt2nid(ptr noundef %45)
  store i32 %46, ptr %4, align 4, !tbaa !9
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %44
  call void @ERR_GOST_error(i32 noundef 103, i32 noundef 111, ptr noundef @.str.1, i32 noundef 383)
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  call void (i32, ...) @ERR_add_error_data(i32 noundef 3, ptr noundef @.str.8, ptr noundef %50, ptr noundef @.str.9)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %52

51:                                               ; preds = %44
  store i32 0, ptr %8, align 4
  br label %52

52:                                               ; preds = %51, %49, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %53 = load i32, ptr %8, align 4
  switch i32 %53, label %84 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %58

55:                                               ; preds = %1
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call i32 @OBJ_obj2nid(ptr noundef %56)
  store i32 %57, ptr %4, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %55, %54
  store ptr @gost_cipher_list, ptr %5, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %73, %58
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.gost_cipher_info, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %70

64:                                               ; preds = %59
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gost_cipher_info, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = icmp ne i32 %67, %68
  br label %70

70:                                               ; preds = %64, %59
  %71 = phi i1 [ false, %59 ], [ %69, %64 ]
  br i1 %71, label %72, label %76

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gost_cipher_info, ptr %74, i32 1
  store ptr %75, ptr %5, align 8, !tbaa !5
  br label %59, !llvm.loop !16

76:                                               ; preds = %70
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gost_cipher_info, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !15
  %80 = icmp ne ptr %79, null
  br i1 %80, label %82, label %81

81:                                               ; preds = %76
  call void @ERR_GOST_error(i32 noundef 103, i32 noundef 110, ptr noundef @.str.1, i32 noundef 394)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %84

82:                                               ; preds = %76
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %83, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %84

84:                                               ; preds = %82, %81, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %85 = load ptr, ptr %2, align 8
  ret ptr %85
}

declare ptr @get_gost_engine_param(i32 noundef) #2

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

declare i32 @OBJ_txt2nid(ptr noundef) #2

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

declare void @ERR_add_error_data(i32 noundef, ...) #2

declare i32 @OBJ_obj2nid(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { nounwind }
attributes #5 = { 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 = !{!12, !10, i64 0}
!12 = !{!"gost_cipher_info", !10, i64 0, !6, i64 8, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !14}


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

@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@gost_cipher_list = external hidden global [7 x %struct.gost_cipher_info], align 16
@.str.8 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @get_encryption_params(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %13

2:                                                ; preds = %1
  %3 = tail call ptr @get_gost_engine_param(i32 noundef 0) #2
  %.not28 = icmp eq ptr %3, null
  br i1 %.not28, label %.preheader, label %4

4:                                                ; preds = %2
  %char0 = load i8, ptr %3, align 1
  %.not29 = icmp eq i8 %char0, 0
  br i1 %.not29, label %.preheader, label %9

.preheader:                                       ; preds = %4, %2
  br label %5

5:                                                ; preds = %.preheader, %8
  %indvars.iv = phi i64 [ %indvars.iv.next, %8 ], [ 0, %.preheader ]
  %6 = getelementptr inbounds [7 x %struct.gost_cipher_info], ptr @gost_cipher_list, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 8, !tbaa !5
  switch i32 %7, label %8 [
    i32 0, label %.critedge
    i32 1003, label %.critedge.loopexit
  ]

8:                                                ; preds = %5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %5, !llvm.loop !11

9:                                                ; preds = %4
  %10 = tail call i32 @OBJ_txt2nid(ptr noundef nonnull %3) #2
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  tail call void @ERR_GOST_error(i32 noundef 103, i32 noundef 111, ptr noundef nonnull @.str.1, i32 noundef 383) #2
  tail call void (i32, ...) @ERR_add_error_data(i32 noundef 3, ptr noundef nonnull @.str.8, ptr noundef nonnull %3, ptr noundef nonnull @.str.9) #2
  br label %.critedge

13:                                               ; preds = %1
  %14 = tail call i32 @OBJ_obj2nid(ptr noundef nonnull %0) #2
  br label %15

15:                                               ; preds = %9, %13
  %.123 = phi i32 [ %14, %13 ], [ %10, %9 ]
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @gost_cipher_list, i64 8), align 8, !tbaa !13
  %.not3140 = icmp eq ptr %16, null
  br i1 %.not3140, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %18
  %.02141 = phi ptr [ %19, %18 ], [ @gost_cipher_list, %15 ]
  %17 = load i32, ptr %.02141, align 8, !tbaa !5
  %.not32 = icmp eq i32 %17, %.123
  br i1 %.not32, label %.critedge, label %18

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.02141, i64 24
  %20 = getelementptr inbounds i8, ptr %.02141, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %.not31 = icmp eq ptr %21, null
  br i1 %.not31, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %18, %15
  tail call void @ERR_GOST_error(i32 noundef 103, i32 noundef 110, ptr noundef nonnull @.str.1, i32 noundef 394) #2
  br label %.critedge

.critedge.loopexit:                               ; preds = %5
  br label %.critedge

.critedge:                                        ; preds = %.lr.ph, %5, %.critedge.loopexit, %12, %._crit_edge
  %.2 = phi ptr [ null, %._crit_edge ], [ null, %12 ], [ %6, %.critedge.loopexit ], [ @gost_cipher_list, %5 ], [ %.02141, %.lr.ph ]
  ret ptr %.2
}

declare ptr @get_gost_engine_param(i32 noundef) local_unnamed_addr #1

declare i32 @OBJ_txt2nid(ptr noundef) local_unnamed_addr #1

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

declare void @ERR_add_error_data(i32 noundef, ...) local_unnamed_addr #1

declare i32 @OBJ_obj2nid(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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, !7, i64 0}
!6 = !{!"gost_cipher_info", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !10, i64 8}
!14 = distinct !{!14, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass