; LLVM IR from zhemao/libds :: listtest (main)

; 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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef 32)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef 24)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %13 = call ptr (...) @create_list()
  store ptr %13, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = call ptr (...) @create_list()
  store ptr %14, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  call void @list_add(ptr noundef %15, ptr noundef %8, i32 noundef 4)
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  call void @list_remove(ptr noundef %16, i8 noundef signext 0)
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  call void @list_add(ptr noundef %17, ptr noundef %8, i32 noundef 4)
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  call void @list_remove(ptr noundef %18, i8 noundef signext 1)
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %25, %2
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 10
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  call void @list_add(ptr noundef %23, ptr noundef %8, i32 noundef 4)
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  call void @list_add(ptr noundef %24, ptr noundef %8, i32 noundef 4)
  br label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !5
  br label %19, !llvm.loop !11

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = call ptr @list_iterator(ptr noundef %29, i8 noundef signext 0)
  store ptr %30, ptr %10, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %35, %28
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = call ptr @list_next(ptr noundef %32)
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %41

35:                                               ; preds = %31
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = call ptr @list_current(ptr noundef %36)
  store ptr %37, ptr %9, align 8, !tbaa !9
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %39)
  br label %31, !llvm.loop !13

41:                                               ; preds = %31
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  call void @destroy_list(ptr noundef %42)
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  call void @list_remove(ptr noundef %43, i8 noundef signext 0)
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  call void @list_remove(ptr noundef %44, i8 noundef signext 1)
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %45) #4
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = call ptr @list_iterator(ptr noundef %46, i8 noundef signext 1)
  store ptr %47, ptr %10, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %52, %41
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = call ptr @list_prev(ptr noundef %49)
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = call ptr @list_current(ptr noundef %53)
  store ptr %54, ptr %9, align 8, !tbaa !9
  %55 = load ptr, ptr %9, align 8, !tbaa !9
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %56)
  br label %48, !llvm.loop !14

58:                                               ; preds = %48
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  call void @destroy_list(ptr noundef %59)
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  call void @free(ptr noundef %60) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  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
  ret i32 0
}

declare i32 @printf(ptr noundef, ...) #1

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

declare ptr @create_list(...) #1

declare void @list_add(ptr noundef, ptr noundef, i32 noundef) #1

declare void @list_remove(ptr noundef, i8 noundef signext) #1

declare ptr @list_iterator(ptr noundef, i8 noundef signext) #1

declare ptr @list_next(ptr noundef) #1

declare ptr @list_current(ptr noundef) #1

declare void @destroy_list(ptr noundef) #1

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

declare ptr @list_prev(ptr noundef) #1

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef 32)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef 24)
  %6 = tail call ptr (...) @create_list() #5
  %7 = tail call ptr (...) @create_list() #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @list_add(ptr noundef %6, ptr noundef nonnull %3, i32 noundef 4) #5
  call void @list_remove(ptr noundef %6, i8 noundef signext 0) #5
  call void @list_add(ptr noundef %6, ptr noundef nonnull %3, i32 noundef 4) #5
  call void @list_remove(ptr noundef %6, i8 noundef signext 1) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %2, %8
  call void @list_add(ptr noundef %6, ptr noundef nonnull %3, i32 noundef 4) #5
  call void @list_add(ptr noundef %7, ptr noundef nonnull %3, i32 noundef 4) #5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %9, 9
  br i1 %11, label %8, label %12, !llvm.loop !9

12:                                               ; preds = %8
  %13 = call ptr @list_iterator(ptr noundef %6, i8 noundef signext 0) #5
  %14 = call ptr @list_next(ptr noundef %13) #5
  %.not21 = icmp eq ptr %14, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.lr.ph
  %15 = call ptr @list_current(ptr noundef %13) #5
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %16)
  %18 = call ptr @list_next(ptr noundef %13) #5
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %12
  call void @destroy_list(ptr noundef %6) #5
  call void @list_remove(ptr noundef %7, i8 noundef signext 0) #5
  call void @list_remove(ptr noundef %7, i8 noundef signext 1) #5
  call void @free(ptr noundef %13) #5
  %19 = call ptr @list_iterator(ptr noundef %7, i8 noundef signext 1) #5
  %20 = call ptr @list_prev(ptr noundef %19) #5
  %.not2022 = icmp eq ptr %20, null
  br i1 %.not2022, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %._crit_edge, %.lr.ph24
  %21 = call ptr @list_current(ptr noundef %19) #5
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %22)
  %24 = call ptr @list_prev(ptr noundef %19) #5
  %.not20 = icmp eq ptr %24, null
  br i1 %.not20, label %._crit_edge25, label %.lr.ph24, !llvm.loop !12

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge
  call void @destroy_list(ptr noundef %7) #5
  call void @free(ptr noundef %19) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

declare ptr @create_list(...) local_unnamed_addr #3

declare void @list_add(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @list_remove(ptr noundef, i8 noundef signext) local_unnamed_addr #3

declare ptr @list_iterator(ptr noundef, i8 noundef signext) local_unnamed_addr #3

declare ptr @list_next(ptr noundef) local_unnamed_addr #3

declare ptr @list_current(ptr noundef) local_unnamed_addr #3

declare void @destroy_list(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

declare ptr @list_prev(ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass