; 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: nounwind uwtable
declare dso_local i32 @TCOD_pf_compute_step(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_pf_compute(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %18

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %14, %7
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TCOD_Pathfinder, ptr %9, i32 0, i32 8
  %11 = getelementptr inbounds %struct.TCOD_Heap, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %8
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call i32 @TCOD_pf_compute_step(ptr noundef %15)
  br label %8, !llvm.loop !17

17:                                               ; preds = %8
  store i32 0, ptr %2, align 4
  br label %18

18:                                               ; preds = %17, %6
  %19 = load i32, ptr %2, align 4
  ret i32 %19
}

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

!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, !13, i64 352}
!10 = !{!"TCOD_Pathfinder", !7, i64 0, !7, i64 8, !11, i64 40, !11, i64 41, !11, i64 42, !12, i64 48, !14, i64 144, !12, i64 248, !15, i64 344}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"TCOD_ArrayData", !7, i64 0, !13, i64 4, !7, i64 8, !7, i64 48, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"TCOD_BasicGraph2D", !12, i64 0, !13, i64 96, !13, i64 100}
!15 = !{!"TCOD_Heap", !6, i64 0, !13, i64 8, !13, i64 12, !16, i64 16, !16, i64 24, !16, i64 32, !13, i64 40}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 i32 @TCOD_pf_compute_step(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @TCOD_pf_compute(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 352
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not34 = icmp eq i32 %3, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %4 = tail call i32 @TCOD_pf_compute_step(ptr noundef nonnull %0)
  %5 = load i32, ptr %2, align 8, !tbaa !5
  %.not3 = icmp eq i32 %5, 0
  br i1 %.not3, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %1
  %.0 = phi i32 [ -1, %1 ], [ 0, %.preheader ], [ 0, %.lr.ph ]
  ret i32 %.0
}

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

!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, !11, i64 352}
!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 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass