; LLVM IR from juliuskoskela/c-vec :: utests (test_vec_strings)

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

@.str.2 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [28 x i8], align 1
@__PRETTY_FUNCTION__.test_vec_strings = external hidden unnamed_addr constant [24 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [30 x i8], align 1

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

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

declare i32 @vec_new(ptr noundef, i64 noundef, i64 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @vec_free(ptr noundef) #0

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

declare i32 @vec_push(ptr noundef, ptr noundef) #0

declare ptr @vec_get(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @test_vec_strings() #3 {
  %1 = alloca %struct.s_vec, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %1) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %8 = call noalias ptr @strdup(ptr noundef @.str.51) #6
  store ptr %8, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %9 = call noalias ptr @strdup(ptr noundef @.str.52) #6
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = call i32 @vec_new(ptr noundef %1, i64 noundef 10, i64 noundef 8)
  %11 = call i32 @vec_push(ptr noundef %1, ptr noundef %2)
  %12 = call i32 @vec_push(ptr noundef %1, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %13 = call ptr @vec_get(ptr noundef %1, i64 noundef 0)
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %15 = call ptr @vec_get(ptr noundef %1, i64 noundef 1)
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @strcmp(ptr noundef %17, ptr noundef @.str.51) #7
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %0
  br label %22

21:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str.53, ptr noundef @.str.2, i32 noundef 302, ptr noundef @__PRETTY_FUNCTION__.test_vec_strings) #8
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i32 @strcmp(ptr noundef %23, ptr noundef @.str.52) #7
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  br label %28

27:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.54, ptr noundef @.str.2, i32 noundef 303, ptr noundef @__PRETTY_FUNCTION__.test_vec_strings) #8
  unreachable

28:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %40, %28
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.s_vec, ptr %1, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %43

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = call ptr @vec_get(ptr noundef %1, i64 noundef %36)
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  store ptr %38, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %39) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %40

40:                                               ; preds = %35
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %6, align 8, !tbaa !9
  br label %29, !llvm.loop !13

43:                                               ; preds = %34
  call void @vec_free(ptr noundef %1)
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr %1) #6
  ret void
}

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #5

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

attributes #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 = { noreturn 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 "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 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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, !10, i64 24}
!12 = !{!"s_vec", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!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.s_vec = type { ptr, i64, i64, i64 }

@.str.2 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [28 x i8], align 1
@__PRETTY_FUNCTION__.test_vec_strings = external hidden unnamed_addr constant [24 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [30 x i8], align 1

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

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

declare i32 @vec_new(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @vec_free(ptr noundef) local_unnamed_addr #2

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

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

declare ptr @vec_get(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @test_vec_strings() local_unnamed_addr #4 {
  %1 = alloca %struct.s_vec, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #8
  %4 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.51) #8
  store ptr %4, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  %5 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.52) #8
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = call i32 @vec_new(ptr noundef nonnull %1, i64 noundef 10, i64 noundef 8) #8
  %7 = call i32 @vec_push(ptr noundef nonnull %1, ptr noundef nonnull %2) #8
  %8 = call i32 @vec_push(ptr noundef nonnull %1, ptr noundef nonnull %3) #8
  %9 = call ptr @vec_get(ptr noundef nonnull %1, i64 noundef 0) #8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = call ptr @vec_get(ptr noundef nonnull %1, i64 noundef 1) #8
  %12 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) @.str.51) #9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %0
  call void @__assert_fail(ptr noundef nonnull @.str.53, ptr noundef nonnull @.str.2, i32 noundef 302, ptr noundef nonnull @__PRETTY_FUNCTION__.test_vec_strings) #10
  unreachable

15:                                               ; preds = %0
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %16, ptr noundef nonnull dereferenceable(1) @.str.52) #9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.preheader, label %21

.preheader:                                       ; preds = %15
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %.not = icmp eq i64 %20, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

21:                                               ; preds = %15
  call void @__assert_fail(ptr noundef nonnull @.str.54, ptr noundef nonnull @.str.2, i32 noundef 303, ptr noundef nonnull @__PRETTY_FUNCTION__.test_vec_strings) #10
  unreachable

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  call void @vec_free(ptr noundef nonnull %1) #8
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.55)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #8
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #8
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.05 = phi i64 [ %25, %.lr.ph ], [ 0, %.preheader ]
  %23 = call ptr @vec_get(ptr noundef nonnull %1, i64 noundef %.05) #8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  call void @free(ptr noundef %24) #8
  %25 = add nuw i64 %.05, 1
  %26 = load i64, ptr %19, align 8, !tbaa !9
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !12
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #6

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

attributes #0 = { 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 #1 = { mustprogress 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 = { noreturn 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 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 #5 = { mustprogress nofree nounwind willreturn 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 #6 = { 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { noreturn 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 24}
!10 = !{!"s_vec", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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