; LLVM IR from guanzhi/GmSSL :: src/skf (skf_lib)

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

@skf_method = external dso_local global ptr, align 8
@skf_vendor = external dso_local global ptr, align 8
@skf_wisec = external global %struct.skf_vendor_st, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @SKF_LoadLibrary(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr @skf_method, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = load ptr, ptr @skf_method, align 8, !tbaa !5
  call void @SKF_METHOD_free(ptr noundef %9)
  store ptr null, ptr @skf_method, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call ptr @SKF_METHOD_load_library(ptr noundef %11)
  store ptr %12, ptr @skf_method, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 167772161, ptr %3, align 4
  br label %27

15:                                               ; preds = %10
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %26

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr @skf_wisec, align 8, !tbaa !9
  %21 = call i32 @strcmp(ptr noundef %19, ptr noundef %20) #3
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  store ptr @skf_wisec, ptr @skf_vendor, align 8, !tbaa !5
  br label %25

24:                                               ; preds = %18
  store i32 167772161, ptr %3, align 4
  br label %27

25:                                               ; preds = %23
  br label %26

26:                                               ; preds = %25, %15
  store i32 0, ptr %3, align 4
  br label %27

27:                                               ; preds = %26, %24, %14
  %28 = load i32, ptr %3, align 4
  ret i32 %28
}

declare void @SKF_METHOD_free(ptr noundef) #1

declare ptr @SKF_METHOD_load_library(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #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 = { nounwind willreturn memory(read) "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 willreturn memory(read) }

!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, !6, i64 0}
!10 = !{!"skf_vendor_st", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!11 = !{!"int", !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.skf_vendor_st = type { ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@skf_method = external dso_local local_unnamed_addr global ptr, align 8
@skf_vendor = external dso_local local_unnamed_addr global ptr, align 8
@skf_wisec = external global %struct.skf_vendor_st, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 167772162) i32 @SKF_LoadLibrary(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @skf_method, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  tail call void @SKF_METHOD_free(ptr noundef nonnull %3) #3
  store ptr null, ptr @skf_method, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %4, %2
  %6 = tail call ptr @SKF_METHOD_load_library(ptr noundef %0) #3
  store ptr %6, ptr @skf_method, align 8, !tbaa !5
  %.not5 = icmp eq ptr %6, null
  br i1 %.not5, label %13, label %7

7:                                                ; preds = %5
  %.not6 = icmp eq ptr %1, null
  br i1 %.not6, label %13, label %8

8:                                                ; preds = %7
  %9 = load ptr, ptr @skf_wisec, align 8, !tbaa !9
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %9) #4
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %8
  store ptr @skf_wisec, ptr @skf_vendor, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %7, %12, %8, %5
  %.0 = phi i32 [ 167772161, %5 ], [ 167772161, %8 ], [ 0, %12 ], [ 0, %7 ]
  ret i32 %.0
}

declare void @SKF_METHOD_free(ptr noundef) local_unnamed_addr #1

declare ptr @SKF_METHOD_load_library(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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, !6, i64 0}
!10 = !{!"skf_vendor_st", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!11 = !{!"int", !7, i64 0}


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