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

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_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_llist_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 i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  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
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #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 %9, 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 %55

16:                                               ; preds = %2
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @rl_list_iterator_create(ptr noundef %18, ptr noundef %6, 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 %55

24:                                               ; preds = %16
  br label %25

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

29:                                               ; preds = %25
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr %7, align 8, !tbaa !9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = call i32 @rl_multi_string_delete(ptr noundef %32, i64 noundef %33)
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %35) #4
  br label %25, !llvm.loop !13

36:                                               ; preds = %25
  store ptr null, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !11
  %38 = icmp ne i32 %37, 9
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %55

40:                                               ; preds = %36
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @rl_list_delete(ptr noundef %41, ptr noundef %42)
  store i32 %43, ptr %8, align 4, !tbaa !11
  %44 = load i32, ptr %8, align 4, !tbaa !11
  %45 = icmp ne i32 0, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  br label %55

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

53:                                               ; preds = %47
  br label %55

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

55:                                               ; preds = %54, %53, %46, %39, %23, %15
  %56 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  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 %56
}

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

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

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

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_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

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

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

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

23:                                               ; preds = %21, %19, %._crit_edge, %6, %2
  %.0 = phi i32 [ %5, %2 ], [ %8, %6 ], [ %.lcssa, %._crit_edge ], [ %20, %19 ], [ %22, %21 ]
  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 %.0
}

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

declare i32 @rl_delete(ptr noundef, i64 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass