; LLVM IR from uNetworking/uSockets :: src (loop)

; 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.us_loop_t = type { %struct.us_internal_loop_data_t, i32, i32, i32, i32, [1024 x %struct.epoll_event], [8 x i8] }
%struct.us_internal_loop_data_t = type { ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i64 }
%struct.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }

; Function Attrs: nounwind uwtable
define dso_local void @us_internal_loop_data_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call ptr @us_create_timer(ptr noundef %9, i32 noundef 1, i32 noundef 0)
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.us_loop_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %12, i32 0, i32 0
  store ptr %10, ptr %13, align 16, !tbaa !9
  %14 = call noalias ptr @malloc(i64 noundef 524352) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.us_loop_t, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %16, i32 0, i32 5
  store ptr %14, ptr %17, align 8, !tbaa !14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.us_loop_t, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %19, i32 0, i32 6
  store ptr null, ptr %20, align 16, !tbaa !15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.us_loop_t, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %22, i32 0, i32 3
  store ptr null, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.us_loop_t, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %25, i32 0, i32 4
  store ptr null, ptr %26, align 16, !tbaa !17
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.us_loop_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %28, i32 0, i32 9
  store ptr null, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.us_loop_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %31, i32 0, i32 10
  store ptr null, ptr %32, align 16, !tbaa !19
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.us_loop_t, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %34, i32 0, i32 11
  store i32 0, ptr %35, align 8, !tbaa !20
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.us_loop_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %38, i32 0, i32 7
  store ptr %36, ptr %39, align 8, !tbaa !21
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.us_loop_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %42, i32 0, i32 8
  store ptr %40, ptr %43, align 16, !tbaa !22
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.us_loop_t, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %45, i32 0, i32 12
  store i64 0, ptr %46, align 16, !tbaa !23
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call ptr @us_internal_create_async(ptr noundef %47, i32 noundef 1, i32 noundef 0)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.us_loop_t, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %50, i32 0, i32 1
  store ptr %48, ptr %51, align 8, !tbaa !24
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.us_loop_t, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.us_internal_loop_data_t, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !24
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  call void @us_internal_async_set(ptr noundef %55, ptr noundef %56)
  ret void
}

declare ptr @us_create_timer(ptr noundef, i32 noundef, i32 noundef) #1

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

declare ptr @us_internal_create_async(ptr noundef, i32 noundef, i32 noundef) #1

declare void @us_internal_async_set(ptr noundef, ptr noundef) #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 = { "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) "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 allocsize(0) }

!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 = !{!"us_loop_t", !11, i64 0, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !7, i64 120}
!11 = !{!"us_internal_loop_data_t", !6, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !13, i64 96}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!10, !6, i64 40}
!15 = !{!10, !6, i64 48}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !6, i64 32}
!18 = !{!10, !6, i64 72}
!19 = !{!10, !6, i64 80}
!20 = !{!10, !12, i64 88}
!21 = !{!10, !6, i64 56}
!22 = !{!10, !6, i64 64}
!23 = !{!10, !13, i64 96}
!24 = !{!10, !6, i64 8}


; 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: nounwind uwtable
define dso_local void @us_internal_loop_data_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @us_create_timer(ptr noundef %0, i32 noundef 1, i32 noundef 0) #4
  store ptr %5, ptr %0, align 16, !tbaa !5
  %6 = tail call noalias dereferenceable_or_null(524352) ptr @malloc(i64 noundef 524352) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %6, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr null, ptr %8, align 16, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %9, i8 0, i64 16, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %10, i8 0, i64 20, i1 false)
  store ptr %2, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %3, ptr %12, align 16, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 0, ptr %13, align 16, !tbaa !17
  %14 = tail call ptr @us_internal_create_async(ptr noundef nonnull %0, i32 noundef 1, i32 noundef 0) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %14, ptr %15, align 8, !tbaa !18
  tail call void @us_internal_async_set(ptr noundef %14, ptr noundef %1) #4
  ret void
}

declare ptr @us_create_timer(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

declare ptr @us_internal_create_async(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @us_internal_async_set(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { "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,uninitialized") allocsize(0) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !8, i64 0}
!6 = !{!"us_loop_t", !7, i64 0, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !9, i64 120}
!7 = !{!"us_internal_loop_data_t", !8, i64 0, !8, i64 8, !11, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !11, i64 88, !12, i64 96}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long long", !9, i64 0}
!13 = !{!6, !8, i64 40}
!14 = !{!6, !8, i64 48}
!15 = !{!6, !8, i64 56}
!16 = !{!6, !8, i64 64}
!17 = !{!6, !12, i64 96}
!18 = !{!6, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass