; LLVM IR from openanolis/openssl :: apps/lib (app_rand)

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

@save_rand_file = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@randfiles = external hidden global ptr, align 8

declare ptr @CRYPTO_strdup(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_OPENSSL_STRING_sk_type(ptr noundef) #1

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @opt_rand(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %4, label %30 [
    i32 1500, label %5
    i32 1503, label %5
    i32 1501, label %6
    i32 1502, label %22
  ]

5:                                                ; preds = %1, %1
  br label %30

6:                                                ; preds = %1
  %7 = load ptr, ptr @randfiles, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %13

9:                                                ; preds = %6
  %10 = call ptr @OPENSSL_sk_new_null()
  store ptr %10, ptr @randfiles, align 8, !tbaa !9
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  store i32 0, ptr %2, align 4
  br label %31

13:                                               ; preds = %9, %6
  %14 = load ptr, ptr @randfiles, align 8, !tbaa !9
  %15 = call ptr @ossl_check_OPENSSL_STRING_sk_type(ptr noundef %14)
  %16 = call ptr @opt_arg()
  %17 = call ptr @ossl_check_OPENSSL_STRING_type(ptr noundef %16)
  %18 = call i32 @OPENSSL_sk_push(ptr noundef %15, ptr noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %13
  store i32 0, ptr %2, align 4
  br label %31

21:                                               ; preds = %13
  br label %30

22:                                               ; preds = %1
  %23 = load ptr, ptr @save_rand_file, align 8, !tbaa !9
  call void @CRYPTO_free(ptr noundef %23, ptr noundef @.str.2, i32 noundef 115)
  %24 = call ptr @opt_arg()
  %25 = call ptr @CRYPTO_strdup(ptr noundef %24, ptr noundef @.str.2, i32 noundef 116)
  store ptr %25, ptr @save_rand_file, align 8, !tbaa !9
  %26 = load ptr, ptr @save_rand_file, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store i32 0, ptr %2, align 4
  br label %31

29:                                               ; preds = %22
  br label %30

30:                                               ; preds = %29, %21, %5, %1
  store i32 1, ptr %2, align 4
  br label %31

31:                                               ; preds = %30, %28, %20, %12
  %32 = load i32, ptr %2, align 4
  ret i32 %32
}

declare ptr @OPENSSL_sk_new_null() #0

declare i32 @OPENSSL_sk_push(ptr noundef, ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_OPENSSL_STRING_type(ptr noundef) #1

declare ptr @opt_arg() #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" }

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


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

@save_rand_file = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@randfiles = external hidden local_unnamed_addr global ptr, align 8

declare ptr @CRYPTO_strdup(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_OPENSSL_STRING_sk_type(ptr noundef) local_unnamed_addr #1

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @opt_rand(i32 noundef %0) local_unnamed_addr #2 {
  switch i32 %0, label %19 [
    i32 1502, label %14
    i32 1501, label %2
  ]

2:                                                ; preds = %1
  %3 = load ptr, ptr @randfiles, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %2
  %6 = tail call ptr @OPENSSL_sk_new_null() #3
  store ptr %6, ptr @randfiles, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %20, label %8

8:                                                ; preds = %5, %2
  %9 = phi ptr [ %6, %5 ], [ %3, %2 ]
  %10 = tail call ptr @ossl_check_OPENSSL_STRING_sk_type(ptr noundef nonnull %9)
  %11 = tail call ptr @opt_arg() #3
  %12 = tail call ptr @ossl_check_OPENSSL_STRING_type(ptr noundef %11)
  %13 = tail call i32 @OPENSSL_sk_push(ptr noundef %10, ptr noundef %12) #3
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %20, label %19

14:                                               ; preds = %1
  %15 = load ptr, ptr @save_rand_file, align 8, !tbaa !5
  tail call void @CRYPTO_free(ptr noundef %15, ptr noundef nonnull @.str.2, i32 noundef 115) #3
  %16 = tail call ptr @opt_arg() #3
  %17 = tail call ptr @CRYPTO_strdup(ptr noundef %16, ptr noundef nonnull @.str.2, i32 noundef 116) #3
  store ptr %17, ptr @save_rand_file, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %14, %8, %1
  br label %20

20:                                               ; preds = %14, %8, %5, %19
  %.0 = phi i32 [ 1, %19 ], [ 0, %5 ], [ 0, %8 ], [ 0, %14 ]
  ret i32 %.0
}

declare ptr @OPENSSL_sk_new_null() local_unnamed_addr #0

declare i32 @OPENSSL_sk_push(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_OPENSSL_STRING_type(ptr noundef) local_unnamed_addr #1

declare ptr @opt_arg() local_unnamed_addr #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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