; LLVM IR from guanzhi/GmSSL :: src (tls)

; 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.SM2_KEY = type { %struct.SM2_Z256_POINT, [4 x i64] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }
%struct.TLS_CTX = type { i32, i32, [64 x i32], i64, ptr, i64, ptr, i64, %struct.SM2_KEY, %struct.SM2_KEY, i32, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1
@__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys = external hidden unnamed_addr constant [45 x i8], align 1

; 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) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

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

declare ptr @tls_protocol_name(i32 noundef) #3

declare i32 @x509_certs_get_cert_by_index(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) #3

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

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

declare i32 @x509_cert_get_subject_public_key(ptr noundef, i64 noundef, ptr noundef) #3

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

declare i32 @fclose(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_ctx_set_tlcp_server_certificate_and_keys(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #4 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca %struct.SM2_KEY, align 8
  %20 = alloca %struct.SM2_KEY, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i64, align 8
  %23 = alloca %struct.SM2_KEY, align 8
  %24 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 -1, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store ptr null, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store ptr null, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store ptr null, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %19) #5
  call void @llvm.lifetime.start.p0(i64 128, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.start.p0(i64 128, ptr %23) #5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %42

27:                                               ; preds = %6
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %42

30:                                               ; preds = %27
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %42

33:                                               ; preds = %30
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %48, label %42

42:                                               ; preds = %39, %36, %33, %30, %27, %6
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2212, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %46

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %24, align 4
  br label %191

48:                                               ; preds = %39
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TLS_CTX, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = call ptr @tls_protocol_name(i32 noundef %51)
  %53 = icmp ne ptr %52, null
  br i1 %53, label %60, label %54

54:                                               ; preds = %48
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr @stderr, align 8, !tbaa !5
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2216, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %24, align 4
  br label %191

60:                                               ; preds = %48
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TLS_CTX, ptr %61, i32 0, i32 6
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %71

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2220, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %69

69:                                               ; preds = %66
  br label %70

70:                                               ; preds = %69
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %24, align 4
  br label %191

71:                                               ; preds = %60
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = call i32 @x509_certs_new_from_file(ptr noundef %15, ptr noundef %16, ptr noundef %72)
  %74 = icmp ne i32 %73, 1
  br i1 %74, label %75, label %81

75:                                               ; preds = %71
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2225, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %79

79:                                               ; preds = %76
  br label %80

80:                                               ; preds = %79
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %24, align 4
  br label %191

81:                                               ; preds = %71
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = call noalias ptr @fopen(ptr noundef %82, ptr noundef @.str.11)
  store ptr %83, ptr %17, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %91, label %85

85:                                               ; preds = %81
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2230, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %89

89:                                               ; preds = %86
  br label %90

90:                                               ; preds = %89
  br label %172

91:                                               ; preds = %81
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = load ptr, ptr %17, align 8, !tbaa !5
  %94 = call i32 @sm2_private_key_info_decrypt_from_pem(ptr noundef %19, ptr noundef %92, ptr noundef %93)
  %95 = icmp ne i32 %94, 1
  br i1 %95, label %96, label %102

96:                                               ; preds = %91
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr @stderr, align 8, !tbaa !5
  %99 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %98, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2234, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %100

100:                                              ; preds = %97
  br label %101

101:                                              ; preds = %100
  br label %172

102:                                              ; preds = %91
  %103 = load ptr, ptr %15, align 8, !tbaa !5
  %104 = load i64, ptr %16, align 8, !tbaa !17
  %105 = call i32 @x509_certs_get_cert_by_index(ptr noundef %103, i64 noundef %104, i32 noundef 0, ptr noundef %21, ptr noundef %22)
  %106 = icmp ne i32 %105, 1
  br i1 %106, label %115, label %107

107:                                              ; preds = %102
  %108 = load ptr, ptr %21, align 8, !tbaa !5
  %109 = load i64, ptr %22, align 8, !tbaa !17
  %110 = call i32 @x509_cert_get_subject_public_key(ptr noundef %108, i64 noundef %109, ptr noundef %23)
  %111 = icmp ne i32 %110, 1
  br i1 %111, label %115, label %112

112:                                              ; preds = %107
  %113 = call i32 @sm2_public_key_equ(ptr noundef %19, ptr noundef %23)
  %114 = icmp ne i32 %113, 1
  br i1 %114, label %115, label %121

115:                                              ; preds = %112, %107, %102
  br label %116

116:                                              ; preds = %115
  %117 = load ptr, ptr @stderr, align 8, !tbaa !5
  %118 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %117, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2240, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %119

119:                                              ; preds = %116
  br label %120

120:                                              ; preds = %119
  br label %172

121:                                              ; preds = %112
  %122 = load ptr, ptr %12, align 8, !tbaa !5
  %123 = call noalias ptr @fopen(ptr noundef %122, ptr noundef @.str.11)
  store ptr %123, ptr %18, align 8, !tbaa !5
  %124 = icmp ne ptr %123, null
  br i1 %124, label %131, label %125

125:                                              ; preds = %121
  br label %126

126:                                              ; preds = %125
  %127 = load ptr, ptr @stderr, align 8, !tbaa !5
  %128 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %127, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2245, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %129

129:                                              ; preds = %126
  br label %130

130:                                              ; preds = %129
  br label %172

131:                                              ; preds = %121
  %132 = load ptr, ptr %13, align 8, !tbaa !5
  %133 = load ptr, ptr %18, align 8, !tbaa !5
  %134 = call i32 @sm2_private_key_info_decrypt_from_pem(ptr noundef %20, ptr noundef %132, ptr noundef %133)
  %135 = icmp ne i32 %134, 1
  br i1 %135, label %136, label %142

136:                                              ; preds = %131
  br label %137

137:                                              ; preds = %136
  %138 = load ptr, ptr @stderr, align 8, !tbaa !5
  %139 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %138, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2249, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %140

140:                                              ; preds = %137
  br label %141

141:                                              ; preds = %140
  br label %172

142:                                              ; preds = %131
  %143 = load ptr, ptr %15, align 8, !tbaa !5
  %144 = load i64, ptr %16, align 8, !tbaa !17
  %145 = call i32 @x509_certs_get_cert_by_index(ptr noundef %143, i64 noundef %144, i32 noundef 1, ptr noundef %21, ptr noundef %22)
  %146 = icmp ne i32 %145, 1
  br i1 %146, label %155, label %147

147:                                              ; preds = %142
  %148 = load ptr, ptr %21, align 8, !tbaa !5
  %149 = load i64, ptr %22, align 8, !tbaa !17
  %150 = call i32 @x509_cert_get_subject_public_key(ptr noundef %148, i64 noundef %149, ptr noundef %23)
  %151 = icmp ne i32 %150, 1
  br i1 %151, label %155, label %152

152:                                              ; preds = %147
  %153 = call i32 @sm2_public_key_equ(ptr noundef %20, ptr noundef %23)
  %154 = icmp ne i32 %153, 1
  br i1 %154, label %155, label %161

155:                                              ; preds = %152, %147, %142
  br label %156

156:                                              ; preds = %155
  %157 = load ptr, ptr @stderr, align 8, !tbaa !5
  %158 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %157, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2255, ptr noundef @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #5
  br label %159

159:                                              ; preds = %156
  br label %160

160:                                              ; preds = %159
  br label %172

161:                                              ; preds = %152
  %162 = load ptr, ptr %15, align 8, !tbaa !5
  %163 = load ptr, ptr %8, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.TLS_CTX, ptr %163, i32 0, i32 6
  store ptr %162, ptr %164, align 8, !tbaa !16
  %165 = load i64, ptr %16, align 8, !tbaa !17
  %166 = load ptr, ptr %8, align 8, !tbaa !5
  %167 = getelementptr inbounds %struct.TLS_CTX, ptr %166, i32 0, i32 7
  store i64 %165, ptr %167, align 8, !tbaa !18
  %168 = load ptr, ptr %8, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.TLS_CTX, ptr %168, i32 0, i32 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %169, ptr align 8 %19, i64 128, i1 false), !tbaa.struct !19
  %170 = load ptr, ptr %8, align 8, !tbaa !5
  %171 = getelementptr inbounds %struct.TLS_CTX, ptr %170, i32 0, i32 9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %171, ptr align 8 %20, i64 128, i1 false), !tbaa.struct !19
  store ptr null, ptr %15, align 8, !tbaa !5
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %172

172:                                              ; preds = %161, %160, %141, %130, %120, %101, %90
  call void @gmssl_secure_clear(ptr noundef %19, i64 noundef 128)
  call void @gmssl_secure_clear(ptr noundef %20, i64 noundef 128)
  %173 = load ptr, ptr %15, align 8, !tbaa !5
  %174 = icmp ne ptr %173, null
  br i1 %174, label %175, label %177

175:                                              ; preds = %172
  %176 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %176) #5
  br label %177

177:                                              ; preds = %175, %172
  %178 = load ptr, ptr %17, align 8, !tbaa !5
  %179 = icmp ne ptr %178, null
  br i1 %179, label %180, label %183

180:                                              ; preds = %177
  %181 = load ptr, ptr %17, align 8, !tbaa !5
  %182 = call i32 @fclose(ptr noundef %181)
  br label %183

183:                                              ; preds = %180, %177
  %184 = load ptr, ptr %18, align 8, !tbaa !5
  %185 = icmp ne ptr %184, null
  br i1 %185, label %186, label %189

186:                                              ; preds = %183
  %187 = load ptr, ptr %18, align 8, !tbaa !5
  %188 = call i32 @fclose(ptr noundef %187)
  br label %189

189:                                              ; preds = %186, %183
  %190 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %190, ptr %7, align 4
  store i32 1, ptr %24, align 4
  br label %191

191:                                              ; preds = %189, %80, %70, %59, %47
  call void @llvm.lifetime.end.p0(i64 128, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %192 = load i32, ptr %7, align 4
  ret i32 %192
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { 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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !13, i64 264, !6, i64 272, !13, i64 280, !6, i64 288, !13, i64 296, !14, i64 304, !14, i64 432, !10, i64 560, !10, i64 564}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 96}
!15 = !{!"", !7, i64 0, !7, i64 32, !7, i64 64}
!16 = !{!12, !6, i64 288}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !13, i64 296}
!19 = !{i64 0, i64 32, !20, i64 32, i64 32, !20, i64 64, i64 32, !20, i64 96, i64 32, !20}
!20 = !{!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"

%struct.SM2_KEY = type { %struct.SM2_Z256_POINT, [4 x i64] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1
@__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys = external hidden unnamed_addr constant [45 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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

declare ptr @tls_protocol_name(i32 noundef) local_unnamed_addr #3

declare i32 @x509_certs_get_cert_by_index(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @x509_certs_new_from_file(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

declare i32 @sm2_private_key_info_decrypt_from_pem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @x509_cert_get_subject_public_key(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @sm2_public_key_equ(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_ctx_set_tlcp_server_certificate_and_keys(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, ptr noundef %3, ptr noundef readonly %4, ptr noundef %5) local_unnamed_addr #5 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.SM2_KEY, align 8
  %10 = alloca %struct.SM2_KEY, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca %struct.SM2_KEY, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #6
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #6
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %9) #6
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #6
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %13) #6
  %14 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %15 = insertelement <4 x ptr> %14, ptr %1, i64 1
  %16 = insertelement <4 x ptr> %15, ptr %2, i64 2
  %17 = insertelement <4 x ptr> %16, ptr %3, i64 3
  %18 = icmp ne ptr %4, null
  %19 = icmp ne ptr %5, null
  %20 = icmp eq <4 x ptr> %17, zeroinitializer
  %21 = bitcast <4 x i1> %20 to i4
  %22 = icmp eq i4 %21, 0
  %op.rdx = and i1 %22, %18
  %op.rdx56 = and i1 %op.rdx, %19
  br i1 %op.rdx56, label %26, label %23

23:                                               ; preds = %6
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2212, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %104

26:                                               ; preds = %6
  %27 = load i32, ptr %0, align 8, !tbaa !9
  %28 = tail call ptr @tls_protocol_name(i32 noundef %27) #6
  %.not = icmp eq ptr %28, null
  br i1 %.not, label %29, label %32

29:                                               ; preds = %26
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2216, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %104

32:                                               ; preds = %26
  %33 = getelementptr inbounds i8, ptr %0, i64 288
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %.not42 = icmp eq ptr %34, null
  br i1 %.not42, label %38, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2220, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %104

38:                                               ; preds = %32
  %39 = call i32 @x509_certs_new_from_file(ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %1) #6
  %.not43 = icmp eq i32 %39, 1
  br i1 %.not43, label %43, label %40

40:                                               ; preds = %38
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2225, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %104

43:                                               ; preds = %38
  %44 = call noalias ptr @fopen(ptr noundef nonnull %2, ptr noundef nonnull @.str.11)
  %.not44 = icmp eq ptr %44, null
  br i1 %.not44, label %45, label %48

45:                                               ; preds = %43
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2230, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

48:                                               ; preds = %43
  %49 = call i32 @sm2_private_key_info_decrypt_from_pem(ptr noundef nonnull %9, ptr noundef nonnull %3, ptr noundef nonnull %44) #6
  %.not45 = icmp eq i32 %49, 1
  br i1 %.not45, label %53, label %50

50:                                               ; preds = %48
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2234, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

53:                                               ; preds = %48
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !16
  %56 = call i32 @x509_certs_get_cert_by_index(ptr noundef %54, i64 noundef %55, i32 noundef 0, ptr noundef nonnull %11, ptr noundef nonnull %12) #6
  %.not46 = icmp eq i32 %56, 1
  br i1 %.not46, label %57, label %63

57:                                               ; preds = %53
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i64, ptr %12, align 8, !tbaa !16
  %60 = call i32 @x509_cert_get_subject_public_key(ptr noundef %58, i64 noundef %59, ptr noundef nonnull %13) #6
  %.not47 = icmp eq i32 %60, 1
  br i1 %.not47, label %61, label %63

61:                                               ; preds = %57
  %62 = call i32 @sm2_public_key_equ(ptr noundef nonnull %9, ptr noundef nonnull %13) #6
  %.not48 = icmp eq i32 %62, 1
  br i1 %.not48, label %66, label %63

63:                                               ; preds = %53, %57, %61
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2240, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

66:                                               ; preds = %61
  %67 = call noalias ptr @fopen(ptr noundef nonnull %4, ptr noundef nonnull @.str.11)
  %.not49 = icmp eq ptr %67, null
  br i1 %.not49, label %68, label %71

68:                                               ; preds = %66
  %69 = load ptr, ptr @stderr, align 8, !tbaa !5
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2245, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

71:                                               ; preds = %66
  %72 = call i32 @sm2_private_key_info_decrypt_from_pem(ptr noundef nonnull %10, ptr noundef nonnull %5, ptr noundef nonnull %67) #6
  %.not50 = icmp eq i32 %72, 1
  br i1 %.not50, label %76, label %73

73:                                               ; preds = %71
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2249, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

76:                                               ; preds = %71
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %8, align 8, !tbaa !16
  %79 = call i32 @x509_certs_get_cert_by_index(ptr noundef %77, i64 noundef %78, i32 noundef 1, ptr noundef nonnull %11, ptr noundef nonnull %12) #6
  %.not51 = icmp eq i32 %79, 1
  br i1 %.not51, label %80, label %86

80:                                               ; preds = %76
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = load i64, ptr %12, align 8, !tbaa !16
  %83 = call i32 @x509_cert_get_subject_public_key(ptr noundef %81, i64 noundef %82, ptr noundef nonnull %13) #6
  %.not52 = icmp eq i32 %83, 1
  br i1 %.not52, label %84, label %86

84:                                               ; preds = %80
  %85 = call i32 @sm2_public_key_equ(ptr noundef nonnull %10, ptr noundef nonnull %13) #6
  %.not53 = icmp eq i32 %85, 1
  br i1 %.not53, label %89, label %86

86:                                               ; preds = %76, %80, %84
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2255, ptr noundef nonnull @__FUNCTION__.tls_ctx_set_tlcp_server_certificate_and_keys) #7
  br label %95

89:                                               ; preds = %84
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %90, ptr %33, align 8, !tbaa !15
  %91 = load i64, ptr %8, align 8, !tbaa !16
  %92 = getelementptr inbounds i8, ptr %0, i64 296
  store i64 %91, ptr %92, align 8, !tbaa !17
  %93 = getelementptr inbounds i8, ptr %0, i64 304
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %93, ptr noundef nonnull align 8 dereferenceable(128) %9, i64 128, i1 false), !tbaa.struct !18
  %94 = getelementptr inbounds i8, ptr %0, i64 432
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %94, ptr noundef nonnull align 8 dereferenceable(128) %10, i64 128, i1 false), !tbaa.struct !18
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %95

95:                                               ; preds = %89, %86, %73, %68, %63, %50, %45
  %.033 = phi i32 [ -1, %50 ], [ -1, %63 ], [ -1, %73 ], [ -1, %86 ], [ 1, %89 ], [ -1, %68 ], [ -1, %45 ]
  %.0 = phi ptr [ null, %50 ], [ null, %63 ], [ %67, %73 ], [ %67, %86 ], [ %67, %89 ], [ null, %68 ], [ null, %45 ]
  call void @gmssl_secure_clear(ptr noundef nonnull %9, i64 noundef 128) #6
  call void @gmssl_secure_clear(ptr noundef nonnull %10, i64 noundef 128) #6
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %.not54 = icmp eq ptr %96, null
  br i1 %.not54, label %98, label %97

97:                                               ; preds = %95
  call void @free(ptr noundef nonnull %96) #6
  br label %98

98:                                               ; preds = %97, %95
  br i1 %.not44, label %101, label %99

99:                                               ; preds = %98
  %100 = call i32 @fclose(ptr noundef nonnull %44)
  br label %101

101:                                              ; preds = %99, %98
  %.not55 = icmp eq ptr %.0, null
  br i1 %.not55, label %104, label %102

102:                                              ; preds = %101
  %103 = call i32 @fclose(ptr noundef nonnull %.0)
  br label %104

104:                                              ; preds = %101, %102, %40, %35, %29, %23
  %.034 = phi i32 [ -1, %35 ], [ -1, %40 ], [ -1, %29 ], [ -1, %23 ], [ %.033, %102 ], [ %.033, %101 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %10) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #6
  ret i32 %.034
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { cold 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 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !12, i64 264, !6, i64 272, !12, i64 280, !6, i64 288, !12, i64 296, !13, i64 304, !13, i64 432, !11, i64 560, !11, i64 564}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !14, i64 0, !7, i64 96}
!14 = !{!"", !7, i64 0, !7, i64 32, !7, i64 64}
!15 = !{!10, !6, i64 288}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 296}
!18 = !{i64 0, i64 32, !19, i64 32, i64 32, !19, i64 64, i64 32, !19, i64 96, i64 32, !19}
!19 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass