; 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_get = external hidden unnamed_addr constant [51 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

declare i32 @TCOD_list_size(ptr noundef) #2

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) #2

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

13:                                               ; preds = %4
  br label %15

14:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 344, ptr noundef @__PRETTY_FUNCTION__.TCOD_path_get) #4
  unreachable

15:                                               ; preds = %13
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %23

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TCOD_Path, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %21, ptr %22, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %18, %15
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TCOD_Path, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %29, ptr %30, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %26, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TCOD_Path, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = call i32 @TCOD_list_size(ptr noundef %34)
  %36 = sub nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %71, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TCOD_Path, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = call ptr @TCOD_list_get(ptr noundef %40, i32 noundef %41)
  %43 = ptrtoint ptr %42 to i64
  %44 = trunc i64 %43 to i32
  store i32 %44, ptr %10, align 4, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %55

47:                                               ; preds = %37
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = add nsw i32 %53, %51
  store i32 %54, ptr %52, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %47, %37
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %66

58:                                               ; preds = %55
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add nsw i32 %64, %62
  store i32 %65, ptr %63, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %58, %55
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %71

71:                                               ; preds = %66
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = icmp sge i32 %72, 0
  br i1 %73, label %37, label %74, !llvm.loop !16

74:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret void
}

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 = { "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 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"TCOD_Path", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.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_get = external hidden unnamed_addr constant [51 x i8], align 1

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

declare i32 @TCOD_list_size(ptr noundef) local_unnamed_addr #1

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_path_get(ptr noundef readonly %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

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

6:                                                ; preds = %4
  %.not24 = icmp eq ptr %2, null
  br i1 %.not24, label %7, label %.thread35

7:                                                ; preds = %6
  %.not25 = icmp eq ptr %3, null
  br i1 %.not25, label %.split.us.split.us.preheader, label %.thread

.thread35:                                        ; preds = %6
  %8 = load i32, ptr %0, align 8, !tbaa !5
  store i32 %8, ptr %2, align 4, !tbaa !12
  %.not2536 = icmp eq ptr %3, null
  br i1 %.not2536, label %.split.split.us.preheader, label %.thread

.thread:                                          ; preds = %7, %.thread35
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !13
  store i32 %10, ptr %3, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = tail call i32 @TCOD_list_size(ptr noundef %12) #4
  br i1 %.not24, label %.split.us.split, label %.split.split

.split.us.split.us.preheader:                     ; preds = %7
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = tail call i32 @TCOD_list_size(ptr noundef %15) #4
  br label %.split.us.split.us

.split.us.split.us:                               ; preds = %.split.us.split.us.preheader, %.split.us.split.us
  %.018.in.us.us = phi i32 [ %.018.us.us, %.split.us.split.us ], [ %16, %.split.us.split.us.preheader ]
  %.0.us.us = phi i32 [ %19, %.split.us.split.us ], [ %1, %.split.us.split.us.preheader ]
  %.018.us.us = add nsw i32 %.018.in.us.us, -1
  %17 = load ptr, ptr %14, align 8, !tbaa !14
  %18 = tail call ptr @TCOD_list_get(ptr noundef %17, i32 noundef %.018.us.us) #4
  %19 = add nsw i32 %.0.us.us, -1
  %20 = icmp sgt i32 %.0.us.us, 0
  br i1 %20, label %.split.us.split.us, label %.split28.us, !llvm.loop !15

.split.us.split:                                  ; preds = %.thread, %.split.us.split
  %.018.in.us = phi i32 [ %.018.us, %.split.us.split ], [ %13, %.thread ]
  %.0.us = phi i32 [ %29, %.split.us.split ], [ %1, %.thread ]
  %.018.us = add nsw i32 %.018.in.us, -1
  %21 = load ptr, ptr %11, align 8, !tbaa !14
  %22 = tail call ptr @TCOD_list_get(ptr noundef %21, i32 noundef %.018.us) #4
  %23 = ptrtoint ptr %22 to i64
  %sext26.us = shl i64 %23, 32
  %24 = ashr exact i64 %sext26.us, 32
  %25 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = load i32, ptr %3, align 4, !tbaa !12
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %3, align 4, !tbaa !12
  %29 = add nsw i32 %.0.us, -1
  %30 = icmp sgt i32 %.0.us, 0
  br i1 %30, label %.split.us.split, label %.split28.us, !llvm.loop !15

.split.split.us.preheader:                        ; preds = %.thread35
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = tail call i32 @TCOD_list_size(ptr noundef %32) #4
  br label %.split.split.us

.split.split.us:                                  ; preds = %.split.split.us.preheader, %.split.split.us
  %.018.in.us29 = phi i32 [ %.018.us31, %.split.split.us ], [ %33, %.split.split.us.preheader ]
  %.0.us30 = phi i32 [ %42, %.split.split.us ], [ %1, %.split.split.us.preheader ]
  %.018.us31 = add nsw i32 %.018.in.us29, -1
  %34 = load ptr, ptr %31, align 8, !tbaa !14
  %35 = tail call ptr @TCOD_list_get(ptr noundef %34, i32 noundef %.018.us31) #4
  %36 = ptrtoint ptr %35 to i64
  %sext.us = shl i64 %36, 32
  %37 = ashr exact i64 %sext.us, 32
  %38 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = load i32, ptr %2, align 4, !tbaa !12
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %2, align 4, !tbaa !12
  %42 = add nsw i32 %.0.us30, -1
  %43 = icmp sgt i32 %.0.us30, 0
  br i1 %43, label %.split.split.us, label %.split28.us, !llvm.loop !15

.split.split:                                     ; preds = %.thread, %.split.split
  %.018.in = phi i32 [ %.018, %.split.split ], [ %13, %.thread ]
  %.0 = phi i32 [ %56, %.split.split ], [ %1, %.thread ]
  %.018 = add nsw i32 %.018.in, -1
  %44 = load ptr, ptr %11, align 8, !tbaa !14
  %45 = tail call ptr @TCOD_list_get(ptr noundef %44, i32 noundef %.018) #4
  %46 = ptrtoint ptr %45 to i64
  %sext = shl i64 %46, 32
  %47 = ashr exact i64 %sext, 32
  %48 = getelementptr inbounds [9 x i32], ptr @dir_x, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = load i32, ptr %2, align 4, !tbaa !12
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %2, align 4, !tbaa !12
  %52 = getelementptr inbounds [9 x i32], ptr @dir_y, i64 0, i64 %47
  %53 = load i32, ptr %52, align 4, !tbaa !12
  %54 = load i32, ptr %3, align 4, !tbaa !12
  %55 = add nsw i32 %54, %53
  store i32 %55, ptr %3, align 4, !tbaa !12
  %56 = add nsw i32 %.0, -1
  %57 = icmp sgt i32 %.0, 0
  br i1 %57, label %.split.split, label %.split28.us, !llvm.loop !15

.split28.us:                                      ; preds = %.split.split.us, %.split.split, %.split.us.split, %.split.us.split.us
  ret void
}

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 = { "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 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 = { noreturn nounwind }
attributes #4 = { 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, !7, i64 0}
!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 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass