; LLVM IR from openssl/openssl :: crypto/err (err_mark)

; 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.err_state_st = type { [16 x i32], [16 x i32], [16 x i64], [16 x ptr], [16 x i64], [16 x i32], [16 x ptr], [16 x i32], [16 x ptr], i32, i32 }

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

declare ptr @ossl_err_get_state_int() #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @err_clear(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ERR_pop_to_mark() #3 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %4 = call ptr @ossl_err_get_state_int()
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %0
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

8:                                                ; preds = %0
  br label %9

9:                                                ; preds = %45, %8
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.err_state_st, ptr %10, i32 0, i32 10
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.err_state_st, ptr %13, i32 0, i32 9
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = icmp ne i32 %12, %15
  br i1 %16, label %17, label %27

17:                                               ; preds = %9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.err_state_st, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.err_state_st, ptr %20, i32 0, i32 9
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [16 x i32], ptr %19, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp eq i32 %25, 0
  br label %27

27:                                               ; preds = %17, %9
  %28 = phi i1 [ false, %9 ], [ %26, %17 ]
  br i1 %28, label %29, label %49

29:                                               ; preds = %27
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.err_state_st, ptr %31, i32 0, i32 9
  %33 = load i32, ptr %32, align 8, !tbaa !12
  %34 = sext i32 %33 to i64
  call void @err_clear(ptr noundef %30, i64 noundef %34, i32 noundef 0)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.err_state_st, ptr %35, i32 0, i32 9
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %29
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.err_state_st, ptr %40, i32 0, i32 9
  %42 = load i32, ptr %41, align 8, !tbaa !12
  %43 = sub nsw i32 %42, 1
  br label %45

44:                                               ; preds = %29
  br label %45

45:                                               ; preds = %44, %39
  %46 = phi i32 [ %43, %39 ], [ 15, %44 ]
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.err_state_st, ptr %47, i32 0, i32 9
  store i32 %46, ptr %48, align 8, !tbaa !12
  br label %9, !llvm.loop !14

49:                                               ; preds = %27
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.err_state_st, ptr %50, i32 0, i32 10
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.err_state_st, ptr %53, i32 0, i32 9
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = icmp eq i32 %52, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

58:                                               ; preds = %49
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.err_state_st, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.err_state_st, ptr %61, i32 0, i32 9
  %63 = load i32, ptr %62, align 8, !tbaa !12
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [16 x i32], ptr %60, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !13
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %65, align 4, !tbaa !13
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %68

68:                                               ; preds = %58, %57, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %69 = load i32, ptr %1, align 4
  ret i32 %69
}

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 = { inlinehint 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 = { 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, !11, i64 900}
!10 = !{!"err_state_st", !7, i64 0, !7, i64 64, !7, i64 128, !7, i64 256, !7, i64 384, !7, i64 512, !7, i64 576, !7, i64 704, !7, i64 768, !11, i64 896, !11, i64 900}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 896}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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"

declare ptr @ossl_err_get_state_int() local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @err_clear(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ERR_pop_to_mark() local_unnamed_addr #2 {
  %1 = tail call ptr @ossl_err_get_state_int() #3
  %2 = icmp eq ptr %1, null
  br i1 %2, label %.critedge.thread, label %.preheader

.preheader:                                       ; preds = %0
  %3 = getelementptr inbounds i8, ptr %1, i64 900
  %4 = getelementptr inbounds i8, ptr %1, i64 896
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 8, !tbaa !10
  %.not18 = icmp eq i32 %5, %6
  br i1 %.not18, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %1, i64 64
  br label %8

8:                                                ; preds = %.lr.ph, %14
  %9 = phi i32 [ %6, %.lr.ph ], [ %spec.select, %14 ]
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [16 x i32], ptr %7, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %8
  tail call void @err_clear(ptr noundef nonnull %1, i64 noundef %10, i32 noundef 0)
  %15 = load i32, ptr %4, align 8, !tbaa !10
  %16 = icmp sgt i32 %15, 0
  %17 = add nsw i32 %15, -1
  %spec.select = select i1 %16, i32 %17, i32 15
  store i32 %spec.select, ptr %4, align 8, !tbaa !10
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %18, %spec.select
  br i1 %.not, label %.critedge.thread, label %8, !llvm.loop !12

.critedge:                                        ; preds = %8
  %19 = getelementptr inbounds [16 x i32], ptr %7, i64 0, i64 %10
  %20 = add nsw i32 %12, -1
  store i32 %20, ptr %19, align 4, !tbaa !11
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %14, %.preheader, %0, %.critedge
  %.0 = phi i32 [ 1, %.critedge ], [ 0, %0 ], [ 0, %.preheader ], [ 0, %14 ]
  ret i32 %.0
}

attributes #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 = { inlinehint 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 = { 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 = { 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, !9, i64 900}
!6 = !{!"err_state_st", !7, i64 0, !7, i64 64, !7, i64 128, !7, i64 256, !7, i64 384, !7, i64 512, !7, i64 576, !7, i64 704, !7, i64 768, !9, i64 896, !9, i64 900}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 896}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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