; LLVM IR from elarity/data-structure-php-clanguage :: clang.linear-list (create_element)

; 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.seq_list = type { [6 x i32], i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @create_element(i32 noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 6
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %3
  store i32 -1, ptr %4, align 4
  br label %79

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.seq_list, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp eq i32 6, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i32 -1, ptr %4, align 4
  br label %79

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %8, align 4, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.seq_list, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp eq i32 0, %28
  br i1 %29, label %30, label %41

30:                                               ; preds = %23
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.seq_list, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [6 x i32], ptr %33, i64 0, i64 %35
  store i32 %31, ptr %36, align 4, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.seq_list, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !11
  br label %78

41:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.seq_list, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = sub nsw i32 %44, 1
  store i32 %45, ptr %9, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %64, %41
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = icmp sge i32 %47, %48
  br i1 %49, label %50, label %67

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.seq_list, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [6 x i32], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr %10, align 4, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.seq_list, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [6 x i32], ptr %59, i64 0, i64 %62
  store i32 %57, ptr %63, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %64

64:                                               ; preds = %50
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %9, align 4, !tbaa !5
  br label %46, !llvm.loop !13

67:                                               ; preds = %46
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.seq_list, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [6 x i32], ptr %70, i64 0, i64 %72
  store i32 %68, ptr %73, align 4, !tbaa !5
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.seq_list, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !11
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %75, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %78

78:                                               ; preds = %67, %30
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %79

79:                                               ; preds = %78, %22, %16
  %80 = load i32, ptr %4, align 4
  ret i32 %80
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!12, !6, i64 24}
!12 = !{!"seq_list", !7, i64 0, !6, 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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 -1, 2) i32 @create_element(i32 noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %or.cond = icmp ugt i32 %0, 6
  br i1 %or.cond, label %28, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 6
  br i1 %7, label %28, label %8

8:                                                ; preds = %4
  %9 = add nsw i32 %0, -1
  %10 = icmp eq i32 %6, 0
  %.not27 = icmp slt i32 %6, %0
  %or.cond31 = or i1 %10, %.not27
  br i1 %or.cond31, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %8
  %11 = zext i32 %6 to i64
  %12 = zext nneg i32 %0 to i64
  %13 = add nuw nsw i64 %11, 1
  %smin = tail call i64 @llvm.smin.i64(i64 %11, i64 %12)
  %14 = sub nsw i64 %13, %smin
  %min.iters.check = icmp ult i64 %14, 8
  br i1 %min.iters.check, label %.lr.ph.preheader36, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %14, -8
  %ind.end = sub nsw i64 %11, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %11, %index
  %15 = add nsw i64 %offset.idx, -1
  %16 = getelementptr inbounds [6 x i32], ptr %2, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 -12
  %18 = getelementptr inbounds i8, ptr %16, i64 -28
  %wide.load = load <4 x i32>, ptr %17, align 4, !tbaa !10
  %wide.load32 = load <4 x i32>, ptr %18, align 4, !tbaa !10
  %19 = getelementptr inbounds [6 x i32], ptr %2, i64 0, i64 %offset.idx
  %20 = getelementptr inbounds i8, ptr %19, i64 -12
  %21 = getelementptr inbounds i8, ptr %19, i64 -28
  store <4 x i32> %wide.load, ptr %20, align 4, !tbaa !10
  store <4 x i32> %wide.load32, ptr %21, align 4, !tbaa !10
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %14, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader36

.lr.ph.preheader36:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %11, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader36, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader36 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %23 = getelementptr inbounds [6 x i32], ptr %2, i64 0, i64 %indvars.iv.next
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = getelementptr inbounds [6 x i32], ptr %2, i64 0, i64 %indvars.iv
  store i32 %24, ptr %25, align 4, !tbaa !10
  %.not.not = icmp sgt i64 %indvars.iv, %12
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %8
  %26 = sext i32 %9 to i64
  %27 = getelementptr inbounds [6 x i32], ptr %2, i64 0, i64 %26
  store i32 %1, ptr %27, align 4, !tbaa !10
  %storemerge.in = load i32, ptr %5, align 4, !tbaa !5
  %storemerge = add nsw i32 %storemerge.in, 1
  store i32 %storemerge, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %4, %3, %._crit_edge
  %.0 = phi i32 [ 1, %._crit_edge ], [ -1, %3 ], [ -1, %4 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

!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, !9, i64 24}
!6 = !{!"seq_list", !7, i64 0, !9, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}


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