; LLVM IR from openanolis/openssl :: demos/bio (saccept)

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

@done = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@stdout = external global ptr, align 8
@stderr = external global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @sigsetup() #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [512 x i8], align 16
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 512, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 1, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store ptr @.str, ptr %6, align 8, !tbaa !9
  br label %21

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds ptr, ptr %18, i64 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %6, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %17, %16
  %22 = call ptr @TLS_server_method()
  %23 = call ptr @SSL_CTX_new(ptr noundef %22)
  store ptr %23, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %10, align 8, !tbaa !9
  %25 = call i32 @SSL_CTX_use_certificate_chain_file(ptr noundef %24, ptr noundef @.str.1)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  br label %83

28:                                               ; preds = %21
  %29 = load ptr, ptr %10, align 8, !tbaa !9
  %30 = call i32 @SSL_CTX_use_PrivateKey_file(ptr noundef %29, ptr noundef @.str.1, i32 noundef 1)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  br label %83

33:                                               ; preds = %28
  %34 = load ptr, ptr %10, align 8, !tbaa !9
  %35 = call i32 @SSL_CTX_check_private_key(ptr noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  br label %83

38:                                               ; preds = %33
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = call ptr @BIO_new_ssl(ptr noundef %39, i32 noundef 0)
  store ptr %40, ptr %8, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = call ptr @BIO_new_accept(ptr noundef %41)
  store ptr %42, ptr %7, align 8, !tbaa !9
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %45

44:                                               ; preds = %38
  br label %83

45:                                               ; preds = %38
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = call i64 @BIO_ctrl(ptr noundef %46, i32 noundef 118, i64 noundef 3, ptr noundef %47)
  call void @sigsetup()
  br label %49

49:                                               ; preds = %65, %45
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = call i64 @BIO_ctrl(ptr noundef %50, i32 noundef 101, i64 noundef 0, ptr noundef null)
  %52 = icmp sle i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  br label %83

54:                                               ; preds = %49
  br label %55

55:                                               ; preds = %74, %54
  %56 = load volatile i32, ptr @done, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  %58 = xor i1 %57, true
  br i1 %58, label %59, label %82

59:                                               ; preds = %55
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = getelementptr inbounds [512 x i8], ptr %11, i64 0, i64 0
  %62 = call i32 @BIO_read(ptr noundef %60, ptr noundef %61, i32 noundef 512)
  store i32 %62, ptr %13, align 4, !tbaa !5
  %63 = load i32, ptr %13, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %59
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = call ptr @BIO_pop(ptr noundef %67)
  store ptr %68, ptr %9, align 8, !tbaa !9
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  call void @BIO_free_all(ptr noundef %69)
  br label %49

70:                                               ; preds = %59
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  br label %83

74:                                               ; preds = %70
  %75 = getelementptr inbounds [512 x i8], ptr %11, i64 0, i64 0
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = load ptr, ptr @stdout, align 8, !tbaa !9
  %79 = call i64 @fwrite(ptr noundef %75, i64 noundef 1, i64 noundef %77, ptr noundef %78)
  %80 = load ptr, ptr @stdout, align 8, !tbaa !9
  %81 = call i32 @fflush(ptr noundef %80)
  br label %55, !llvm.loop !11

82:                                               ; preds = %55
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %82, %73, %53, %44, %37, %32, %27
  %84 = load i32, ptr %12, align 4, !tbaa !5
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %88

86:                                               ; preds = %83
  %87 = load ptr, ptr @stderr, align 8, !tbaa !9
  call void @ERR_print_errors_fp(ptr noundef %87)
  br label %88

88:                                               ; preds = %86, %83
  %89 = load ptr, ptr %7, align 8, !tbaa !9
  %90 = call i32 @BIO_free(ptr noundef %89)
  %91 = load i32, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 512, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret i32 %91
}

declare ptr @SSL_CTX_new(ptr noundef) #2

declare ptr @TLS_server_method() #2

declare i32 @SSL_CTX_use_certificate_chain_file(ptr noundef, ptr noundef) #2

declare i32 @SSL_CTX_use_PrivateKey_file(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @SSL_CTX_check_private_key(ptr noundef) #2

declare ptr @BIO_new_ssl(ptr noundef, i32 noundef) #2

declare ptr @BIO_new_accept(ptr noundef) #2

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) #2

declare i32 @BIO_read(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #2

declare ptr @BIO_pop(ptr noundef) #2

declare void @BIO_free_all(ptr noundef) #2

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare i32 @fflush(ptr noundef) #2

declare void @ERR_print_errors_fp(ptr noundef) #2

declare i32 @BIO_free(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

@done = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @sigsetup() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [512 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %3) #4
  %4 = icmp slt i32 %0, 2
  br i1 %4, label %8, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %2, %5
  %.0 = phi ptr [ %7, %5 ], [ @.str, %2 ]
  %9 = tail call ptr @TLS_server_method() #4
  %10 = tail call ptr @SSL_CTX_new(ptr noundef %9) #4
  %11 = tail call i32 @SSL_CTX_use_certificate_chain_file(ptr noundef %10, ptr noundef nonnull @.str.1) #4
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.loopexit33, label %12

12:                                               ; preds = %8
  %13 = tail call i32 @SSL_CTX_use_PrivateKey_file(ptr noundef %10, ptr noundef nonnull @.str.1, i32 noundef 1) #4
  %.not22 = icmp eq i32 %13, 0
  br i1 %.not22, label %.loopexit33, label %14

14:                                               ; preds = %12
  %15 = tail call i32 @SSL_CTX_check_private_key(ptr noundef %10) #4
  %.not23 = icmp eq i32 %15, 0
  br i1 %.not23, label %.loopexit33, label %16

16:                                               ; preds = %14
  %17 = tail call ptr @BIO_new_ssl(ptr noundef %10, i32 noundef 0) #4
  %18 = tail call ptr @BIO_new_accept(ptr noundef %.0) #4
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.loopexit33, label %20

20:                                               ; preds = %16
  %21 = tail call i64 @BIO_ctrl(ptr noundef nonnull %18, i32 noundef 118, i64 noundef 3, ptr noundef %17) #4
  tail call void @sigsetup()
  %22 = tail call i64 @BIO_ctrl(ptr noundef nonnull %18, i32 noundef 101, i64 noundef 0, ptr noundef null) #4
  %23 = icmp slt i64 %22, 1
  br i1 %23, label %.loopexit33, label %.preheader

.preheader:                                       ; preds = %20, %27
  %24 = load volatile i32, ptr @done, align 4, !tbaa !9
  %.not2435 = icmp eq i32 %24, 0
  br i1 %.not2435, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %34
  %25 = call i32 @BIO_read(ptr noundef nonnull %18, ptr noundef nonnull %3, i32 noundef 512) #4
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %.lr.ph
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %29 = call ptr @BIO_pop(ptr noundef nonnull %18) #4
  call void @BIO_free_all(ptr noundef %29) #4
  %30 = call i64 @BIO_ctrl(ptr noundef nonnull %18, i32 noundef 101, i64 noundef 0, ptr noundef null) #4
  %31 = icmp slt i64 %30, 1
  br i1 %31, label %.loopexit33, label %.preheader

32:                                               ; preds = %.lr.ph
  %33 = icmp slt i32 %25, 0
  br i1 %33, label %.loopexit33, label %34

34:                                               ; preds = %32
  %35 = zext nneg i32 %25 to i64
  %36 = load ptr, ptr @stdout, align 8, !tbaa !5
  %37 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 1, i64 noundef %35, ptr noundef %36)
  %38 = load ptr, ptr @stdout, align 8, !tbaa !5
  %39 = call i32 @fflush(ptr noundef %38)
  %40 = load volatile i32, ptr @done, align 4, !tbaa !9
  %.not24 = icmp eq i32 %40, 0
  br i1 %.not24, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit33:                                      ; preds = %27, %32, %20, %16, %14, %12, %8
  %.019.ph = phi ptr [ null, %8 ], [ null, %12 ], [ null, %14 ], [ null, %16 ], [ %18, %20 ], [ %18, %32 ], [ %18, %27 ]
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  call void @ERR_print_errors_fp(ptr noundef %41) #4
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %34, %.loopexit33
  %.01832 = phi i32 [ 1, %.loopexit33 ], [ 0, %34 ], [ 0, %.preheader ]
  %.01930 = phi ptr [ %.019.ph, %.loopexit33 ], [ %18, %34 ], [ %18, %.preheader ]
  %42 = call i32 @BIO_free(ptr noundef %.01930) #4
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %3) #4
  ret i32 %.01832
}

declare ptr @SSL_CTX_new(ptr noundef) local_unnamed_addr #2

declare ptr @TLS_server_method() local_unnamed_addr #2

declare i32 @SSL_CTX_use_certificate_chain_file(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @SSL_CTX_use_PrivateKey_file(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @SSL_CTX_check_private_key(ptr noundef) local_unnamed_addr #2

declare ptr @BIO_new_ssl(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @BIO_new_accept(ptr noundef) local_unnamed_addr #2

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @BIO_read(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare ptr @BIO_pop(ptr noundef) local_unnamed_addr #2

declare void @BIO_free_all(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

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

declare void @ERR_print_errors_fp(ptr noundef) local_unnamed_addr #2

declare i32 @BIO_free(ptr 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass