; LLVM IR from godzilla-foundation/godzilla-community :: core/deps/nanomsg-1.1.5/src/aio (timerset)

; 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.nn_timerset_hndl = type { %struct.nn_list_item, i64 }
%struct.nn_list_item = type { ptr, ptr }
%struct.nn_timerset = type { %struct.nn_list }
%struct.nn_list = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @nn_timerset_add(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = call i64 @nn_clock_ms()
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = add i64 %10, %12
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.nn_timerset_hndl, ptr %14, i32 0, i32 1
  store i64 %13, ptr %15, align 8, !tbaa !11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.nn_timerset, ptr %16, i32 0, i32 0
  %18 = call ptr @nn_list_begin(ptr noundef %17)
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %43, %3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.nn_timerset, ptr %21, i32 0, i32 0
  %23 = call ptr @nn_list_end(ptr noundef %22)
  %24 = icmp ne ptr %20, %23
  br i1 %24, label %25, label %48

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 0
  br label %32

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31, %28
  %33 = phi ptr [ %30, %28 ], [ null, %31 ]
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.nn_timerset_hndl, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.nn_timerset_hndl, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !11
  %40 = icmp ult i64 %36, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %32
  br label %48

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.nn_timerset, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call ptr @nn_list_next(ptr noundef %45, ptr noundef %46)
  store ptr %47, ptr %7, align 8, !tbaa !5
  br label %19, !llvm.loop !15

48:                                               ; preds = %41, %19
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.nn_timerset, ptr %49, i32 0, i32 0
  %51 = call ptr @nn_list_begin(ptr noundef %50)
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = icmp eq ptr %51, %52
  %54 = zext i1 %53 to i64
  %55 = select i1 %53, i32 1, i32 0
  store i32 %55, ptr %9, align 4, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.nn_timerset, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.nn_timerset_hndl, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  call void @nn_list_insert(ptr noundef %57, ptr noundef %59, ptr noundef %60)
  %61 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret i32 %61
}

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

declare i64 @nn_clock_ms() #2

declare ptr @nn_list_begin(ptr noundef) #2

declare ptr @nn_list_end(ptr noundef) #2

declare ptr @nn_list_next(ptr noundef, ptr noundef) #2

declare void @nn_list_insert(ptr noundef, ptr noundef, 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 = { 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 = !{!12, !14, i64 16}
!12 = !{!"nn_timerset_hndl", !13, i64 0, !14, i64 16}
!13 = !{!"nn_list_item", !6, i64 0, !6, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nn_timerset_add(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @nn_clock_ms() #2
  %5 = sext i32 %1 to i64
  %6 = add i64 %4, %5
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store i64 %6, ptr %7, align 8, !tbaa !5
  %8 = tail call ptr @nn_list_begin(ptr noundef %0) #2
  %9 = tail call ptr @nn_list_end(ptr noundef %0) #2
  %.not16 = icmp eq ptr %8, %9
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %14
  %.017 = phi ptr [ %15, %14 ], [ %8, %3 ]
  %10 = load i64, ptr %7, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.017, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %._crit_edge, label %14

14:                                               ; preds = %.lr.ph
  %15 = tail call ptr @nn_list_next(ptr noundef %0, ptr noundef nonnull %.017) #2
  %16 = tail call ptr @nn_list_end(ptr noundef %0) #2
  %.not = icmp eq ptr %15, %16
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %14, %.lr.ph, %3
  %.0.lcssa = phi ptr [ %8, %3 ], [ %.017, %.lr.ph ], [ %15, %14 ]
  %17 = tail call ptr @nn_list_begin(ptr noundef %0) #2
  %18 = icmp eq ptr %17, %.0.lcssa
  %19 = zext i1 %18 to i32
  tail call void @nn_list_insert(ptr noundef %0, ptr noundef nonnull %2, ptr noundef %.0.lcssa) #2
  ret i32 %19
}

declare i64 @nn_clock_ms() local_unnamed_addr #1

declare ptr @nn_list_begin(ptr noundef) local_unnamed_addr #1

declare ptr @nn_list_end(ptr noundef) local_unnamed_addr #1

declare ptr @nn_list_next(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @nn_list_insert(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 }

!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, !11, i64 16}
!6 = !{!"nn_timerset_hndl", !7, i64 0, !11, i64 16}
!7 = !{!"nn_list_item", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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