; 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_graph2d_pointer(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %6
  br label %81

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

35:                                               ; preds = %69, %17
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %37, i32 0, i32 0
  %39 = load i8, ptr %38, align 8, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = icmp slt i32 %36, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %72

43:                                               ; preds = %35
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !21
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %49, i32 0, i32 6
  %51 = getelementptr inbounds %struct.TCOD_BasicGraph2D, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [5 x i64], ptr %52, i64 0, i64 %54
  store i64 %48, ptr %55, align 8, !tbaa !21
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [4 x i64], ptr %57, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !21
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %62, i32 0, i32 6
  %64 = getelementptr inbounds %struct.TCOD_BasicGraph2D, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.TCOD_ArrayData, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [5 x i64], ptr %65, i64 0, i64 %67
  store i64 %61, ptr %68, align 8, !tbaa !21
  br label %69

69:                                               ; preds = %43
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %13, align 4, !tbaa !9
  br label %35, !llvm.loop !22

72:                                               ; preds = %42
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %74, i32 0, i32 6
  %76 = getelementptr inbounds %struct.TCOD_BasicGraph2D, ptr %75, i32 0, i32 1
  store i32 %73, ptr %76, align 8, !tbaa !24
  %77 = load i32, ptr %12, align 4, !tbaa !9
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %78, i32 0, i32 6
  %80 = getelementptr inbounds %struct.TCOD_BasicGraph2D, ptr %79, i32 0, i32 2
  store i32 %77, ptr %80, align 4, !tbaa !25
  br label %81

81:                                               ; preds = %72, %16
  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 144}
!19 = !{!12, !10, i64 148}
!20 = !{!12, !6, i64 232}
!21 = !{!17, !17, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !10, i64 240}
!25 = !{!12, !10, i64 244}


; 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_graph2d_pointer(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %38, label %7

7:                                                ; preds = %6
  %8 = load i8, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 144
  store i8 %8, ptr %9, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %0, i64 148
  store i32 %2, ptr %10, align 4, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %0, i64 232
  store ptr %1, ptr %11, align 8, !tbaa !18
  %12 = icmp sgt i8 %8, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7
  %wide.trip.count = zext nneg i8 %8 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 192
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = getelementptr inbounds i8, ptr %0, i64 152
  %xtraiter = and i64 %wide.trip.count, 1
  %16 = icmp eq i8 %8, 1
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 126
  br label %25

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

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %17 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv.unr
  %18 = load i64, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv.unr
  store i64 %18, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds [4 x i64], ptr %14, i64 0, i64 %indvars.iv.unr
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds [5 x i64], ptr %15, i64 0, i64 %indvars.iv.unr
  store i64 %21, ptr %22, align 8, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %7
  %23 = getelementptr inbounds i8, ptr %0, i64 240
  store i32 %4, ptr %23, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %0, i64 244
  store i32 %5, ptr %24, align 4, !tbaa !21
  br label %38

25:                                               ; preds = %25, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %25 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %25 ]
  %26 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  %27 = load i64, ptr %26, align 8, !tbaa !19
  %28 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv
  store i64 %27, ptr %28, align 8, !tbaa !19
  %29 = getelementptr inbounds [4 x i64], ptr %14, i64 0, i64 %indvars.iv
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds [5 x i64], ptr %15, i64 0, i64 %indvars.iv
  store i64 %30, ptr %31, align 8, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv.next
  %33 = load i64, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds [5 x i64], ptr %13, i64 0, i64 %indvars.iv.next
  store i64 %33, ptr %34, align 8, !tbaa !19
  %35 = getelementptr inbounds [4 x i64], ptr %14, i64 0, i64 %indvars.iv.next
  %36 = load i64, ptr %35, align 8, !tbaa !19
  %37 = getelementptr inbounds [5 x i64], ptr %15, i64 0, i64 %indvars.iv.next
  store i64 %36, ptr %37, align 8, !tbaa !19
  %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 %._crit_edge.loopexit.unr-lcssa, label %25, !llvm.loop !22

38:                                               ; preds = %6, %._crit_edge
  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 144}
!17 = !{!6, !11, i64 148}
!18 = !{!6, !12, i64 232}
!19 = !{!15, !15, i64 0}
!20 = !{!6, !11, i64 240}
!21 = !{!6, !11, i64 244}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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