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

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

@.str.1 = external hidden unnamed_addr constant [20 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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gost2015_process_unprotected_attributes(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %40

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call ptr @OBJ_txt2obj(ptr noundef @.str.1, i32 noundef 1)
  %17 = call ptr @X509at_get0_data_by_OBJ(ptr noundef %15, ptr noundef %16, i32 noundef -3, i32 noundef 4)
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %14
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.asn1_string_st, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = trunc i64 %24 to i32
  %26 = icmp ne i32 %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %20, %14
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %37

28:                                               ; preds = %20
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.asn1_string_st, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.asn1_string_st, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = sext i32 %35 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %29, ptr align 1 %32, i64 %36, i1 false)
  store i32 0, ptr %11, align 4
  br label %37

37:                                               ; preds = %28, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %38 = load i32, ptr %11, align 4
  switch i32 %38, label %56 [
    i32 0, label %39
    i32 1, label %54
  ]

39:                                               ; preds = %37
  br label %53

40:                                               ; preds = %4
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -1, ptr %5, align 4
  br label %54

44:                                               ; preds = %40
  %45 = call ptr @OBJ_txt2obj(ptr noundef @.str.1, i32 noundef 1)
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = trunc i64 %47 to i32
  %49 = call ptr @X509at_add1_attr_by_OBJ(ptr noundef %6, ptr noundef %45, i32 noundef 4, ptr noundef %46, i32 noundef %48)
  %50 = icmp eq ptr %49, null
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 -1, i32 1
  store i32 %52, ptr %5, align 4
  br label %54

53:                                               ; preds = %39
  store i32 1, ptr %5, align 4
  br label %54

54:                                               ; preds = %53, %44, %43, %37
  %55 = load i32, ptr %5, align 4
  ret i32 %55

56:                                               ; preds = %37
  unreachable
}

declare ptr @X509at_get0_data_by_OBJ(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #3

declare ptr @OBJ_txt2obj(ptr noundef, i32 noundef) #3

declare ptr @X509at_add1_attr_by_OBJ(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #3

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


; 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.1 = external hidden unnamed_addr constant [20 x i8], align 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) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @gost2015_process_unprotected_attributes(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  %6 = icmp eq i32 %1, 0
  br i1 %6, label %7, label %17

7:                                                ; preds = %4
  %8 = tail call ptr @OBJ_txt2obj(ptr noundef nonnull @.str.1, i32 noundef 1) #3
  %9 = tail call ptr @X509at_get0_data_by_OBJ(ptr noundef %0, ptr noundef %8, i32 noundef -3, i32 noundef 4) #3
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.thread, label %10

10:                                               ; preds = %7
  %11 = load i32, ptr %9, align 8, !tbaa !9
  %12 = trunc i64 %2 to i32
  %.not13 = icmp eq i32 %11, %12
  br i1 %.not13, label %13, label %.thread

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %sext = shl i64 %2, 32
  %16 = ashr exact i64 %sext, 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 %15, i64 %16, i1 false)
  br label %.thread

17:                                               ; preds = %4
  %18 = icmp eq ptr %0, null
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %17
  %20 = tail call ptr @OBJ_txt2obj(ptr noundef nonnull @.str.1, i32 noundef 1) #3
  %21 = trunc i64 %2 to i32
  %22 = call ptr @X509at_add1_attr_by_OBJ(ptr noundef nonnull %5, ptr noundef %20, i32 noundef 4, ptr noundef %3, i32 noundef %21) #3
  %23 = icmp eq ptr %22, null
  %24 = select i1 %23, i32 -1, i32 1
  br label %.thread

.thread:                                          ; preds = %7, %10, %13, %17, %19
  %.1 = phi i32 [ %24, %19 ], [ -1, %17 ], [ 1, %13 ], [ -1, %10 ], [ -1, %7 ]
  ret i32 %.1
}

declare ptr @X509at_get0_data_by_OBJ(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @OBJ_txt2obj(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @X509at_add1_attr_by_OBJ(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree 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 }

!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, !11, i64 0}
!10 = !{!"asn1_string_st", !11, i64 0, !11, i64 4, !6, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 8}


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