; 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_list = type { i64, i64, ptr, i64, i64 }

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

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_llist_get_objects(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 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 uwtable
define dso_local i32 @rl_lrange_iterator(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  store i64 0, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = call i32 @rl_llist_get_objects(ptr noundef %20, ptr noundef %21, i64 noundef %22, ptr noundef null, ptr noundef %15, i32 noundef 0, i32 noundef 0)
  store i32 %23, ptr %17, align 4, !tbaa !11
  %24 = load i32, ptr %17, align 4, !tbaa !11
  %25 = icmp ne i32 0, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %7
  br label %90

27:                                               ; preds = %7
  %28 = load ptr, ptr %15, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rl_list, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !13
  store i64 %30, ptr %18, align 8, !tbaa !9
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %27
  %34 = load i64, ptr %18, align 8, !tbaa !9
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = add nsw i64 %35, %34
  store i64 %36, ptr %11, align 8, !tbaa !9
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %39, %33
  br label %41

41:                                               ; preds = %40, %27
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = icmp slt i64 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i64, ptr %18, align 8, !tbaa !9
  %46 = load i64, ptr %12, align 8, !tbaa !9
  %47 = add nsw i64 %46, %45
  store i64 %47, ptr %12, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %44, %41
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = load i64, ptr %18, align 8, !tbaa !9
  %51 = icmp sge i64 %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load i64, ptr %18, align 8, !tbaa !9
  %54 = sub nsw i64 %53, 1
  store i64 %54, ptr %12, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %52, %48
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = load i64, ptr %12, align 8, !tbaa !9
  %58 = icmp sgt i64 %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  store i32 0, ptr %17, align 4, !tbaa !11
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %60, align 8, !tbaa !9
  br label %90

61:                                               ; preds = %55
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = sub nsw i64 %62, %63
  %65 = add nsw i64 %64, 1
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %15, align 8, !tbaa !5
  %69 = call i32 @rl_list_iterator_create(ptr noundef %67, ptr noundef %16, ptr noundef %68, i32 noundef 1)
  store i32 %69, ptr %17, align 4, !tbaa !11
  %70 = load i32, ptr %17, align 4, !tbaa !11
  %71 = icmp ne i32 0, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %61
  br label %90

73:                                               ; preds = %61
  br label %74

74:                                               ; preds = %84, %73
  %75 = load i64, ptr %19, align 8, !tbaa !9
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = icmp slt i64 %75, %76
  br i1 %77, label %78, label %82

78:                                               ; preds = %74
  %79 = load ptr, ptr %16, align 8, !tbaa !5
  %80 = call i32 @rl_list_iterator_next(ptr noundef %79, ptr noundef null)
  %81 = icmp eq i32 %80, 0
  br label %82

82:                                               ; preds = %78, %74
  %83 = phi i1 [ false, %74 ], [ %81, %78 ]
  br i1 %83, label %84, label %87

84:                                               ; preds = %82
  %85 = load i64, ptr %19, align 8, !tbaa !9
  %86 = add nsw i64 %85, 1
  store i64 %86, ptr %19, align 8, !tbaa !9
  br label %74, !llvm.loop !15

87:                                               ; preds = %82
  %88 = load ptr, ptr %16, align 8, !tbaa !5
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %88, ptr %89, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %87, %72, %59, %26
  %91 = load i32, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret i32 %91
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 8}
!14 = !{!"rl_list", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 32}
!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"

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

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_llist_get_objects(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 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: nounwind uwtable
define dso_local i32 @rl_lrange_iterator(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr nocapture noundef writeonly %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #1 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %10 = call i32 @rl_llist_get_objects(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef null, ptr noundef nonnull %8, i32 noundef 0, i32 noundef 0)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %30

11:                                               ; preds = %7
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp slt i64 %3, 0
  %16 = add nsw i64 %14, %3
  %spec.store.select = call i64 @llvm.smax.i64(i64 %16, i64 0)
  %.026 = select i1 %15, i64 %spec.store.select, i64 %3
  %17 = icmp slt i64 %4, 0
  %18 = select i1 %17, i64 %14, i64 0
  %.028 = add nsw i64 %18, %4
  %.not36 = icmp slt i64 %.028, %14
  %19 = add nsw i64 %14, -1
  %.1 = select i1 %.not36, i64 %.028, i64 %19
  %20 = icmp sgt i64 %.026, %.1
  br i1 %20, label %21, label %22

21:                                               ; preds = %11
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %30

22:                                               ; preds = %11
  %reass.sub = sub nsw i64 %.1, %.026
  %23 = add i64 %reass.sub, 1
  store i64 %23, ptr %5, align 8, !tbaa !12
  %24 = call i32 @rl_list_iterator_create(ptr noundef %0, ptr noundef nonnull %9, ptr noundef nonnull %12, i32 noundef 1) #4
  %.not37 = icmp eq i32 %24, 0
  br i1 %.not37, label %.preheader, label %30

.preheader:                                       ; preds = %22
  %.not40 = icmp eq i64 %.026, 0
  br i1 %.not40, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.038 = phi i64 [ %28, %.lr.ph ], [ 0, %.preheader ]
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = call i32 @rl_list_iterator_next(ptr noundef %25, ptr noundef null) #4
  %27 = icmp ne i32 %26, 0
  %28 = add nuw nsw i64 %.038, 1
  %exitcond.not = icmp eq i64 %28, %.026
  %or.cond = select i1 %27, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %.critedge, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %.preheader
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %29, ptr %6, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %22, %7, %.critedge, %21
  %.027 = phi i32 [ %10, %7 ], [ 0, %21 ], [ %24, %22 ], [ 0, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  ret i32 %.027
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 8}
!10 = !{!"rl_list", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass