; LLVM IR from openanolis/openssl :: doc/designs/ddd (ddd-05-mem-nonblocking)

; 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, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 32) #6
  store ptr %12, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %9, 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 %76

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call ptr @SSL_new(ptr noundef %17)
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.app_conn_st, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !9
  store ptr %18, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %16
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %24) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

25:                                               ; preds = %16
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_set_connect_state(ptr noundef %26)
  %27 = call i32 @BIO_new_bio_pair(ptr noundef %7, i64 noundef 0, ptr noundef %8, i64 noundef 0)
  %28 = icmp sle i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %25
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_free(ptr noundef %30)
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %31) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

32:                                               ; preds = %25
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void @SSL_set_bio(ptr noundef %33, ptr noundef %34, ptr noundef %35)
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call i32 @SSL_set1_host(ptr noundef %36, ptr noundef %37)
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %32
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_free(ptr noundef %41)
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %42) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

43:                                               ; preds = %32
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call i64 @SSL_ctrl(ptr noundef %44, i32 noundef 55, i64 noundef 0, ptr noundef %45)
  %47 = icmp sle i64 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %43
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_free(ptr noundef %49)
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %50) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

51:                                               ; preds = %43
  %52 = call ptr @BIO_f_ssl()
  %53 = call ptr @BIO_new(ptr noundef %52)
  store ptr %53, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_free(ptr noundef %57)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %58) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

59:                                               ; preds = %51
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = call i64 @BIO_ctrl(ptr noundef %60, i32 noundef 109, i64 noundef 1, ptr noundef %61)
  %63 = icmp sle i64 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %59
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  call void @SSL_free(ptr noundef %65)
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = call i32 @BIO_free(ptr noundef %66)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

68:                                               ; preds = %59
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.app_conn_st, ptr %70, i32 0, i32 1
  store ptr %69, ptr %71, align 8, !tbaa !12
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.app_conn_st, ptr %73, i32 0, i32 2
  store ptr %72, ptr %74, align 8, !tbaa !13
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %75, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %76

76:                                               ; preds = %68, %64, %56, %48, %40, %29, %23, %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
  %77 = load ptr, ptr %3, align 8
  ret ptr %77
}

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

declare ptr @SSL_new(ptr noundef) #3

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

declare void @SSL_set_connect_state(ptr noundef) #3

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

declare void @SSL_free(ptr noundef) #3

declare void @SSL_set_bio(ptr noundef, ptr noundef, ptr noundef) #3

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

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

declare ptr @BIO_new(ptr noundef) #3

declare ptr @BIO_f_ssl() #3

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

declare i32 @BIO_free(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 0}
!10 = !{!"app_conn_st", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 16}


; 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
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %5 = tail call noalias dereferenceable_or_null(32) ptr @calloc(i64 noundef 1, i64 noundef 32) #6
  %6 = icmp eq ptr %5, null
  br i1 %6, label %38, label %7

7:                                                ; preds = %2
  %8 = tail call ptr @SSL_new(ptr noundef %0) #5
  store ptr %8, ptr %5, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  tail call void @free(ptr noundef nonnull %5) #5
  br label %38

11:                                               ; preds = %7
  tail call void @SSL_set_connect_state(ptr noundef nonnull %8) #5
  %12 = call i32 @BIO_new_bio_pair(ptr noundef nonnull %3, i64 noundef 0, ptr noundef nonnull %4, i64 noundef 0) #5
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  call void @SSL_free(ptr noundef nonnull %8) #5
  call void @free(ptr noundef nonnull %5) #5
  br label %38

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !11
  call void @SSL_set_bio(ptr noundef nonnull %8, ptr noundef %16, ptr noundef %16) #5
  %17 = call i32 @SSL_set1_host(ptr noundef nonnull %8, ptr noundef %1) #5
  %18 = icmp slt i32 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  call void @SSL_free(ptr noundef nonnull %8) #5
  call void @free(ptr noundef nonnull %5) #5
  br label %38

20:                                               ; preds = %15
  %21 = call i64 @SSL_ctrl(ptr noundef nonnull %8, i32 noundef 55, i64 noundef 0, ptr noundef %1) #5
  %22 = icmp slt i64 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  call void @SSL_free(ptr noundef nonnull %8) #5
  call void @free(ptr noundef nonnull %5) #5
  br label %38

24:                                               ; preds = %20
  %25 = call ptr @BIO_f_ssl() #5
  %26 = call ptr @BIO_new(ptr noundef %25) #5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  call void @SSL_free(ptr noundef nonnull %8) #5
  call void @free(ptr noundef nonnull %5) #5
  br label %38

29:                                               ; preds = %24
  %30 = call i64 @BIO_ctrl(ptr noundef nonnull %26, i32 noundef 109, i64 noundef 1, ptr noundef nonnull %8) #5
  %31 = icmp slt i64 %30, 1
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  call void @SSL_free(ptr noundef nonnull %8) #5
  %33 = call i32 @BIO_free(ptr noundef nonnull %26) #5
  br label %38

34:                                               ; preds = %29
  %35 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %26, ptr %35, align 8, !tbaa !12
  %36 = load ptr, ptr %4, align 8, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %36, ptr %37, align 8, !tbaa !13
  br label %38

38:                                               ; preds = %2, %34, %32, %28, %23, %19, %14, %10
  %.0 = phi ptr [ null, %10 ], [ null, %14 ], [ null, %19 ], [ null, %23 ], [ null, %28 ], [ null, %32 ], [ %5, %34 ], [ null, %2 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  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 @SSL_new(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 @SSL_set_connect_state(ptr noundef) local_unnamed_addr #3

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

declare void @SSL_free(ptr noundef) local_unnamed_addr #3

declare void @SSL_set_bio(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #3

declare ptr @BIO_f_ssl() local_unnamed_addr #3

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

declare i32 @BIO_free(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, !7, i64 0}
!6 = !{!"app_conn_st", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}


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