; LLVM IR from hutusi/rethink-c :: test (test_vector)

; 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, i32 }

@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.test_vector = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_vector() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %4 = call ptr (i32, ...) @vector_new(i32 noundef 2, double noundef 0.000000e+00, double noundef 1.000000e+00)
  store ptr %4, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._Vector, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp ne i32 %7, 2
  br i1 %8, label %9, label %21

9:                                                ; preds = %0
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._Vector, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %12, i32 noundef 2)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._Vector, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %18, label %19

18:                                               ; preds = %9
  br label %20

19:                                               ; preds = %9
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 12, ptr noundef @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

20:                                               ; preds = %18
  br label %21

21:                                               ; preds = %20, %0
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._Vector, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds double, ptr %24, i64 0
  %26 = load double, ptr %25, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %26, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._Vector, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds double, ptr %29, i64 1
  %31 = load double, ptr %30, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %31, double noundef 1.000000e+00, double noundef 0.000000e+00)
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  call void @vector_free(ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %33 = call ptr (i32, ...) @vector_new(i32 noundef 4, double noundef 3.000000e+00, double noundef 5.000000e+00, double noundef -3.000000e+00, double noundef 1.000000e+00)
  store ptr %33, ptr %2, align 8, !tbaa !5
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._Vector, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = icmp ne i32 %36, 4
  br i1 %37, label %38, label %50

38:                                               ; preds = %21
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._Vector, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %41, i32 noundef 4)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._Vector, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !9
  %46 = icmp eq i32 %45, 4
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  br label %49

48:                                               ; preds = %38
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 18, ptr noundef @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49, %21
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._Vector, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !12
  %54 = getelementptr inbounds double, ptr %53, i64 0
  %55 = load double, ptr %54, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %55, double noundef 3.000000e+00, double noundef 0.000000e+00)
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._Vector, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = getelementptr inbounds double, ptr %58, i64 1
  %60 = load double, ptr %59, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %60, double noundef 5.000000e+00, double noundef 0.000000e+00)
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._Vector, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  %64 = getelementptr inbounds double, ptr %63, i64 2
  %65 = load double, ptr %64, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %65, double noundef -3.000000e+00, double noundef 0.000000e+00)
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._Vector, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !12
  %69 = getelementptr inbounds double, ptr %68, i64 3
  %70 = load double, ptr %69, align 8, !tbaa !13
  call void @assert_double_eq(double noundef %70, double noundef 1.000000e+00, double noundef 0.000000e+00)
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  call void @vector_free(ptr noundef %71)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %72 = call ptr (i32, ...) @vector_new(i32 noundef 0, double noundef 3.000000e+00, double noundef 5.000000e+00)
  store ptr %72, ptr %3, align 8, !tbaa !5
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._Vector, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 8, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %89

77:                                               ; preds = %50
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._Vector, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 8, !tbaa !9
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %80, i32 noundef 0)
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._Vector, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 8, !tbaa !9
  %85 = icmp eq i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %77
  br label %88

87:                                               ; preds = %77
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.2, i32 noundef 26, ptr noundef @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88, %50
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  call void @vector_free(ptr noundef %90)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @assert_double_eq(double noundef, double noundef, double noundef) #4

declare void @vector_free(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 = { 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 = { inlinehint 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 = { nounwind }
attributes #6 = { 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 8}
!10 = !{!"_Vector", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}


; 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 [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.test_vector = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @test_vector() local_unnamed_addr #0 {
  %1 = tail call ptr (i32, ...) @vector_new(i32 noundef 2, double noundef 0.000000e+00, double noundef 1.000000e+00) #5
  %2 = getelementptr inbounds i8, ptr %1, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 2
  br i1 %.not, label %9, label %4

4:                                                ; preds = %0
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %3, i32 noundef 2)
  %6 = load i32, ptr %2, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 12, ptr noundef nonnull @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

9:                                                ; preds = %4, %0
  %10 = load ptr, ptr %1, align 8, !tbaa !11
  %11 = load double, ptr %10, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %11, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %14, double noundef 1.000000e+00, double noundef 0.000000e+00)
  tail call void @vector_free(ptr noundef nonnull %1) #5
  %15 = tail call ptr (i32, ...) @vector_new(i32 noundef 4, double noundef 3.000000e+00, double noundef 5.000000e+00, double noundef -3.000000e+00, double noundef 1.000000e+00) #5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %.not20 = icmp eq i32 %17, 4
  br i1 %.not20, label %23, label %18

18:                                               ; preds = %9
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %17, i32 noundef 4)
  %20 = load i32, ptr %16, align 8, !tbaa !5
  %21 = icmp eq i32 %20, 4
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 18, ptr noundef nonnull @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

23:                                               ; preds = %18, %9
  %24 = load ptr, ptr %15, align 8, !tbaa !11
  %25 = load double, ptr %24, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %25, double noundef 3.000000e+00, double noundef 0.000000e+00)
  %26 = load ptr, ptr %15, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load double, ptr %27, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %28, double noundef 5.000000e+00, double noundef 0.000000e+00)
  %29 = load ptr, ptr %15, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load double, ptr %30, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %31, double noundef -3.000000e+00, double noundef 0.000000e+00)
  %32 = load ptr, ptr %15, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %32, i64 24
  %34 = load double, ptr %33, align 8, !tbaa !12
  tail call void @assert_double_eq(double noundef %34, double noundef 1.000000e+00, double noundef 0.000000e+00)
  tail call void @vector_free(ptr noundef nonnull %15) #5
  %35 = tail call ptr (i32, ...) @vector_new(i32 noundef 0, double noundef 3.000000e+00, double noundef 5.000000e+00) #5
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load i32, ptr %36, align 8, !tbaa !5
  %.not21 = icmp eq i32 %37, 0
  br i1 %.not21, label %43, label %38

38:                                               ; preds = %23
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %37, i32 noundef 0)
  %40 = load i32, ptr %36, align 8, !tbaa !5
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2, i32 noundef 26, ptr noundef nonnull @__PRETTY_FUNCTION__.test_vector) #6
  unreachable

43:                                               ; preds = %38, %23
  tail call void @vector_free(ptr noundef nonnull %35) #5
  ret void
}

declare ptr @vector_new(i32 noundef, ...) local_unnamed_addr #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @assert_double_eq(double noundef, double noundef, double noundef) local_unnamed_addr #4

declare void @vector_free(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 = { 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 #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 = { inlinehint 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 = { nounwind }
attributes #6 = { 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, !10, i64 8}
!6 = !{!"_Vector", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass