; LLVM IR from openanolis/openssl :: doc/designs/ddd (ddd-02-conn-nonblocking-threads)

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

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

; 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 ptr @new_conn(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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 i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 24) #6
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call ptr @BIO_new_ssl_connect(ptr noundef %17)
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %22) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

23:                                               ; preds = %16
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call i64 @BIO_ctrl(ptr noundef %24, i32 noundef 110, i64 noundef 0, ptr noundef %9)
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %23
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BIO_free_all(ptr noundef %28)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %29) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

30:                                               ; preds = %23
  %31 = call ptr @BIO_f_buffer()
  %32 = call ptr @BIO_new(ptr noundef %31)
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BIO_free_all(ptr noundef %36)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %37) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

38:                                               ; preds = %30
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call ptr @BIO_push(ptr noundef %39, ptr noundef %40)
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call i64 @BIO_ctrl(ptr noundef %42, i32 noundef 100, i64 noundef 0, ptr noundef %43)
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %38
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BIO_free_all(ptr noundef %47)
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %48) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

49:                                               ; preds = %38
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = call ptr @BIO_ptr_ctrl(ptr noundef %50, i32 noundef 123, i64 noundef 0)
  store ptr %51, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %57

54:                                               ; preds = %49
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BIO_free_all(ptr noundef %55)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %56) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

57:                                               ; preds = %49
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = call i32 @SSL_set1_host(ptr noundef %58, ptr noundef %59)
  %61 = icmp sle i32 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %57
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BIO_free_all(ptr noundef %63)
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %64) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

65:                                               ; preds = %57
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = call i64 @BIO_ctrl(ptr noundef %66, i32 noundef 102, i64 noundef 1, ptr noundef null)
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.app_conn_st, ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !9
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %71, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %65, %62, %54, %46, %35, %27, %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %73 = load ptr, ptr %3, align 8
  ret ptr %73
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

declare ptr @BIO_new_ssl_connect(ptr noundef) #3

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

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

declare void @BIO_free_all(ptr noundef) #3

declare ptr @BIO_new(ptr noundef) #3

declare ptr @BIO_f_buffer() #3

declare ptr @BIO_push(ptr noundef, ptr noundef) #3

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind allocsize(0,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 #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 "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 }
attributes #6 = { nounwind allocsize(0,1) }

!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 8}
!10 = !{!"app_conn_st", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!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"

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

; Function Attrs: mustprogress 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 noalias noundef ptr @new_conn(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = tail call noalias dereferenceable_or_null(24) ptr @calloc(i64 noundef 1, i64 noundef 24) #6
  %5 = icmp eq ptr %4, null
  br i1 %5, label %36, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @BIO_new_ssl_connect(ptr noundef %0) #5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  tail call void @free(ptr noundef nonnull %4) #5
  br label %36

10:                                               ; preds = %6
  %11 = call i64 @BIO_ctrl(ptr noundef nonnull %7, i32 noundef 110, i64 noundef 0, ptr noundef nonnull %3) #5
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  call void @BIO_free_all(ptr noundef nonnull %7) #5
  call void @free(ptr noundef nonnull %4) #5
  br label %36

14:                                               ; preds = %10
  %15 = call ptr @BIO_f_buffer() #5
  %16 = call ptr @BIO_new(ptr noundef %15) #5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void @BIO_free_all(ptr noundef nonnull %7) #5
  call void @free(ptr noundef nonnull %4) #5
  br label %36

19:                                               ; preds = %14
  %20 = call ptr @BIO_push(ptr noundef nonnull %7, ptr noundef nonnull %16) #5
  %21 = call i64 @BIO_ctrl(ptr noundef nonnull %7, i32 noundef 100, i64 noundef 0, ptr noundef %1) #5
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  call void @BIO_free_all(ptr noundef nonnull %7) #5
  call void @free(ptr noundef nonnull %4) #5
  br label %36

24:                                               ; preds = %19
  %25 = call ptr @BIO_ptr_ctrl(ptr noundef nonnull %7, i32 noundef 123, i64 noundef 0) #5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  call void @BIO_free_all(ptr noundef nonnull %7) #5
  call void @free(ptr noundef nonnull %4) #5
  br label %36

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i32 @SSL_set1_host(ptr noundef %29, ptr noundef nonnull %25) #5
  %31 = icmp slt i32 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  call void @BIO_free_all(ptr noundef nonnull %7) #5
  call void @free(ptr noundef nonnull %4) #5
  br label %36

33:                                               ; preds = %28
  %34 = call i64 @BIO_ctrl(ptr noundef nonnull %7, i32 noundef 102, i64 noundef 1, ptr noundef null) #5
  %35 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %7, ptr %35, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %2, %33, %32, %27, %23, %18, %13, %9
  %.0 = phi ptr [ null, %9 ], [ null, %13 ], [ null, %18 ], [ null, %23 ], [ null, %27 ], [ null, %32 ], [ %4, %33 ], [ null, %2 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

declare ptr @BIO_new_ssl_connect(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 i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare void @BIO_free_all(ptr noundef) local_unnamed_addr #3

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #3

declare ptr @BIO_f_buffer() local_unnamed_addr #3

declare ptr @BIO_push(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 #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 }
attributes #6 = { nounwind allocsize(0,1) }

!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 8}
!10 = !{!"app_conn_st", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}


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