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

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

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_type, align 8

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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @rl_list_destroy(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare i32 @rl_list_iterator_create(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @rl_list_iterator_next(ptr noundef, ptr noundef) #1

declare i32 @rl_list_iterator_destroy(ptr noundef, ptr noundef) #1

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

17:                                               ; preds = %3
  br label %62

18:                                               ; preds = %3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i32 @rl_list_pages(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  store i32 %23, ptr %10, align 4, !tbaa !11
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  br label %62

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = call i32 @rl_list_iterator_create(ptr noundef %28, ptr noundef %9, ptr noundef %29, i32 noundef 1)
  store i32 %30, ptr %10, align 4, !tbaa !11
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  br label %62

34:                                               ; preds = %27
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %48, %34
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call i32 @rl_list_iterator_next(ptr noundef %36, ptr noundef %7)
  store i32 %37, ptr %10, align 4, !tbaa !11
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %50

39:                                               ; preds = %35
  %40 = load i32, ptr %11, align 4, !tbaa !11
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %48

43:                                               ; preds = %39
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds i16, ptr %44, i64 %46
  store i16 1, ptr %47, align 2, !tbaa !13
  br label %48

48:                                               ; preds = %43, %42
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %49) #4
  br label %35, !llvm.loop !15

50:                                               ; preds = %35
  store ptr null, ptr %9, align 8, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = icmp ne i32 %51, 9
  br i1 %52, label %53, label %54

53:                                               ; preds = %50
  br label %62

54:                                               ; preds = %50
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call i32 @rl_list_destroy(ptr noundef %55, ptr noundef %56)
  store i32 %57, ptr %10, align 4, !tbaa !11
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = icmp ne i32 0, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  br label %62

61:                                               ; preds = %54
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %61, %60, %53, %33, %26, %17
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %69

65:                                               ; preds = %62
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = call i32 @rl_list_iterator_destroy(ptr noundef %66, ptr noundef %67)
  br label %69

69:                                               ; preds = %65, %62
  %70 = load i32, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %70
}

declare i32 @rl_list_pages(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 }

!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, !14, i64 0}
!14 = !{!"short", !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"

%struct.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rl_list_type = type { ptr, ptr, i32, ptr }

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_type, align 8

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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @rl_list_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

declare i32 @rl_list_iterator_create(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @rl_list_iterator_next(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @rl_list_iterator_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_multi_string_pages(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  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_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_list_long, i64 noundef %1, ptr noundef nonnull @rl_list_type_long, ptr noundef nonnull %4, i32 noundef 0) #4
  %.not = icmp eq i32 %6, 2
  br i1 %.not, label %7, label %.thread

7:                                                ; preds = %3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 @rl_list_pages(ptr noundef %0, ptr noundef %8, ptr noundef %2) #4
  %.not23 = icmp eq i32 %9, 0
  br i1 %.not23, label %10, label %.thread

10:                                               ; preds = %7
  %11 = call i32 @rl_list_iterator_create(ptr noundef %0, ptr noundef nonnull %5, ptr noundef %8, i32 noundef 1) #4
  %.not24 = icmp eq i32 %11, 0
  %.pr.pre33 = load ptr, ptr %5, align 8, !tbaa !5
  br i1 %.not24, label %.preheader, label %25

.preheader:                                       ; preds = %10
  %12 = call i32 @rl_list_iterator_next(ptr noundef %.pr.pre33, ptr noundef nonnull %4) #4
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %.pre) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @rl_list_iterator_next(ptr noundef %14, ptr noundef nonnull %4) #4
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.critedge, label %._crit_edge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph.preheader, %.critedge
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i16, ptr %2, i64 %18
  store i16 1, ptr %19, align 2, !tbaa !13
  call void @free(ptr noundef %17) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @rl_list_iterator_next(ptr noundef %20, ptr noundef nonnull %4) #4
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.critedge, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.critedge, %.lr.ph.preheader, %.preheader
  %.lcssa = phi i32 [ %12, %.preheader ], [ %15, %.lr.ph.preheader ], [ %21, %.critedge ]
  store ptr null, ptr %5, align 8, !tbaa !5
  %.not25 = icmp eq i32 %.lcssa, 9
  br i1 %.not25, label %23, label %.thread

23:                                               ; preds = %._crit_edge
  %24 = call i32 @rl_list_destroy(ptr noundef %0, ptr noundef %8) #4
  %.pr.pre = load ptr, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23, %10
  %.pr = phi ptr [ %.pr.pre, %23 ], [ %.pr.pre33, %10 ]
  %.017.ph = phi i32 [ %24, %23 ], [ %11, %10 ]
  %.not27 = icmp eq ptr %.pr, null
  br i1 %.not27, label %.thread, label %26

26:                                               ; preds = %25
  %27 = call i32 @rl_list_iterator_destroy(ptr noundef %0, ptr noundef nonnull %.pr) #4
  br label %.thread

.thread:                                          ; preds = %3, %7, %._crit_edge, %26, %25
  %.01730 = phi i32 [ %.017.ph, %26 ], [ %.017.ph, %25 ], [ %.lcssa, %._crit_edge ], [ %6, %3 ], [ %9, %7 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i32 %.01730
}

declare i32 @rl_list_pages(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}


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