; LLVM IR from libtcod/libtcod :: src/libtcod (list_c)

; 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"

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_list_begin(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_list_end(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_list_reverse(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call ptr @TCOD_list_begin(ptr noundef %6)
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call ptr @TCOD_list_end(ptr noundef %8)
  %10 = getelementptr inbounds ptr, ptr %9, i64 -1
  store ptr %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %15, %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ult ptr %12, %13
  br i1 %14, label %15, label %27

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %19, ptr %20, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %21, ptr %22, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds ptr, ptr %23, i32 1
  store ptr %24, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds ptr, ptr %25, i32 -1
  store ptr %26, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %11, !llvm.loop !9

27:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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: nounwind uwtable
declare dso_local ptr @TCOD_list_begin(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_list_end(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_list_reverse(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @TCOD_list_begin(ptr noundef %0)
  %3 = ptrtoint ptr %2 to i64
  %4 = tail call ptr @TCOD_list_end(ptr noundef %0)
  %5 = ptrtoint ptr %4 to i64
  %.01112 = getelementptr inbounds i8, ptr %4, i64 -8
  %6 = icmp ult ptr %2, %.01112
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %7 = add i64 %5, -16
  %8 = add i64 %3, 8
  %umax16 = tail call i64 @llvm.umax.i64(i64 %7, i64 %8)
  %9 = add i64 %umax16, -8
  %10 = icmp ne i64 %9, %3
  %umin17 = zext i1 %10 to i64
  %11 = add i64 %3, %umin17
  %12 = sub i64 %9, %11
  %13 = lshr i64 %12, 4
  %14 = add nuw nsw i64 %13, %umin17
  %15 = add nuw nsw i64 %14, 1
  %min.iters.check = icmp ult i64 %14, 29
  br i1 %min.iters.check, label %.lr.ph.preheader30, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %16 = add i64 %5, -16
  %17 = add i64 %3, 8
  %umax = tail call i64 @llvm.umax.i64(i64 %16, i64 %17)
  %18 = add i64 %umax, -8
  %19 = icmp ne i64 %18, %3
  %umin = zext i1 %19 to i64
  %20 = add i64 %3, %umin
  %21 = sub i64 %18, %20
  %22 = lshr i64 %21, 4
  %23 = add nuw nsw i64 %22, %umin
  %24 = shl nuw i64 %23, 3
  %25 = getelementptr i8, ptr %2, i64 %24
  %scevgep = getelementptr i8, ptr %25, i64 8
  %26 = sub nuw nsw i64 -8, %24
  %scevgep15 = getelementptr i8, ptr %4, i64 %26
  %bound0 = icmp ult ptr %2, %4
  %bound1 = icmp ult ptr %scevgep15, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader30, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %15, 4611686018427387900
  %27 = mul i64 %n.vec, -8
  %ind.end = getelementptr i8, ptr %.01112, i64 %27
  %28 = shl i64 %n.vec, 3
  %ind.end18 = getelementptr i8, ptr %2, i64 %28
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = mul i64 %index, -8
  %next.gep = getelementptr i8, ptr %.01112, i64 %offset.idx
  %offset.idx21 = shl i64 %index, 3
  %next.gep22 = getelementptr i8, ptr %2, i64 %offset.idx21
  %29 = getelementptr i8, ptr %next.gep22, i64 16
  %wide.load = load <2 x ptr>, ptr %next.gep22, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %wide.load24 = load <2 x ptr>, ptr %29, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %30 = getelementptr i8, ptr %next.gep, i64 -8
  %31 = getelementptr i8, ptr %next.gep, i64 -24
  %wide.load25 = load <2 x ptr>, ptr %30, align 8, !tbaa !5, !alias.scope !12
  %reverse = shufflevector <2 x ptr> %wide.load25, <2 x ptr> poison, <2 x i32> <i32 1, i32 0>
  %wide.load26 = load <2 x ptr>, ptr %31, align 8, !tbaa !5, !alias.scope !12
  %reverse27 = shufflevector <2 x ptr> %wide.load26, <2 x ptr> poison, <2 x i32> <i32 1, i32 0>
  store <2 x ptr> %reverse, ptr %next.gep22, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  store <2 x ptr> %reverse27, ptr %29, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %reverse28 = shufflevector <2 x ptr> %wide.load, <2 x ptr> poison, <2 x i32> <i32 1, i32 0>
  store <2 x ptr> %reverse28, ptr %30, align 8, !tbaa !5, !alias.scope !12
  %reverse29 = shufflevector <2 x ptr> %wide.load24, <2 x ptr> poison, <2 x i32> <i32 1, i32 0>
  store <2 x ptr> %reverse29, ptr %31, align 8, !tbaa !5, !alias.scope !12
  %index.next = add nuw i64 %index, 4
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !14

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

.lr.ph.preheader30:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.01114.ph = phi ptr [ %.01112, %vector.memcheck ], [ %.01112, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.013.ph = phi ptr [ %2, %vector.memcheck ], [ %2, %.lr.ph.preheader ], [ %ind.end18, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader30, %.lr.ph
  %.01114 = phi ptr [ %.011, %.lr.ph ], [ %.01114.ph, %.lr.ph.preheader30 ]
  %.013 = phi ptr [ %35, %.lr.ph ], [ %.013.ph, %.lr.ph.preheader30 ]
  %33 = load ptr, ptr %.013, align 8, !tbaa !5
  %34 = load ptr, ptr %.01114, align 8, !tbaa !5
  store ptr %34, ptr %.013, align 8, !tbaa !5
  store ptr %33, ptr %.01114, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.013, i64 8
  %.011 = getelementptr inbounds i8, ptr %.01114, i64 -8
  %36 = icmp ult ptr %35, %.011
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %1
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}


; Effective O3 passes: GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass