; LLVM IR from 0intro/wmii :: lib/libstuff/util (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.Rectangle = type { %struct.Point, %struct.Point }
%struct.Point = type { i32, i32 }
%struct.Vector_rect = type { ptr, i64, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local void @vector_rpush(ptr noundef %0, i64 %1, i64 %2) #1 {
  %4 = alloca %struct.Rectangle, align 4
  %5 = alloca ptr, align 8
  %6 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  store i64 %1, ptr %6, align 4
  %7 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  store i64 %2, ptr %7, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Vector_rect, ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Vector_rect, ptr %11, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = icmp eq i64 %10, %13
  br i1 %14, label %15, label %39

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Vector_rect, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !12
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Vector_rect, ptr %21, i32 0, i32 2
  store i64 2, ptr %22, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %20, %15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Vector_rect, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = shl i64 %26, 2
  store i64 %27, ptr %25, align 8, !tbaa !12
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Vector_rect, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Vector_rect, ptr %31, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !12
  %34 = mul i64 %33, 16
  %35 = trunc i64 %34 to i32
  %36 = call ptr @erealloc(ptr noundef %30, i32 noundef %35)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Vector_rect, ptr %37, i32 0, i32 0
  store ptr %36, ptr %38, align 8, !tbaa !13
  br label %39

39:                                               ; preds = %23, %3
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Vector_rect, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Vector_rect, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %44, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Rectangle, ptr %42, i64 %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %47, ptr align 4 %4, i64 16, i1 false), !tbaa.struct !14
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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_rect", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !6, i64 0}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !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"

%struct.Rectangle = type { %struct.Point, %struct.Point }
%struct.Point = type { i32, i32 }

declare ptr @erealloc(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vector_rpush(ptr nocapture noundef %0, i64 %1, i64 %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i64 %5, %7
  br i1 %8, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %3
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br label %15

9:                                                ; preds = %3
  %10 = icmp eq i64 %5, 0
  %spec.select = select i1 %10, i64 2, i64 %5
  %11 = shl i64 %spec.select, 2
  store i64 %11, ptr %6, align 8, !tbaa !11
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  %.tr = trunc i64 %spec.select to i32
  %13 = shl i32 %.tr, 6
  %14 = tail call ptr @erealloc(ptr noundef %12, i32 noundef %13) #2
  store ptr %14, ptr %0, align 8, !tbaa !12
  %.pre10 = load i64, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %._crit_edge, %9
  %16 = phi i64 [ %5, %._crit_edge ], [ %.pre10, %9 ]
  %17 = phi ptr [ %.pre, %._crit_edge ], [ %14, %9 ]
  %18 = add nsw i64 %16, 1
  store i64 %18, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Rectangle, ptr %17, i64 %16
  store i64 %1, ptr %19, align 4
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %19, i64 8
  store i64 %2, ptr %.sroa.2.0..sroa_idx, align 4
  ret void
}

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 = { 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 = { 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_rect", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass