; LLVM IR from libtcod/libtcod :: src/libtcod (path_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"

%struct.TCOD_Path = type { i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, ptr, float, ptr, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@dir_x = external hidden constant [9 x i32], align 16
@dir_y = external hidden constant [9 x i32], align 16
@__PRETTY_FUNCTION__.TCOD_path_walk = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_path_compute(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @TCOD_path_walk(ptr noundef %0, ptr noundef %1, ptr noundef %2, i1 noundef zeroext %3) #2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  %14 = zext i1 %3 to i8
  store i8 %14, ptr %9, align 1, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %19

18:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 313, ptr noundef @__PRETTY_FUNCTION__.TCOD_path_walk) #4
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call zeroext i1 @TCOD_path_is_empty(ptr noundef %20)
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i1 false, ptr %5, align 1
  br label %102

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_Path, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = call ptr @TCOD_list_pop(ptr noundef %26)
  %28 = ptrtoint ptr %27 to i64
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %10, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TCOD_Path, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %10, align 4, !tbaa !15
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = add nsw i32 %32, %36
  store i32 %37, ptr %11, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TCOD_Path, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = load i32, ptr %10, align 4, !tbaa !15
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = add nsw i32 %40, %44
  store i32 %45, ptr %12, align 4, !tbaa !15
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TCOD_Path, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TCOD_Path, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !17
  %53 = load i32, ptr %11, align 4, !tbaa !15
  %54 = load i32, ptr %12, align 4, !tbaa !15
  %55 = call float @TCOD_path_walk_cost(ptr noundef %46, i32 noundef %49, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  %56 = fcmp ole float %55, 0.000000e+00
  br i1 %56, label %57, label %82

57:                                               ; preds = %23
  %58 = load i8, ptr %9, align 1, !tbaa !9, !range !18, !noundef !19
  %59 = trunc i8 %58 to i1
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %101

61:                                               ; preds = %57
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TCOD_Path, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !16
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TCOD_Path, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !17
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TCOD_Path, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !20
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TCOD_Path, ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 4, !tbaa !21
  %75 = call zeroext i1 @TCOD_path_compute(ptr noundef %62, i32 noundef %65, i32 noundef %68, i32 noundef %71, i32 noundef %74)
  br i1 %75, label %77, label %76

76:                                               ; preds = %61
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %101

77:                                               ; preds = %61
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = call zeroext i1 @TCOD_path_walk(ptr noundef %78, ptr noundef %79, ptr noundef %80, i1 noundef zeroext true)
  store i1 %81, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %101

82:                                               ; preds = %23
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %88

85:                                               ; preds = %82
  %86 = load i32, ptr %11, align 4, !tbaa !15
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %86, ptr %87, align 4, !tbaa !15
  br label %88

88:                                               ; preds = %85, %82
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = icmp ne ptr %89, null
  br i1 %90, label %91, label %94

91:                                               ; preds = %88
  %92 = load i32, ptr %12, align 4, !tbaa !15
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %92, ptr %93, align 4, !tbaa !15
  br label %94

94:                                               ; preds = %91, %88
  %95 = load i32, ptr %11, align 4, !tbaa !15
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.TCOD_Path, ptr %96, i32 0, i32 0
  store i32 %95, ptr %97, align 8, !tbaa !16
  %98 = load i32, ptr %12, align 4, !tbaa !15
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.TCOD_Path, ptr %99, i32 0, i32 1
  store i32 %98, ptr %100, align 4, !tbaa !17
  store i1 true, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %101

101:                                              ; preds = %94, %77, %76, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %102

102:                                              ; preds = %101, %22
  %103 = load i1, ptr %5, align 1
  ret i1 %103
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_path_is_empty(ptr noundef) #2

declare ptr @TCOD_list_pop(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden float @TCOD_path_walk_cost(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { noreturn nounwind "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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"TCOD_Path", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !6, i64 16, !13, i64 24, !13, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !14, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 0}
!17 = !{!12, !13, i64 4}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !13, i64 8}
!21 = !{!12, !13, i64 12}


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

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@dir_x = external hidden local_unnamed_addr constant [9 x i32], align 16
@dir_y = external hidden local_unnamed_addr constant [9 x i32], align 16
@__PRETTY_FUNCTION__.TCOD_path_walk = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_path_compute(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @TCOD_path_walk(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, i1 noundef zeroext %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  br i1 %.not, label %33, label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %4
  %9 = tail call zeroext i1 @TCOD_path_is_empty(ptr noundef nonnull %0)
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %tailrecurse.preheader
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = tail call ptr @TCOD_list_pop(ptr noundef %11) #3
  %13 = ptrtoint ptr %12 to i64
  %14 = load i32, ptr %0, align 8, !tbaa !12
  %sext.peel = shl i64 %13, 32
  %15 = ashr exact i64 %sext.peel, 32
  %16 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = add nsw i32 %17, %14
  %19 = load i32, ptr %6, align 4, !tbaa !14
  %20 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %15
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = add nsw i32 %21, %19
  %23 = tail call float @TCOD_path_walk_cost(ptr noundef nonnull %0, i32 noundef %14, i32 noundef %19, i32 noundef %18, i32 noundef %22)
  %24 = fcmp ugt float %23, 0.000000e+00
  br i1 %24, label %.loopexit43, label %25

25:                                               ; preds = %10
  br i1 %3, label %26, label %.loopexit

26:                                               ; preds = %25
  %27 = load i32, ptr %0, align 8, !tbaa !12
  %28 = load i32, ptr %6, align 4, !tbaa !14
  %29 = load i32, ptr %7, align 8, !tbaa !15
  %30 = load i32, ptr %8, align 4, !tbaa !16
  %31 = tail call zeroext i1 @TCOD_path_compute(ptr noundef nonnull %0, i32 noundef %27, i32 noundef %28, i32 noundef %29, i32 noundef %30)
  br i1 %31, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %26, %49
  %32 = tail call zeroext i1 @TCOD_path_is_empty(ptr noundef nonnull %0)
  br i1 %32, label %.loopexit, label %34

33:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 313, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_path_walk) #4
  unreachable

34:                                               ; preds = %tailrecurse
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = tail call ptr @TCOD_list_pop(ptr noundef %35) #3
  %37 = ptrtoint ptr %36 to i64
  %38 = load i32, ptr %0, align 8, !tbaa !12
  %sext = shl i64 %37, 32
  %39 = ashr exact i64 %sext, 32
  %40 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = add nsw i32 %41, %38
  %43 = load i32, ptr %6, align 4, !tbaa !14
  %44 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %39
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = add nsw i32 %45, %43
  %47 = tail call float @TCOD_path_walk_cost(ptr noundef nonnull %0, i32 noundef %38, i32 noundef %43, i32 noundef %42, i32 noundef %46)
  %48 = fcmp ugt float %47, 0.000000e+00
  br i1 %48, label %.loopexit43, label %49

49:                                               ; preds = %34
  %50 = load i32, ptr %0, align 8, !tbaa !12
  %51 = load i32, ptr %6, align 4, !tbaa !14
  %52 = load i32, ptr %7, align 8, !tbaa !15
  %53 = load i32, ptr %8, align 4, !tbaa !16
  %54 = tail call zeroext i1 @TCOD_path_compute(ptr noundef nonnull %0, i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  br i1 %54, label %tailrecurse, label %.loopexit, !llvm.loop !17

.loopexit43:                                      ; preds = %34, %10
  %.lcssa41 = phi i32 [ %18, %10 ], [ %42, %34 ]
  %.lcssa = phi i32 [ %22, %10 ], [ %46, %34 ]
  %.not34 = icmp eq ptr %1, null
  br i1 %.not34, label %56, label %55

55:                                               ; preds = %.loopexit43
  store i32 %.lcssa41, ptr %1, align 4, !tbaa !13
  br label %56

56:                                               ; preds = %55, %.loopexit43
  %.not35 = icmp eq ptr %2, null
  br i1 %.not35, label %58, label %57

57:                                               ; preds = %56
  store i32 %.lcssa, ptr %2, align 4, !tbaa !13
  br label %58

58:                                               ; preds = %57, %56
  store i32 %.lcssa41, ptr %0, align 8, !tbaa !12
  store i32 %.lcssa, ptr %6, align 4, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %49, %tailrecurse, %tailrecurse.preheader, %25, %26, %58
  %.1 = phi i1 [ true, %58 ], [ false, %26 ], [ false, %25 ], [ false, %tailrecurse.preheader ], [ false, %tailrecurse ], [ false, %49 ]
  ret i1 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @TCOD_path_is_empty(ptr noundef) local_unnamed_addr #1

declare ptr @TCOD_list_pop(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden float @TCOD_path_walk_cost(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { noreturn nounwind "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 = { 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 = { "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 #3 = { nounwind }
attributes #4 = { noreturn 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, !10, i64 16}
!6 = !{!"TCOD_Path", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !11, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass