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

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

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

13:                                               ; preds = %3
  store i32 4, ptr %7, align 4, !tbaa !9
  br label %69

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rlite, ptr %15, i32 0, i32 6
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = sub nsw i64 %17, 12
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rl_list_type, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = sext i32 %21 to i64
  %23 = sdiv i64 %18, %22
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rl_list, ptr %24, i32 0, i32 0
  store i64 %23, ptr %25, align 8, !tbaa !16
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rl_list, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !18
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call i32 @rl_list_node_create(ptr noundef %29, ptr noundef %30, ptr noundef %9)
  store i32 %31, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp ne i32 0, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %14
  br label %69

35:                                               ; preds = %14
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rl_list_node, ptr %36, i32 0, i32 1
  store i64 0, ptr %37, align 8, !tbaa !19
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rl_list_node, ptr %38, i32 0, i32 2
  store i64 0, ptr %39, align 8, !tbaa !21
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rl_list, ptr %40, i32 0, i32 1
  store i64 0, ptr %41, align 8, !tbaa !22
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rlite, ptr %42, i32 0, i32 5
  %44 = load i64, ptr %43, align 8, !tbaa !23
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_list, ptr %45, i32 0, i32 3
  store i64 %44, ptr %46, align 8, !tbaa !24
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.rl_list, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = getelementptr inbounds %struct.rl_list_type, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !25
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.rlite, ptr %53, i32 0, i32 5
  %55 = load i64, ptr %54, align 8, !tbaa !23
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call i32 @rl_write(ptr noundef %47, ptr noundef %52, i64 noundef %55, ptr noundef %56)
  store i32 %57, ptr %7, align 4, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = icmp ne i32 0, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %35
  br label %69

61:                                               ; preds = %35
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_list, ptr %62, i32 0, i32 3
  %64 = load i64, ptr %63, align 8, !tbaa !24
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rl_list, ptr %65, i32 0, i32 4
  store i64 %64, ptr %66, align 8, !tbaa !26
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %67, ptr %68, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %61, %60, %34, %13
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %69
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = call i32 @rl_list_destroy(ptr noundef %73, ptr noundef %74)
  br label %76

76:                                               ; preds = %72, %69
  %77 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %77
}

declare i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

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

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 = { 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 #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 }
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, !13, i64 48}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24}
!16 = !{!17, !13, i64 0}
!17 = !{!"rl_list", !13, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 32}
!18 = !{!17, !6, i64 16}
!19 = !{!20, !13, i64 8}
!20 = !{!"rl_list_node", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24}
!21 = !{!20, !13, i64 16}
!22 = !{!17, !13, i64 8}
!23 = !{!12, !13, i64 40}
!24 = !{!17, !13, i64 24}
!25 = !{!15, !6, i64 8}
!26 = !{!17, !13, i64 32}


; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_list_create(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %30, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add nsw i64 %8, -12
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = sext i32 %11 to i64
  %13 = sdiv i64 %9, %12
  store i64 %13, ptr %5, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %2, ptr %14, align 8, !tbaa !16
  %15 = call i32 @rl_list_node_create(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %4)
  %.not26 = icmp eq i32 %15, 0
  br i1 %.not26, label %16, label %30

16:                                               ; preds = %6
  %17 = load ptr, ptr %4, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = getelementptr inbounds i8, ptr %5, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %18, i8 0, i64 16, i1 false)
  store i64 0, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %5, i64 24
  store i64 %21, ptr %22, align 8, !tbaa !20
  %23 = load ptr, ptr %14, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %26 = call i32 @rl_write(ptr noundef nonnull %0, ptr noundef %25, i64 noundef %21, ptr noundef %17) #5
  %.not27 = icmp eq i32 %26, 0
  br i1 %.not27, label %27, label %30

27:                                               ; preds = %16
  %28 = load i64, ptr %22, align 8, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %5, i64 32
  store i64 %28, ptr %29, align 8, !tbaa !22
  store ptr %5, ptr %1, align 8, !tbaa !17
  br label %32

30:                                               ; preds = %6, %16, %3
  %.0.ph = phi i32 [ 4, %3 ], [ %26, %16 ], [ %15, %6 ]
  %31 = call i32 @rl_list_destroy(ptr noundef %0, ptr noundef %5)
  br label %32

32:                                               ; preds = %27, %30
  %.032 = phi i32 [ %.0.ph, %30 ], [ 0, %27 ]
  ret i32 %.032
}

declare i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_list_destroy(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 = { 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 #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 = { "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 allocsize(0) }
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, !7, i64 48}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !10, i64 16}
!13 = !{!"", !11, i64 0, !11, i64 8, !10, i64 16, !11, i64 24}
!14 = !{!15, !7, i64 0}
!15 = !{!"rl_list", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !7, i64 32}
!16 = !{!15, !11, i64 16}
!17 = !{!11, !11, i64 0}
!18 = !{!15, !7, i64 8}
!19 = !{!6, !7, i64 40}
!20 = !{!15, !7, i64 24}
!21 = !{!13, !11, i64 8}
!22 = !{!15, !7, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass