; LLVM IR from seppo0010/rlite :: src (type_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_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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_llist_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 i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  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 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #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 %10, i32 noundef 1)
  store i32 %14, ptr %9, align 4, !tbaa !11
  %15 = load i32, ptr %9, align 4, !tbaa !11
  %16 = icmp ne i32 2, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  br label %59

18:                                               ; preds = %3
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %7, 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 %9, align 4, !tbaa !11
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  br label %59

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

33:                                               ; preds = %27
  br label %59

34:                                               ; preds = %27
  br label %35

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

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !9
  store i64 %41, ptr %11, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = getelementptr inbounds i16, ptr %42, i64 %43
  store i16 1, ptr %44, align 2, !tbaa !13
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i32 @rl_multi_string_pages(ptr noundef %45, i64 noundef %46, ptr noundef %47)
  store i32 %48, ptr %9, align 4, !tbaa !11
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = icmp ne i32 0, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %39
  br label %59

52:                                               ; preds = %39
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %53) #4
  br label %35, !llvm.loop !15

54:                                               ; preds = %35
  store ptr null, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !11
  %56 = icmp ne i32 %55, 9
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  br label %59

58:                                               ; preds = %54
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %58, %57, %51, %33, %26, %17
  %60 = load i32, ptr %9, align 4, !tbaa !11
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %70

62:                                               ; preds = %59
  %63 = load ptr, ptr %8, 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 %8, align 8, !tbaa !5
  %68 = call i32 @rl_list_iterator_destroy(ptr noundef %66, ptr noundef %67)
  br label %69

69:                                               ; preds = %65, %62
  br label %70

70:                                               ; preds = %69, %59
  %71 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, 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 %71
}

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

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

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

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

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

; 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_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_llist_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
  %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 %5, i32 noundef 1) #4
  %.not = icmp eq i32 %6, 2
  br i1 %.not, label %7, label %.loopexit.thread

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

10:                                               ; preds = %7
  %11 = call i32 @rl_list_iterator_create(ptr noundef %0, ptr noundef nonnull %4, ptr noundef %8, i32 noundef 1) #4
  %.not27 = icmp eq i32 %11, 0
  %.pre35 = load ptr, ptr %4, align 8
  br i1 %.not27, label %.preheader, label %.loopexit

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

.lr.ph:                                           ; preds = %.preheader, %18
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i16, ptr %2, i64 %15
  store i16 1, ptr %16, align 2, !tbaa !11
  %17 = call i32 @rl_multi_string_pages(ptr noundef %0, i64 noundef %15, ptr noundef %2) #4
  %.not29 = icmp eq i32 %17, 0
  br i1 %.not29, label %18, label %.loopexit.loopexit

18:                                               ; preds = %.lr.ph
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %19) #4
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i32 @rl_list_iterator_next(ptr noundef %20, ptr noundef nonnull %5) #4
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %18, %.preheader
  %.lcssa = phi i32 [ %12, %.preheader ], [ %21, %18 ]
  %.not28 = icmp eq i32 %.lcssa, 9
  %spec.store.select = select i1 %.not28, i32 0, i32 %.lcssa
  br label %.loopexit.thread

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre = load ptr, ptr %4, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %10
  %23 = phi ptr [ %.pre35, %10 ], [ %.pre, %.loopexit.loopexit ]
  %.0 = phi i32 [ %11, %10 ], [ %17, %.loopexit.loopexit ]
  %.not42 = icmp eq ptr %23, null
  br i1 %.not42, label %.loopexit.thread, label %24

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

.loopexit.thread:                                 ; preds = %._crit_edge, %7, %3, %24, %.loopexit
  %.038 = phi i32 [ %.0, %24 ], [ %.0, %.loopexit ], [ %spec.store.select, %._crit_edge ], [ %9, %7 ], [ %6, %3 ]
  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 %.038
}

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

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

declare i32 @rl_multi_string_pages(ptr noundef, i64 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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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