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

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

@.str = external hidden unnamed_addr constant [73 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

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: nounwind uwtable
define dso_local void @ERR_vset_error(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i64 0, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %17 = call ptr @ossl_err_get_state_int()
  store ptr %17, ptr %9, align 8, !tbaa !9
  %18 = load ptr, ptr %9, align 8, !tbaa !9
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  store i32 1, ptr %14, align 4
  br label %123

21:                                               ; preds = %4
  %22 = load ptr, ptr %9, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.err_state_st, ptr %22, i32 0, i32 9
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = sext i32 %24 to i64
  store i64 %25, ptr %13, align 8, !tbaa !11
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %97

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store ptr null, ptr %16, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.err_state_st, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %13, align 8, !tbaa !11
  %32 = getelementptr inbounds [16 x ptr], ptr %30, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  store ptr %33, ptr %10, align 8, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.err_state_st, ptr %34, i32 0, i32 4
  %36 = load i64, ptr %13, align 8, !tbaa !11
  %37 = getelementptr inbounds [16 x i64], ptr %35, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !11
  store i64 %38, ptr %11, align 8, !tbaa !11
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.err_state_st, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %13, align 8, !tbaa !11
  %42 = getelementptr inbounds [16 x ptr], ptr %40, i64 0, i64 %41
  store ptr null, ptr %42, align 8, !tbaa !9
  %43 = load ptr, ptr %9, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.err_state_st, ptr %43, i32 0, i32 5
  %45 = load i64, ptr %13, align 8, !tbaa !11
  %46 = getelementptr inbounds [16 x i32], ptr %44, i64 0, i64 %45
  store i32 0, ptr %46, align 4, !tbaa !5
  %47 = load i64, ptr %11, align 8, !tbaa !11
  %48 = icmp ult i64 %47, 1024
  br i1 %48, label %49, label %55

49:                                               ; preds = %28
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = call ptr @CRYPTO_realloc(ptr noundef %50, i64 noundef 1024, ptr noundef @.str, i32 noundef 84)
  store ptr %51, ptr %16, align 8, !tbaa !9
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %55

53:                                               ; preds = %49
  %54 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %54, ptr %10, align 8, !tbaa !9
  store i64 1024, ptr %11, align 8, !tbaa !11
  br label %55

55:                                               ; preds = %53, %49, %28
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %64

58:                                               ; preds = %55
  %59 = load ptr, ptr %10, align 8, !tbaa !9
  %60 = load i64, ptr %11, align 8, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = call i32 @BIO_vsnprintf(ptr noundef %59, i64 noundef %60, ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %15, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %58, %55
  %65 = load i32, ptr %15, align 4, !tbaa !5
  %66 = icmp slt i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %67, %64
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %76

71:                                               ; preds = %68
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = load i32, ptr %15, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  store i8 0, ptr %75, align 1, !tbaa !15
  br label %76

76:                                               ; preds = %71, %68
  %77 = load ptr, ptr %10, align 8, !tbaa !9
  %78 = load i32, ptr %15, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = call ptr @CRYPTO_realloc(ptr noundef %77, i64 noundef %80, ptr noundef @.str, i32 noundef 103)
  store ptr %81, ptr %16, align 8, !tbaa !9
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %92

83:                                               ; preds = %76
  %84 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %84, ptr %10, align 8, !tbaa !9
  %85 = load i32, ptr %15, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  store i64 %87, ptr %11, align 8, !tbaa !11
  %88 = load ptr, ptr %10, align 8, !tbaa !9
  %89 = load i32, ptr %15, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %88, i64 %90
  store i8 0, ptr %91, align 1, !tbaa !15
  br label %92

92:                                               ; preds = %83, %76
  %93 = load ptr, ptr %10, align 8, !tbaa !9
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %96

95:                                               ; preds = %92
  store i64 3, ptr %12, align 8, !tbaa !11
  br label %96

96:                                               ; preds = %95, %92
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %97

97:                                               ; preds = %96, %21
  %98 = load ptr, ptr %9, align 8, !tbaa !9
  %99 = load ptr, ptr %9, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.err_state_st, ptr %99, i32 0, i32 9
  %101 = load i32, ptr %100, align 8, !tbaa !13
  %102 = sext i32 %101 to i64
  call void @err_clear_data(ptr noundef %98, i64 noundef %102, i32 noundef 0)
  %103 = load ptr, ptr %9, align 8, !tbaa !9
  %104 = load ptr, ptr %9, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.err_state_st, ptr %104, i32 0, i32 9
  %106 = load i32, ptr %105, align 8, !tbaa !13
  %107 = sext i32 %106 to i64
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = load i32, ptr %6, align 4, !tbaa !5
  call void @err_set_error(ptr noundef %103, i64 noundef %107, i32 noundef %108, i32 noundef %109)
  %110 = load ptr, ptr %7, align 8, !tbaa !9
  %111 = icmp ne ptr %110, null
  br i1 %111, label %112, label %122

112:                                              ; preds = %97
  %113 = load ptr, ptr %9, align 8, !tbaa !9
  %114 = load ptr, ptr %9, align 8, !tbaa !9
  %115 = getelementptr inbounds %struct.err_state_st, ptr %114, i32 0, i32 9
  %116 = load i32, ptr %115, align 8, !tbaa !13
  %117 = sext i32 %116 to i64
  %118 = load ptr, ptr %10, align 8, !tbaa !9
  %119 = load i64, ptr %11, align 8, !tbaa !11
  %120 = load i64, ptr %12, align 8, !tbaa !11
  %121 = trunc i64 %120 to i32
  call void @err_set_data(ptr noundef %113, i64 noundef %117, ptr noundef %118, i64 noundef %119, i32 noundef %121)
  br label %122

122:                                              ; preds = %112, %97
  store i32 0, ptr %14, align 4
  br label %123

123:                                              ; preds = %122, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %124 = load i32, ptr %14, align 4
  switch i32 %124, label %126 [
    i32 0, label %125
    i32 1, label %125
  ]

125:                                              ; preds = %123, %123
  ret void

126:                                              ; preds = %123
  unreachable
}

declare ptr @CRYPTO_realloc(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

declare i32 @BIO_vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

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

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

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

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 = { 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 = { 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 #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 = !{!"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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 896}
!14 = !{!"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, !6, i64 896, !6, i64 900}
!15 = !{!7, !7, 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 [73 x i8], align 1

declare ptr @ossl_err_get_state_int() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ERR_vset_error(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call ptr @ossl_err_get_state_int() #4
  %6 = icmp eq ptr %5, null
  br i1 %6, label %43, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %5, i64 896
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %35, label %9

9:                                                ; preds = %7
  %10 = load i32, ptr %8, align 8, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %5, i64 256
  %13 = getelementptr inbounds [16 x ptr], ptr %12, i64 0, i64 %11
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %5, i64 384
  %16 = getelementptr inbounds [16 x i64], ptr %15, i64 0, i64 %11
  %17 = load i64, ptr %16, align 8, !tbaa !12
  store ptr null, ptr %13, align 8, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %5, i64 512
  %19 = getelementptr inbounds [16 x i32], ptr %18, i64 0, i64 %11
  store i32 0, ptr %19, align 4, !tbaa !14
  %20 = icmp ult i64 %17, 1024
  br i1 %20, label %21, label %23

21:                                               ; preds = %9
  %22 = tail call ptr @CRYPTO_realloc(ptr noundef %14, i64 noundef 1024, ptr noundef nonnull @.str, i32 noundef 84) #4
  %.not53 = icmp eq ptr %22, null
  %spec.select = select i1 %.not53, i64 %17, i64 1024
  %spec.select57 = select i1 %.not53, ptr %14, ptr %22
  br label %23

23:                                               ; preds = %21, %9
  %.044 = phi i64 [ %17, %9 ], [ %spec.select, %21 ]
  %.041 = phi ptr [ %14, %9 ], [ %spec.select57, %21 ]
  %.not54 = icmp eq ptr %.041, null
  br i1 %.not54, label %.thread, label %24

24:                                               ; preds = %23
  %25 = tail call i32 @BIO_vsnprintf(ptr noundef nonnull %.041, i64 noundef %.044, ptr noundef nonnull %2, ptr noundef %3) #4
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %25, i32 0)
  %26 = zext nneg i32 %spec.store.select to i64
  %27 = getelementptr inbounds i8, ptr %.041, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !15
  br label %.thread

.thread:                                          ; preds = %23, %24
  %spec.store.select61 = phi i32 [ %spec.store.select, %24 ], [ 0, %23 ]
  %28 = add nuw nsw i32 %spec.store.select61, 1
  %29 = zext nneg i32 %28 to i64
  %30 = tail call ptr @CRYPTO_realloc(ptr noundef %.041, i64 noundef %29, ptr noundef nonnull @.str, i32 noundef 103) #4
  %.not55 = icmp eq ptr %30, null
  br i1 %.not55, label %34, label %31

31:                                               ; preds = %.thread
  %32 = zext nneg i32 %spec.store.select61 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  store i8 0, ptr %33, align 1, !tbaa !15
  br label %34

34:                                               ; preds = %31, %.thread
  %.145 = phi i64 [ %29, %31 ], [ %.044, %.thread ]
  %.1 = phi ptr [ %30, %31 ], [ %.041, %.thread ]
  %.not56 = icmp eq ptr %.1, null
  %spec.select58 = select i1 %.not56, i32 0, i32 3
  br label %35

35:                                               ; preds = %34, %7
  %.246 = phi i64 [ %.145, %34 ], [ 0, %7 ]
  %.143 = phi i32 [ %spec.select58, %34 ], [ 0, %7 ]
  %.2 = phi ptr [ %.1, %34 ], [ null, %7 ]
  %36 = load i32, ptr %8, align 8, !tbaa !5
  %37 = sext i32 %36 to i64
  tail call void @err_clear_data(ptr noundef nonnull %5, i64 noundef %37, i32 noundef 0)
  %38 = load i32, ptr %8, align 8, !tbaa !5
  %39 = sext i32 %38 to i64
  tail call void @err_set_error(ptr noundef nonnull %5, i64 noundef %39, i32 noundef %0, i32 noundef %1)
  br i1 %.not, label %43, label %40

40:                                               ; preds = %35
  %41 = load i32, ptr %8, align 8, !tbaa !5
  %42 = sext i32 %41 to i64
  tail call void @err_set_data(ptr noundef nonnull %5, i64 noundef %42, ptr noundef %.2, i64 noundef %.246, i32 noundef %.143)
  br label %43

43:                                               ; preds = %35, %40, %4
  ret void
}

declare ptr @CRYPTO_realloc(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @BIO_vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { 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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !9, i64 896}
!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 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!9, !9, i64 0}
!15 = !{!7, !7, i64 0}


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