; LLVM IR from shixiongfei/nio4c :: nio4c_selector (nio_selector)

; 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.niosocket_s = type { i32 }
%struct.nioselector_s = type { ptr, %struct.niohtable_s, %struct.niosocket_s, %struct.niosocket_s, i32 }
%struct.niohtable_s = type { ptr, i32, i32, i32 }
%struct.niopoll_s = type { ptr, ptr, ptr, ptr, ptr, ptr }

@nio_pollcreate = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @nio_selector() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca [2 x %struct.niosocket_s], align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = call ptr @nio_realloc(ptr noundef null, i64 noundef 48)
  store ptr %5, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %0
  store ptr null, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %85

9:                                                ; preds = %0
  %10 = getelementptr inbounds [2 x %struct.niosocket_s], ptr %3, i64 0, i64 0
  %11 = call i32 @nio_pipe(ptr noundef %10)
  %12 = icmp ne i32 0, %11
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call ptr @nio_realloc(ptr noundef %14, i64 noundef 0)
  store ptr null, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %85

16:                                               ; preds = %9
  %17 = load ptr, ptr @nio_pollcreate, align 8, !tbaa !5
  %18 = call ptr %17()
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.nioselector_s, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.nioselector_s, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds [2 x %struct.niosocket_s], ptr %3, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 4 %23, i64 4, i1 false), !tbaa.struct !14
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.nioselector_s, ptr %24, i32 0, i32 3
  %26 = getelementptr inbounds [2 x %struct.niosocket_s], ptr %3, i64 0, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 4 %26, i64 4, i1 false), !tbaa.struct !14
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.nioselector_s, ptr %27, i32 0, i32 4
  store i32 0, ptr %28, align 8, !tbaa !16
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.nioselector_s, ptr %29, i32 0, i32 1
  %31 = call i32 @niohtable_create(ptr noundef %30)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.nioselector_s, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.niopoll_s, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.nioselector_s, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.nioselector_s, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds %struct.niosocket_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !19
  %44 = call i32 %36(ptr noundef %39, i32 noundef %43, ptr noundef null)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.nioselector_s, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.niopoll_s, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.nioselector_s, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.nioselector_s, ptr %53, i32 0, i32 3
  %55 = getelementptr inbounds %struct.niosocket_s, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = call i32 %49(ptr noundef %52, i32 noundef %56, ptr noundef null)
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.nioselector_s, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.niopoll_s, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.nioselector_s, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.nioselector_s, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds %struct.niosocket_s, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !19
  %70 = call i32 %62(ptr noundef %65, i32 noundef %69, i32 noundef 1, i32 noundef 0, ptr noundef null)
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.nioselector_s, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.niopoll_s, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !21
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.nioselector_s, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.nioselector_s, ptr %79, i32 0, i32 3
  %81 = getelementptr inbounds %struct.niosocket_s, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 4, !tbaa !20
  %83 = call i32 %75(ptr noundef %78, i32 noundef %82, i32 noundef 1, i32 noundef 0, ptr noundef null)
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %84, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %85

85:                                               ; preds = %16, %13, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %86 = load ptr, ptr %1, align 8
  ret ptr %86
}

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

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

declare i32 @nio_pipe(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i32 @niohtable_create(ptr noundef) #2

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"nioselector_s", !6, i64 0, !11, i64 8, !13, i64 32, !13, i64 36, !12, i64 40}
!11 = !{!"niohtable_s", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"niosocket_s", !12, i64 0}
!14 = !{i64 0, i64 4, !15}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 40}
!17 = !{!18, !6, i64 16}
!18 = !{!"niopoll_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!19 = !{!10, !12, i64 32}
!20 = !{!10, !12, i64 36}
!21 = !{!18, !6, i64 32}


; 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.niosocket_s = type { i32 }

@nio_pollcreate = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @nio_selector() local_unnamed_addr #0 {
  %1 = alloca [2 x %struct.niosocket_s], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %2 = tail call ptr @nio_realloc(ptr noundef null, i64 noundef 48) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %36, label %3

3:                                                ; preds = %0
  %4 = call i32 @nio_pipe(ptr noundef nonnull %1) #3
  %.not22 = icmp eq i32 %4, 0
  br i1 %.not22, label %7, label %5

5:                                                ; preds = %3
  %6 = call ptr @nio_realloc(ptr noundef nonnull %2, i64 noundef 0) #3
  br label %36

7:                                                ; preds = %3
  %8 = load ptr, ptr @nio_pollcreate, align 8, !tbaa !5
  %9 = call ptr %8() #3
  store ptr %9, ptr %2, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  %11 = getelementptr inbounds i8, ptr %2, i64 36
  %12 = load <2 x i32>, ptr %1, align 8, !tbaa !14
  store <2 x i32> %12, ptr %10, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 0, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  %15 = call i32 @niohtable_create(ptr noundef nonnull %14) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load i32, ptr %10, align 8, !tbaa !18
  %20 = call i32 %18(ptr noundef %16, i32 noundef %19, ptr noundef null) #3
  %21 = load ptr, ptr %2, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load i32, ptr %11, align 4, !tbaa !19
  %25 = call i32 %23(ptr noundef %21, i32 noundef %24, ptr noundef null) #3
  %26 = load ptr, ptr %2, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = load i32, ptr %10, align 8, !tbaa !18
  %30 = call i32 %28(ptr noundef %26, i32 noundef %29, i32 noundef 1, i32 noundef 0, ptr noundef null) #3
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 32
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %34 = load i32, ptr %11, align 4, !tbaa !19
  %35 = call i32 %33(ptr noundef %31, i32 noundef %34, i32 noundef 1, i32 noundef 0, ptr noundef null) #3
  br label %36

36:                                               ; preds = %0, %7, %5
  %.0 = phi ptr [ null, %5 ], [ %2, %7 ], [ null, %0 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret ptr %.0
}

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

declare ptr @nio_realloc(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @nio_pipe(ptr noundef) local_unnamed_addr #2

declare i32 @niohtable_create(ptr noundef) local_unnamed_addr #2

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

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 = { 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, !6, i64 0}
!10 = !{!"nioselector_s", !6, i64 0, !11, i64 8, !13, i64 32, !13, i64 36, !12, i64 40}
!11 = !{!"niohtable_s", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"niosocket_s", !12, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 40}
!16 = !{!17, !6, i64 16}
!17 = !{!"niopoll_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!10, !12, i64 32}
!19 = !{!10, !12, i64 36}
!20 = !{!17, !6, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass