; 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

; 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_delete(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = call i32 @rl_read(ptr noundef %10, ptr noundef @rl_data_type_list_long, i64 noundef %11, ptr noundef @rl_list_type_long, ptr noundef %5, i32 noundef 1)
  store i32 %12, ptr %8, align 4, !tbaa !11
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = icmp ne i32 2, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %63

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i32 @rl_list_iterator_create(ptr noundef %18, ptr noundef %7, ptr noundef %19, i32 noundef 1)
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = icmp ne i32 0, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  br label %63

24:                                               ; preds = %16
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %42, %24
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call i32 @rl_list_iterator_next(ptr noundef %26, ptr noundef %5)
  store i32 %27, ptr %8, align 4, !tbaa !11
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %44

29:                                               ; preds = %25
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %42

33:                                               ; preds = %29
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = call i32 @rl_delete(ptr noundef %34, i64 noundef %36)
  store i32 %37, ptr %8, align 4, !tbaa !11
  %38 = load i32, ptr %8, align 4, !tbaa !11
  %39 = icmp ne i32 0, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  br label %63

41:                                               ; preds = %33
  br label %42

42:                                               ; preds = %41, %32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %43) #4
  br label %25, !llvm.loop !13

44:                                               ; preds = %25
  store ptr null, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = icmp ne i32 %45, 9
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  br label %63

48:                                               ; preds = %44
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 @rl_list_delete(ptr noundef %49, ptr noundef %50)
  store i32 %51, ptr %8, align 4, !tbaa !11
  %52 = load i32, ptr %8, align 4, !tbaa !11
  %53 = icmp ne i32 0, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %48
  br label %63

55:                                               ; preds = %48
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i64, ptr %4, align 8, !tbaa !9
  %58 = call i32 @rl_delete(ptr noundef %56, i64 noundef %57)
  store i32 %58, ptr %8, align 4, !tbaa !11
  %59 = load i32, ptr %8, align 4, !tbaa !11
  %60 = icmp ne i32 0, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  br label %63

62:                                               ; preds = %55
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %63

63:                                               ; preds = %62, %61, %54, %47, %40, %23, %15
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %70

66:                                               ; preds = %63
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = call i32 @rl_list_iterator_destroy(ptr noundef %67, ptr noundef %68)
  br label %70

70:                                               ; preds = %66, %63
  %71 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 %71
}

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

declare i32 @rl_list_delete(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 = distinct !{!13, !14}
!14 = !{!"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

; 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_delete(ptr noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = 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 %3, i32 noundef 1) #4
  %.not = icmp eq i32 %5, 2
  br i1 %.not, label %6, label %.loopexit

6:                                                ; preds = %2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i32 @rl_list_iterator_create(ptr noundef %0, ptr noundef nonnull %4, ptr noundef %7, i32 noundef 1) #4
  %.not24 = icmp eq i32 %8, 0
  br i1 %.not24, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %6
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @rl_list_iterator_next(ptr noundef %9, ptr noundef nonnull %3) #4
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.critedge:                                        ; preds = %.lr.ph
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = call i32 @rl_delete(ptr noundef %0, i64 noundef %13) #4
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %.lr.ph, label %.loopexit

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

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %10, %.preheader ], [ %17, %.lr.ph ]
  store ptr null, ptr %4, align 8, !tbaa !5
  %.not25 = icmp eq i32 %.lcssa, 9
  br i1 %.not25, label %19, label %.thread

19:                                               ; preds = %._crit_edge
  %20 = call i32 @rl_list_delete(ptr noundef %0, ptr noundef %7) #4
  %.not26 = icmp eq i32 %20, 0
  br i1 %.not26, label %21, label %.loopexit

21:                                               ; preds = %19
  %22 = call i32 @rl_delete(ptr noundef %0, i64 noundef %1) #4
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %21, %19, %6, %2
  %.017.ph = phi i32 [ %22, %21 ], [ %20, %19 ], [ %8, %6 ], [ %5, %2 ], [ %14, %.critedge ]
  %.pr = load ptr, ptr %4, align 8, !tbaa !5
  %.not29 = icmp eq ptr %.pr, null
  br i1 %.not29, label %.thread, label %23

23:                                               ; preds = %.loopexit
  %24 = call i32 @rl_list_iterator_destroy(ptr noundef %0, ptr noundef nonnull %.pr) #4
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %23, %.loopexit
  %.01732 = phi i32 [ %.017.ph, %23 ], [ %.017.ph, %.loopexit ], [ %.lcssa, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.01732
}

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

declare i32 @rl_list_delete(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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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