; LLVM IR from zhemao/libds :: vectest (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"

%struct.vector = type { ptr, ptr, i64, i64, ptr }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %7 = call ptr (...) @create_vector()
  store ptr %7, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr @.str, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr @.str.1, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %17, %0
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 15
  br i1 %10, label %11, label %20

11:                                               ; preds = %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #5
  %16 = add i64 %15, 1
  call void @vector_add(ptr noundef %12, ptr noundef %13, i64 noundef %16)
  br label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !11

20:                                               ; preds = %8
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call i64 @strlen(ptr noundef %23) #5
  %25 = add i64 %24, 1
  %26 = call i32 @vector_insert(ptr noundef %21, i64 noundef 4, ptr noundef %22, i64 noundef %25)
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef %29) #5
  %31 = add i64 %30, 1
  %32 = call i32 @vector_set(ptr noundef %27, i64 noundef 7, ptr noundef %28, i64 noundef %31)
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @vector_remove(ptr noundef %33, i64 noundef 4)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.vector, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = trunc i64 %36 to i32
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %37)
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = call ptr @subvector(ptr noundef %39, i32 noundef 1, i32 noundef 5)
  store ptr %40, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %54, %20
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.vector, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = icmp ult i64 %43, %46
  br i1 %47, label %48, label %57

48:                                               ; preds = %41
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = call ptr @vector_get(ptr noundef %49, i64 noundef %51)
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %52)
  br label %54

54:                                               ; preds = %48
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !9
  br label %41, !llvm.loop !16

57:                                               ; preds = %41
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %72, %57
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.vector, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %63, align 8, !tbaa !13
  %65 = icmp ult i64 %61, %64
  br i1 %65, label %66, label %75

66:                                               ; preds = %59
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = call ptr @vector_get(ptr noundef %67, i64 noundef %69)
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %70)
  br label %72

72:                                               ; preds = %66
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %4, align 4, !tbaa !9
  br label %59, !llvm.loop !17

75:                                               ; preds = %59
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  call void @destroy_vector(ptr noundef %76)
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  call void @destroy_vector(ptr noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

declare ptr @create_vector(...) #2

declare void @vector_add(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare i32 @vector_insert(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

declare i32 @vector_set(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

declare void @vector_remove(ptr noundef, i64 noundef) #2

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

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

declare ptr @vector_get(ptr noundef, i64 noundef) #2

declare void @destroy_vector(ptr noundef) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 16}
!14 = !{!"vector", !6, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !6, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !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 [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr (...) @create_vector() #4
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str) #5
  %3 = add i64 %2, 1
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  tail call void @vector_add(ptr noundef %1, ptr noundef nonnull @.str, i64 noundef %3) #4
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.1) #5
  %5 = add i64 %4, 1
  %6 = tail call i32 @vector_insert(ptr noundef %1, i64 noundef 4, ptr noundef nonnull @.str.1, i64 noundef %5) #4
  %7 = tail call i32 @vector_set(ptr noundef %1, i64 noundef 7, ptr noundef nonnull @.str.1, i64 noundef %5) #4
  tail call void @vector_remove(ptr noundef %1, i64 noundef 4) #4
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = trunc i64 %9 to i32
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %10)
  %12 = tail call ptr @subvector(ptr noundef %1, i32 noundef 1, i32 noundef 5) #4
  %13 = load i64, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %14 = tail call ptr @vector_get(ptr noundef nonnull %1, i64 noundef %indvars.iv) #4
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i64, ptr %8, align 8, !tbaa !5
  %17 = icmp ugt i64 %16, %indvars.iv.next
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %0
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %19 = getelementptr inbounds i8, ptr %12, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %.not33 = icmp eq i64 %20, 0
  br i1 %.not33, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %._crit_edge, %.lr.ph31
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph31 ], [ 0, %._crit_edge ]
  %21 = tail call ptr @vector_get(ptr noundef nonnull %12, i64 noundef %indvars.iv35) #4
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %21)
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %23 = load i64, ptr %19, align 8, !tbaa !5
  %24 = icmp ugt i64 %23, %indvars.iv.next36
  br i1 %24, label %.lr.ph31, label %._crit_edge32, !llvm.loop !13

._crit_edge32:                                    ; preds = %.lr.ph31, %._crit_edge
  tail call void @destroy_vector(ptr noundef %1) #4
  tail call void @destroy_vector(ptr noundef nonnull %12) #4
  ret i32 0
}

declare ptr @create_vector(...) local_unnamed_addr #1

declare void @vector_add(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

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

declare void @vector_remove(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

declare ptr @vector_get(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @destroy_vector(ptr noundef) local_unnamed_addr #1

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 16}
!6 = !{!"vector", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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