; 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_iterator = type { ptr, ptr, ptr, i32, i64 }
%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 }

; 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 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #2

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

15:                                               ; preds = %4
  store i32 4, ptr %10, align 4, !tbaa !9
  br label %82

16:                                               ; preds = %4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rl_list_iterator, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rl_list_iterator, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !14
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rl_list_iterator, ptr %23, i32 0, i32 2
  store ptr null, ptr %24, align 8, !tbaa !15
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %56

27:                                               ; preds = %16
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rl_list_iterator, ptr %28, i32 0, i32 3
  store i32 -1, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rl_list, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds %struct.rl_list_type, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rl_list, ptr %36, i32 0, i32 4
  %38 = load i64, ptr %37, align 8, !tbaa !21
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call i32 @rl_read(ptr noundef %30, ptr noundef %35, i64 noundef %38, ptr noundef %39, ptr noundef %9, i32 noundef 0)
  store i32 %40, ptr %10, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp ne i32 2, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %27
  br label %82

44:                                               ; preds = %27
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rl_list_iterator, ptr %46, i32 0, i32 2
  store ptr %45, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.rl_list_iterator, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct.rl_list_node, ptr %50, i32 0, i32 0
  %52 = load i64, ptr %51, align 8, !tbaa !22
  %53 = sub nsw i64 %52, 1
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.rl_list_iterator, ptr %54, i32 0, i32 4
  store i64 %53, ptr %55, align 8, !tbaa !24
  br label %79

56:                                               ; preds = %16
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.rl_list_iterator, ptr %57, i32 0, i32 3
  store i32 1, ptr %58, align 8, !tbaa !16
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.rl_list, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = getelementptr inbounds %struct.rl_list_type, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rl_list, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !25
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = call i32 @rl_read(ptr noundef %59, ptr noundef %64, i64 noundef %67, ptr noundef %68, ptr noundef %9, i32 noundef 0)
  store i32 %69, ptr %10, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = icmp ne i32 2, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %56
  br label %82

73:                                               ; preds = %56
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rl_list_iterator, ptr %75, i32 0, i32 2
  store ptr %74, ptr %76, align 8, !tbaa !15
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rl_list_iterator, ptr %77, i32 0, i32 4
  store i64 0, ptr %78, align 8, !tbaa !24
  br label %79

79:                                               ; preds = %73, %44
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %80, ptr %81, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %79, %72, %43, %15
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %92

85:                                               ; preds = %82
  %86 = load i32, ptr %10, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %92

88:                                               ; preds = %85
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = call i32 @rl_list_iterator_destroy(ptr noundef %89, ptr noundef %90)
  br label %92

92:                                               ; preds = %88, %85, %82
  %93 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i32 %93
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_iterator_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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"rl_list_iterator", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !10, i64 24}
!17 = !{!18, !6, i64 16}
!18 = !{!"rl_list", !13, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 32}
!19 = !{!20, !6, i64 8}
!20 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24}
!21 = !{!18, !13, i64 32}
!22 = !{!23, !13, i64 0}
!23 = !{!"rl_list_node", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24}
!24 = !{!12, !13, i64 32}
!25 = !{!18, !13, i64 24}


; 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 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 3, 2) i32 @rl_list_iterator_create(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %.not38 = icmp eq ptr %6, null
  br i1 %.not38, label %.thread, label %7

7:                                                ; preds = %4
  store ptr %0, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %2, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr null, ptr %9, align 8, !tbaa !13
  %10 = icmp slt i32 %3, 0
  %11 = getelementptr inbounds i8, ptr %6, i64 24
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  br i1 %10, label %13, label %24

13:                                               ; preds = %7
  store i32 -1, ptr %11, align 8, !tbaa !14
  %14 = load ptr, ptr %12, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %2, i64 32
  %18 = load i64, ptr %17, align 8, !tbaa !19
  %19 = call i32 @rl_read(ptr noundef %0, ptr noundef %16, i64 noundef %18, ptr noundef %2, ptr noundef nonnull %5, i32 noundef 0) #4
  %.not34 = icmp eq i32 %19, 2
  br i1 %.not34, label %20, label %35

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !20
  store ptr %21, ptr %9, align 8, !tbaa !13
  %22 = load i64, ptr %21, align 8, !tbaa !21
  %23 = add nsw i64 %22, -1
  br label %33

24:                                               ; preds = %7
  store i32 1, ptr %11, align 8, !tbaa !14
  %25 = load ptr, ptr %12, align 8, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %2, i64 24
  %29 = load i64, ptr %28, align 8, !tbaa !23
  %30 = call i32 @rl_read(ptr noundef %0, ptr noundef %27, i64 noundef %29, ptr noundef %2, ptr noundef nonnull %5, i32 noundef 0) #4
  %.not = icmp eq i32 %30, 2
  br i1 %.not, label %31, label %35

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !20
  store ptr %32, ptr %9, align 8, !tbaa !13
  br label %33

33:                                               ; preds = %31, %20
  %.sink = phi i64 [ 0, %31 ], [ %23, %20 ]
  %34 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 %.sink, ptr %34, align 8, !tbaa !24
  store ptr %6, ptr %1, align 8, !tbaa !20
  br label %.thread

35:                                               ; preds = %24, %13
  %.0 = phi i32 [ %19, %13 ], [ %30, %24 ]
  %.not39 = icmp eq i32 %.0, 0
  br i1 %.not39, label %.thread, label %36

36:                                               ; preds = %35
  %37 = call i32 @rl_list_iterator_destroy(ptr noundef %0, ptr noundef nonnull %6)
  br label %.thread

.thread:                                          ; preds = %33, %4, %36, %35
  %.037 = phi i32 [ %.0, %36 ], [ 0, %35 ], [ 4, %4 ], [ 0, %33 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.037
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_iterator_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, !7, i64 0}
!6 = !{!"rl_list_iterator", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !10, i64 24}
!15 = !{!16, !7, i64 16}
!16 = !{!"rl_list", !11, i64 0, !11, i64 8, !7, i64 16, !11, i64 24, !11, i64 32}
!17 = !{!18, !7, i64 8}
!18 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24}
!19 = !{!16, !11, i64 32}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !11, i64 0}
!22 = !{!"rl_list_node", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24}
!23 = !{!16, !11, i64 24}
!24 = !{!6, !11, i64 32}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass