; LLVM IR from seppo0010/rlite :: src (page_list)

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

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

declare i32 @get_4bytes(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_list_node_deserialize_long(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %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 i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i64 12, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = call i32 @rl_list_node_create(ptr noundef %15, ptr noundef %16, ptr noundef %10)
  store i32 %17, ptr %13, align 4, !tbaa !11
  %18 = load i32, ptr %13, align 4, !tbaa !11
  %19 = icmp ne i32 0, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  br label %80

21:                                               ; preds = %4
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call i32 @get_4bytes(ptr noundef %22)
  %24 = sext i32 %23 to i64
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.rl_list_node, ptr %25, i32 0, i32 0
  store i64 %24, ptr %26, align 8, !tbaa !13
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = call i32 @get_4bytes(ptr noundef %28)
  %30 = sext i32 %29 to i64
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rl_list_node, ptr %31, i32 0, i32 1
  store i64 %30, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = call i32 @get_4bytes(ptr noundef %34)
  %36 = sext i32 %35 to i64
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rl_list_node, ptr %37, i32 0, i32 2
  store i64 %36, ptr %38, align 8, !tbaa !16
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %74, %21
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.rl_list_node, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = icmp slt i64 %40, %43
  br i1 %44, label %45, label %77

45:                                               ; preds = %39
  %46 = call noalias ptr @malloc(i64 noundef 8) #5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_list_node, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds ptr, ptr %49, i64 %50
  store ptr %46, ptr %51, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_list_node, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = getelementptr inbounds ptr, ptr %54, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %60, label %59

59:                                               ; preds = %45
  store i32 4, ptr %13, align 4, !tbaa !11
  br label %80

60:                                               ; preds = %45
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  %64 = call i32 @get_4bytes(ptr noundef %63)
  %65 = sext i32 %64 to i64
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rl_list_node, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = getelementptr inbounds ptr, ptr %68, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  store i64 %65, ptr %71, align 8, !tbaa !9
  %72 = load i64, ptr %12, align 8, !tbaa !9
  %73 = add nsw i64 %72, 4
  store i64 %73, ptr %12, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %60
  %75 = load i64, ptr %11, align 8, !tbaa !9
  %76 = add nsw i64 %75, 1
  store i64 %76, ptr %11, align 8, !tbaa !9
  br label %39, !llvm.loop !18

77:                                               ; preds = %39
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %78, ptr %79, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %77, %59, %20
  %81 = load i32, ptr %13, align 4, !tbaa !11
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %93

83:                                               ; preds = %80
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %93

86:                                               ; preds = %83
  %87 = load i64, ptr %11, align 8, !tbaa !9
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.rl_list_node, ptr %88, i32 0, i32 0
  store i64 %87, ptr %89, align 8, !tbaa !13
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = call i32 @rl_list_node_destroy(ptr noundef %90, ptr noundef %91)
  br label %93

93:                                               ; preds = %86, %83, %80
  %94 = load i32, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i32 %94
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_node_create(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_node_destroy(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #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, !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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"rl_list_node", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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: 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare i32 @get_4bytes(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_list_node_deserialize_long(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = call i32 @rl_list_node_create(ptr noundef %0, ptr noundef %2, ptr noundef nonnull %5)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = call i32 @get_4bytes(ptr noundef %3) #4
  %9 = sext i32 %8 to i64
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %9, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  %12 = call i32 @get_4bytes(ptr noundef nonnull %11) #4
  %13 = sext i32 %12 to i64
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store i64 %13, ptr %15, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = call i32 @get_4bytes(ptr noundef nonnull %16) #4
  %18 = sext i32 %17 to i64
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store i64 %18, ptr %20, align 8, !tbaa !13
  %21 = load i64, ptr %19, align 8, !tbaa !9
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %7
  %.phi.trans.insert = getelementptr inbounds i8, ptr %19, i64 24
  %.pre36 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %31
  %23 = phi ptr [ %37, %31 ], [ %.pre36, %.lr.ph.preheader ]
  %.02033 = phi i64 [ %40, %31 ], [ 12, %.lr.ph.preheader ]
  %.02132 = phi i64 [ %41, %31 ], [ 0, %.lr.ph.preheader ]
  %24 = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #5
  %25 = getelementptr inbounds ptr, ptr %23, i64 %.02132
  store ptr %24, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.02132
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %.not24 = icmp eq ptr %30, null
  br i1 %.not24, label %.loopexit.thread, label %31

31:                                               ; preds = %.lr.ph
  %32 = getelementptr inbounds i8, ptr %3, i64 %.02033
  %33 = call i32 @get_4bytes(ptr noundef nonnull %32) #4
  %34 = sext i32 %33 to i64
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 24
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds ptr, ptr %37, i64 %.02132
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store i64 %34, ptr %39, align 8, !tbaa !15
  %40 = add nuw nsw i64 %.02033, 4
  %41 = add nuw nsw i64 %.02132, 1
  %42 = load i64, ptr %35, align 8, !tbaa !9
  %43 = icmp slt i64 %41, %42
  br i1 %43, label %.lr.ph, label %.thread, !llvm.loop !16

.thread:                                          ; preds = %31, %7
  %.lcssa = phi ptr [ %19, %7 ], [ %35, %31 ]
  store ptr %.lcssa, ptr %1, align 8, !tbaa !5
  br label %46

.loopexit:                                        ; preds = %4
  %.pre = load ptr, ptr %5, align 8
  %.not29 = icmp eq ptr %.pre, null
  br i1 %.not29, label %46, label %.loopexit.thread

.loopexit.thread:                                 ; preds = %.lr.ph, %.loopexit
  %.041 = phi i32 [ %6, %.loopexit ], [ 4, %.lr.ph ]
  %.140 = phi i64 [ 0, %.loopexit ], [ %.02132, %.lr.ph ]
  %44 = phi ptr [ %.pre, %.loopexit ], [ %26, %.lr.ph ]
  store i64 %.140, ptr %44, align 8, !tbaa !9
  %45 = call i32 @rl_list_node_destroy(ptr noundef %0, ptr noundef nonnull %44)
  br label %46

46:                                               ; preds = %.thread, %.loopexit.thread, %.loopexit
  %.028 = phi i32 [ 0, %.thread ], [ %.041, %.loopexit.thread ], [ %6, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.028
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_node_create(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_node_destroy(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"rl_list_node", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass