; 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
@__PRETTY_FUNCTION__.TCOD_path_reverse = external hidden unnamed_addr constant [36 x i8], align 1
@invert_dir = external hidden constant [9 x i32], align 16

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

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 298, ptr noundef @__PRETTY_FUNCTION__.TCOD_path_reverse) #4
  unreachable

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TCOD_Path, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  store i32 %13, ptr %3, align 4, !tbaa !13
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TCOD_Path, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TCOD_Path, ptr %17, i32 0, i32 0
  store i32 %16, ptr %18, align 8, !tbaa !9
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TCOD_Path, ptr %20, i32 0, i32 2
  store i32 %19, ptr %21, align 8, !tbaa !14
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TCOD_Path, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !15
  store i32 %24, ptr %3, align 4, !tbaa !13
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TCOD_Path, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TCOD_Path, ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 4, !tbaa !15
  %30 = load i32, ptr %3, align 4, !tbaa !13
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TCOD_Path, ptr %31, i32 0, i32 3
  store i32 %30, ptr %32, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %60, %10
  %34 = load i32, ptr %4, align 4, !tbaa !13
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TCOD_Path, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = call i32 @TCOD_list_size(ptr noundef %37)
  %39 = icmp slt i32 %34, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %63

41:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TCOD_Path, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load i32, ptr %4, align 4, !tbaa !13
  %46 = call ptr @TCOD_list_get(ptr noundef %44, i32 noundef %45)
  %47 = ptrtoint ptr %46 to i64
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %5, align 4, !tbaa !13
  %49 = load i32, ptr %5, align 4, !tbaa !13
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [9 x i32], ptr @invert_dir, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !13
  store i32 %52, ptr %5, align 4, !tbaa !13
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TCOD_Path, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = load i32, ptr %5, align 4, !tbaa !13
  %57 = sext i32 %56 to i64
  %58 = inttoptr i64 %57 to ptr
  %59 = load i32, ptr %4, align 4, !tbaa !13
  call void @TCOD_list_set(ptr noundef %55, ptr noundef %58, i32 noundef %59)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %60

60:                                               ; preds = %41
  %61 = load i32, ptr %4, align 4, !tbaa !13
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !13
  br label %33, !llvm.loop !18

63:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

declare i32 @TCOD_list_size(ptr noundef) #3

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

declare void @TCOD_list_set(ptr noundef, ptr noundef, i32 noundef) #3

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, !11, i64 0}
!10 = !{!"TCOD_Path", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 4}
!16 = !{!10, !11, i64 12}
!17 = !{!10, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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
@__PRETTY_FUNCTION__.TCOD_path_reverse = external hidden unnamed_addr constant [36 x i8], align 1
@invert_dir = external hidden local_unnamed_addr constant [9 x i32], align 16

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

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

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 298, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_path_reverse) #3
  unreachable

3:                                                ; preds = %1
  %4 = load <4 x i32>, ptr %0, align 8, !tbaa !5
  %5 = shufflevector <4 x i32> %4, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %5, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = tail call i32 @TCOD_list_size(ptr noundef %7) #4
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.020 = phi i32 [ %19, %.lr.ph ], [ 0, %3 ]
  %10 = load ptr, ptr %6, align 8, !tbaa !9
  %11 = tail call ptr @TCOD_list_get(ptr noundef %10, i32 noundef %.020) #4
  %12 = ptrtoint ptr %11 to i64
  %sext = shl i64 %12, 32
  %13 = ashr exact i64 %sext, 32
  %14 = getelementptr inbounds [9 x i32], ptr @invert_dir, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = sext i32 %15 to i64
  %18 = inttoptr i64 %17 to ptr
  tail call void @TCOD_list_set(ptr noundef %16, ptr noundef %18, i32 noundef %.020) #4
  %19 = add nuw nsw i32 %.020, 1
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = tail call i32 @TCOD_list_size(ptr noundef %20) #4
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

declare i32 @TCOD_list_size(ptr noundef) local_unnamed_addr #2

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

declare void @TCOD_list_set(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"TCOD_Path", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16, !6, i64 24, !6, i64 28, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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