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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [39 x i8], align 1

; 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 i32 @rl_list_find_element(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rl_list, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.rl_list_type, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = icmp ne ptr %26, null
  br i1 %27, label %31, label %28

28:                                               ; preds = %7
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str) #4
  store i32 6, ptr %8, align 4
  br label %122

31:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  store i64 0, ptr %18, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_list, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !16
  store i64 %34, ptr %20, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !17
  br label %35

35:                                               ; preds = %110, %31
  %36 = load i64, ptr %20, align 8, !tbaa !15
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %119

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rl_list, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.rl_list_type, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load i64, ptr %20, align 8, !tbaa !15
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = call i32 @rl_read(ptr noundef %39, ptr noundef %44, i64 noundef %45, ptr noundef %46, ptr noundef %16, i32 noundef 1)
  store i32 %47, ptr %21, align 4, !tbaa !17
  %48 = load i32, ptr %21, align 4, !tbaa !17
  %49 = icmp ne i32 2, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %38
  br label %120

51:                                               ; preds = %38
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %52, ptr %17, align 8, !tbaa !5
  store i64 0, ptr %19, align 8, !tbaa !15
  br label %53

53:                                               ; preds = %107, %51
  %54 = load i64, ptr %19, align 8, !tbaa !15
  %55 = load ptr, ptr %17, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rl_list_node, ptr %55, i32 0, i32 0
  %57 = load i64, ptr %56, align 8, !tbaa !19
  %58 = icmp slt i64 %54, %57
  br i1 %58, label %59, label %110

59:                                               ; preds = %53
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.rl_list, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.rl_list_type, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !12
  %65 = load ptr, ptr %17, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rl_list_node, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load i64, ptr %19, align 8, !tbaa !15
  %69 = getelementptr inbounds ptr, ptr %67, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = call i32 %64(ptr noundef %70, ptr noundef %71)
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %106

74:                                               ; preds = %59
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %80

77:                                               ; preds = %74
  %78 = load i64, ptr %20, align 8, !tbaa !15
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  store i64 %78, ptr %79, align 8, !tbaa !15
  br label %80

80:                                               ; preds = %77, %74
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %86

83:                                               ; preds = %80
  %84 = load ptr, ptr %17, align 8, !tbaa !5
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %84, ptr %85, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %83, %80
  %87 = load ptr, ptr %12, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %97

89:                                               ; preds = %86
  %90 = load ptr, ptr %17, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.rl_list_node, ptr %90, i32 0, i32 3
  %92 = load ptr, ptr %91, align 8, !tbaa !21
  %93 = load i64, ptr %19, align 8, !tbaa !15
  %94 = getelementptr inbounds ptr, ptr %92, i64 %93
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %95, ptr %96, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %89, %86
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = icmp ne ptr %98, null
  br i1 %99, label %100, label %105

100:                                              ; preds = %97
  %101 = load i64, ptr %18, align 8, !tbaa !15
  %102 = load i64, ptr %19, align 8, !tbaa !15
  %103 = add nsw i64 %101, %102
  %104 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %103, ptr %104, align 8, !tbaa !15
  br label %105

105:                                              ; preds = %100, %97
  store i32 2, ptr %21, align 4, !tbaa !17
  br label %120

106:                                              ; preds = %59
  br label %107

107:                                              ; preds = %106
  %108 = load i64, ptr %19, align 8, !tbaa !15
  %109 = add nsw i64 %108, 1
  store i64 %109, ptr %19, align 8, !tbaa !15
  br label %53, !llvm.loop !22

110:                                              ; preds = %53
  %111 = load ptr, ptr %17, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.rl_list_node, ptr %111, i32 0, i32 0
  %113 = load i64, ptr %112, align 8, !tbaa !19
  %114 = load i64, ptr %18, align 8, !tbaa !15
  %115 = add nsw i64 %114, %113
  store i64 %115, ptr %18, align 8, !tbaa !15
  %116 = load ptr, ptr %17, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.rl_list_node, ptr %116, i32 0, i32 2
  %118 = load i64, ptr %117, align 8, !tbaa !24
  store i64 %118, ptr %20, align 8, !tbaa !15
  br label %35, !llvm.loop !25

119:                                              ; preds = %35
  store i32 3, ptr %21, align 4, !tbaa !17
  br label %120

120:                                              ; preds = %119, %105, %50
  %121 = load i32, ptr %21, align 4, !tbaa !17
  store i32 %121, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %122

122:                                              ; preds = %120, %28
  %123 = load i32, ptr %8, align 4
  ret i32 %123
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 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 "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 }

!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 16}
!10 = !{!"rl_list", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"", !6, i64 0, !6, i64 8, !14, i64 16, !6, i64 24}
!14 = !{!"int", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 24}
!17 = !{!14, !14, i64 0}
!18 = !{!13, !6, i64 8}
!19 = !{!20, !11, i64 0}
!20 = !{!"rl_list_node", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24}
!21 = !{!20, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!20, !11, i64 16}
!25 = distinct !{!25, !23}


; 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [39 x i8], align 1

; 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 i32 @rl_list_find_element(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4, ptr noundef writeonly %5, ptr noundef writeonly %6) local_unnamed_addr #1 {
  %8 = alloca ptr, align 8
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %13, label %16

13:                                               ; preds = %7
  %14 = load ptr, ptr @stderr, align 8, !tbaa !14
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str) #4
  br label %54

16:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  %17 = getelementptr inbounds i8, ptr %1, i64 24
  %.03357 = load i64, ptr %17, align 8, !tbaa !15
  %.not4358 = icmp eq i64 %.03357, 0
  br i1 %.not4358, label %.loopexit, label %.lr.ph62

.lr.ph62:                                         ; preds = %16, %._crit_edge
  %.03360 = phi i64 [ %.033, %._crit_edge ], [ %.03357, %16 ]
  %.03559 = phi i64 [ %52, %._crit_edge ], [ 0, %16 ]
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = call i32 @rl_read(ptr noundef %0, ptr noundef %20, i64 noundef %.03360, ptr noundef nonnull %1, ptr noundef nonnull %8, i32 noundef 1) #5
  %.not44 = icmp eq i32 %21, 2
  br i1 %.not44, label %22, label %.loopexit

22:                                               ; preds = %.lr.ph62
  %23 = load ptr, ptr %8, align 8, !tbaa !14
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %22
  %26 = getelementptr inbounds i8, ptr %23, i64 24
  br label %27

27:                                               ; preds = %.lr.ph, %48
  %.03456 = phi i64 [ 0, %.lr.ph ], [ %49, %48 ]
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %26, align 8, !tbaa !19
  %32 = getelementptr inbounds ptr, ptr %31, i64 %.03456
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = call i32 %30(ptr noundef %33, ptr noundef %2) #5
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %48

36:                                               ; preds = %27
  %.not45 = icmp eq ptr %6, null
  br i1 %.not45, label %38, label %37

37:                                               ; preds = %36
  store i64 %.03360, ptr %6, align 8, !tbaa !15
  br label %38

38:                                               ; preds = %37, %36
  %.not46 = icmp eq ptr %5, null
  br i1 %.not46, label %40, label %39

39:                                               ; preds = %38
  store ptr %23, ptr %5, align 8, !tbaa !14
  br label %40

40:                                               ; preds = %39, %38
  %.not47 = icmp eq ptr %3, null
  br i1 %.not47, label %45, label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %26, align 8, !tbaa !19
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.03456
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  store ptr %44, ptr %3, align 8, !tbaa !14
  br label %45

45:                                               ; preds = %41, %40
  %.not48 = icmp eq ptr %4, null
  br i1 %.not48, label %.loopexit, label %46

46:                                               ; preds = %45
  %47 = add nsw i64 %.03456, %.03559
  store i64 %47, ptr %4, align 8, !tbaa !15
  br label %.loopexit

48:                                               ; preds = %27
  %49 = add nuw nsw i64 %.03456, 1
  %50 = load i64, ptr %23, align 8, !tbaa !17
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %27, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %48, %22
  %.lcssa = phi i64 [ %24, %22 ], [ %50, %48 ]
  %52 = add nsw i64 %.lcssa, %.03559
  %53 = getelementptr inbounds i8, ptr %23, i64 16
  %.033 = load i64, ptr %53, align 8, !tbaa !15
  %.not43 = icmp eq i64 %.033, 0
  br i1 %.not43, label %.loopexit, label %.lr.ph62, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph62, %._crit_edge, %16, %45, %46
  %.0 = phi i32 [ 2, %46 ], [ 2, %45 ], [ 3, %16 ], [ %21, %.lr.ph62 ], [ 3, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  br label %54

54:                                               ; preds = %.loopexit, %13
  %.036 = phi i32 [ %.0, %.loopexit ], [ 6, %13 ]
  ret i32 %.036
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 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 = { nofree 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 #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 = { cold nounwind }
attributes #5 = { 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, !10, i64 16}
!6 = !{!"rl_list", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16, !10, i64 24}
!13 = !{!"int", !8, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!18, !7, i64 0}
!18 = !{!"rl_list_node", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!19 = !{!18, !10, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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