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

; 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.TCOD_Pathfinder = type { i8, [4 x i64], i8, i8, i8, %struct.TCOD_ArrayData, %struct.TCOD_BasicGraph2D, %struct.TCOD_ArrayData, %struct.TCOD_Heap }
%struct.TCOD_BasicGraph2D = type { %struct.TCOD_ArrayData, i32, i32 }
%struct.TCOD_ArrayData = type { i8, i32, [5 x i64], [5 x i64], ptr }
%struct.TCOD_Heap = type { ptr, i32, i32, i64, i64, i64, i32 }

; 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
define dso_local void @TCOD_pf_set_traversal_pointer(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %4
  br label %85

13:                                               ; preds = %4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %14, i32 0, i32 0
  %16 = load i8, ptr %15, align 8, !tbaa !11
  %17 = sext i8 %16 to i32
  %18 = add nsw i32 %17, 1
  %19 = trunc i32 %18 to i8
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %20, i32 0, i32 7
  %22 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %21, i32 0, i32 0
  store i8 %19, ptr %22, align 8, !tbaa !18
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %24, i32 0, i32 7
  %26 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %25, i32 0, i32 1
  store i32 %23, ptr %26, align 4, !tbaa !19
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %28, i32 0, i32 7
  %30 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %29, i32 0, i32 4
  store ptr %27, ptr %30, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %82, %13
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %33, i32 0, i32 7
  %35 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 8, !tbaa !18
  %37 = sext i8 %36 to i32
  %38 = icmp slt i32 %32, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %85

40:                                               ; preds = %31
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %41, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !21
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %46, i32 0, i32 7
  %48 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [5 x i64], ptr %48, i64 0, i64 %50
  store i64 %45, ptr %51, align 8, !tbaa !21
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %54, align 8, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %52, %56
  br i1 %57, label %58, label %69

58:                                               ; preds = %40
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %59, i32 0, i32 0
  %61 = load i8, ptr %60, align 8, !tbaa !11
  %62 = sext i8 %61 to i64
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %63, i32 0, i32 7
  %65 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [5 x i64], ptr %65, i64 0, i64 %67
  store i64 %62, ptr %68, align 8, !tbaa !21
  br label %81

69:                                               ; preds = %40
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i64, ptr %70, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !21
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %75, i32 0, i32 7
  %77 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [5 x i64], ptr %77, i64 0, i64 %79
  store i64 %74, ptr %80, align 8, !tbaa !21
  br label %81

81:                                               ; preds = %69, %58
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !9
  br label %31, !llvm.loop !22

85:                                               ; preds = %39, %12
  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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"TCOD_Pathfinder", !7, i64 0, !7, i64 8, !13, i64 40, !13, i64 41, !13, i64 42, !14, i64 48, !15, i64 144, !14, i64 248, !16, i64 344}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"TCOD_ArrayData", !7, i64 0, !10, i64 4, !7, i64 8, !7, i64 48, !6, i64 88}
!15 = !{!"TCOD_BasicGraph2D", !14, i64 0, !10, i64 96, !10, i64 100}
!16 = !{!"TCOD_Heap", !6, i64 0, !10, i64 8, !10, i64 12, !17, i64 16, !17, i64 24, !17, i64 32, !10, i64 40}
!17 = !{!"long", !7, i64 0}
!18 = !{!12, !7, i64 248}
!19 = !{!12, !10, i64 252}
!20 = !{!12, !6, i64 336}
!21 = !{!17, !17, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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 void @TCOD_pf_set_traversal_pointer(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %4
  %6 = load i8, ptr %0, align 8, !tbaa !5
  %7 = add i8 %6, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 248
  store i8 %7, ptr %8, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 252
  store i32 %2, ptr %9, align 4, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 336
  store ptr %1, ptr %10, align 8, !tbaa !18
  %11 = icmp ult i8 %6, 127
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %5
  %12 = zext i8 %7 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 296
  %14 = getelementptr inbounds i8, ptr %0, i64 256
  %15 = zext nneg i8 %6 to i64
  %16 = zext nneg i8 %6 to i64
  %17 = getelementptr inbounds [5 x i64], ptr %14, i64 0, i64 %16
  %xtraiter = and i64 %12, 1
  %18 = icmp eq i8 %6, 0
  br i1 %18, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %12, 254
  br label %19

19:                                               ; preds = %35, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %35 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %35 ]
  %20 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv
  store i64 %21, ptr %22, align 8, !tbaa !19
  %23 = icmp eq i64 %indvars.iv, %16
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  store i64 %15, ptr %17, align 8, !tbaa !19
  br label %27

25:                                               ; preds = %19
  %26 = getelementptr inbounds [5 x i64], ptr %14, i64 0, i64 %indvars.iv
  store i64 %21, ptr %26, align 8, !tbaa !19
  br label %27

27:                                               ; preds = %24, %25
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv.next
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %30 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv.next
  store i64 %29, ptr %30, align 8, !tbaa !19
  %31 = icmp eq i64 %indvars.iv.next, %16
  br i1 %31, label %34, label %32

32:                                               ; preds = %27
  %33 = getelementptr inbounds [5 x i64], ptr %14, i64 0, i64 %indvars.iv.next
  store i64 %29, ptr %33, align 8, !tbaa !19
  br label %35

34:                                               ; preds = %27
  store i64 %15, ptr %17, align 8, !tbaa !19
  br label %35

35:                                               ; preds = %34, %32
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %19, !llvm.loop !20

.loopexit.loopexit.unr-lcssa:                     ; preds = %35, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %35 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %36 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv.unr
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv.unr
  store i64 %37, ptr %38, align 8, !tbaa !19
  %39 = icmp eq i64 %indvars.iv.unr, %16
  br i1 %39, label %42, label %40

40:                                               ; preds = %.epil.preheader
  %41 = getelementptr inbounds [5 x i64], ptr %14, i64 0, i64 %indvars.iv.unr
  store i64 %37, ptr %41, align 8, !tbaa !19
  br label %.loopexit

42:                                               ; preds = %.epil.preheader
  store i64 %15, ptr %17, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %42, %40, %5, %4
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"TCOD_Pathfinder", !7, i64 0, !7, i64 8, !9, i64 40, !9, i64 41, !9, i64 42, !10, i64 48, !13, i64 144, !10, i64 248, !14, i64 344}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"_Bool", !7, i64 0}
!10 = !{!"TCOD_ArrayData", !7, i64 0, !11, i64 4, !7, i64 8, !7, i64 48, !12, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"TCOD_BasicGraph2D", !10, i64 0, !11, i64 96, !11, i64 100}
!14 = !{!"TCOD_Heap", !12, i64 0, !11, i64 8, !11, i64 12, !15, i64 16, !15, i64 24, !15, i64 32, !11, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!6, !7, i64 248}
!17 = !{!6, !11, i64 252}
!18 = !{!6, !12, i64 336}
!19 = !{!15, !15, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass