; LLVM IR from gost-engine/engine :: test_context (main)

; 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.testcase_cipher = type { ptr, i32 }
%struct.testcase_digest = type { ptr, i32 }

@testcases_ciphers = external hidden global [13 x %struct.testcase_cipher], align 16
@testcases_digests = external hidden global [9 x %struct.testcase_digest], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %9 = call i32 @OPENSSL_init_crypto(i64 noundef 76, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr @testcases_ciphers, ptr %7, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %34, %2
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.testcase_cipher, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %37

15:                                               ; preds = %10
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.testcase_cipher, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.testcase_cipher, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = call i32 @test_contexts_cipher(ptr noundef %18, i32 noundef 1, i32 noundef %21)
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = or i32 %23, %22
  store i32 %24, ptr %6, align 4, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.testcase_cipher, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.testcase_cipher, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = call i32 @test_contexts_cipher(ptr noundef %27, i32 noundef 0, i32 noundef %30)
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = or i32 %32, %31
  store i32 %33, ptr %6, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %15
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.testcase_cipher, ptr %35, i32 1
  store ptr %36, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !14

37:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr @testcases_digests, ptr %8, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %63, %37
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.testcase_digest, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %66

43:                                               ; preds = %38
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.testcase_digest, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !18
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %55

48:                                               ; preds = %43
  %49 = load ptr, ptr %8, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.testcase_digest, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = call i32 @test_contexts_mac(ptr noundef %51)
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = or i32 %53, %52
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %62

55:                                               ; preds = %43
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.testcase_digest, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = call i32 @test_contexts_digest(ptr noundef %58)
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = or i32 %60, %59
  store i32 %61, ptr %6, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %55, %48
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.testcase_digest, ptr %64, i32 1
  store ptr %65, ptr %8, align 8, !tbaa !9
  br label %38, !llvm.loop !19

66:                                               ; preds = %38
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %66
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %73

71:                                               ; preds = %66
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %73

73:                                               ; preds = %71, %69
  %74 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  ret i32 %74
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @OPENSSL_init_crypto(i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_cipher(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_mac(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_digest(ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"testcase_cipher", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 0}
!17 = !{!"testcase_digest", !10, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = distinct !{!19, !15}


; 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.testcase_cipher = type { ptr, i32 }
%struct.testcase_digest = type { ptr, i32 }

@testcases_ciphers = external hidden local_unnamed_addr global [13 x %struct.testcase_cipher], align 16
@testcases_digests = external hidden local_unnamed_addr global [9 x %struct.testcase_digest], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 @OPENSSL_init_crypto(i64 noundef 76, ptr noundef null) #3
  %4 = load ptr, ptr @testcases_ciphers, align 16, !tbaa !5
  %.not23 = icmp eq ptr %4, null
  br i1 %.not23, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %2
  %.017.lcssa = phi i32 [ 0, %2 ], [ %14, %.lr.ph ]
  %5 = load ptr, ptr @testcases_digests, align 16, !tbaa !11
  %.not2026 = icmp eq ptr %5, null
  br i1 %.not2026, label %._crit_edge, label %.lr.ph29

.lr.ph:                                           ; preds = %2, %.lr.ph
  %6 = phi ptr [ %16, %.lr.ph ], [ %4, %2 ]
  %.01625 = phi ptr [ %15, %.lr.ph ], [ @testcases_ciphers, %2 ]
  %.01724 = phi i32 [ %14, %.lr.ph ], [ 0, %2 ]
  %7 = getelementptr inbounds i8, ptr %.01625, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = tail call i32 @test_contexts_cipher(ptr noundef nonnull %6, i32 noundef 1, i32 noundef %8)
  %10 = load ptr, ptr %.01625, align 8, !tbaa !5
  %11 = load i32, ptr %7, align 8, !tbaa !13
  %12 = tail call i32 @test_contexts_cipher(ptr noundef %10, i32 noundef 0, i32 noundef %11)
  %13 = or i32 %9, %.01724
  %14 = or i32 %13, %12
  %15 = getelementptr inbounds i8, ptr %.01625, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !14

.lr.ph29:                                         ; preds = %.preheader, %24
  %17 = phi ptr [ %26, %24 ], [ %5, %.preheader ]
  %.028 = phi ptr [ %25, %24 ], [ @testcases_digests, %.preheader ]
  %.127 = phi i32 [ %.2, %24 ], [ %.017.lcssa, %.preheader ]
  %18 = getelementptr inbounds i8, ptr %.028, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %.not22 = icmp eq i32 %19, 0
  br i1 %.not22, label %22, label %20

20:                                               ; preds = %.lr.ph29
  %21 = tail call i32 @test_contexts_mac(ptr noundef nonnull %17)
  br label %24

22:                                               ; preds = %.lr.ph29
  %23 = tail call i32 @test_contexts_digest(ptr noundef nonnull %17)
  br label %24

24:                                               ; preds = %20, %22
  %.pn = phi i32 [ %21, %20 ], [ %23, %22 ]
  %.2 = or i32 %.pn, %.127
  %25 = getelementptr inbounds i8, ptr %.028, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %.not20 = icmp eq ptr %26, null
  br i1 %.not20, label %._crit_edge, label %.lr.ph29, !llvm.loop !17

._crit_edge:                                      ; preds = %24, %.preheader
  %.1.lcssa = phi i32 [ %.017.lcssa, %.preheader ], [ %.2, %24 ]
  %.not21 = icmp eq i32 %.1.lcssa, 0
  %.str.1..str = select i1 %.not21, ptr @.str.1, ptr @.str
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1..str)
  ret i32 %.1.lcssa
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_cipher(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_mac(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @test_contexts_digest(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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


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