; LLVM IR from libtcod/libtcod :: src/libtcod (pathfinder_frontier)

; 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_Frontier = type { i8, i32, [4 x i32], %struct.TCOD_Heap }
%struct.TCOD_Heap = type { ptr, i32, i32, i64, i64, i64, i32 }

@.str.1 = external hidden unnamed_addr constant [97 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1

declare i32 @TCOD_set_errorf(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 i32 @TCOD_frontier_push(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [5 x i32], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %4
  %15 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 77, ptr noundef @.str.4)
  store i32 -2, ptr %5, align 4
  br label %46

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 20, ptr %10) #3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = getelementptr inbounds [5 x i32], ptr %10, i64 0, i64 0
  store i32 %17, ptr %18, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %37, %16
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TCOD_Frontier, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 8, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp slt i32 %20, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %40

27:                                               ; preds = %19
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5 x i32], ptr %10, i64 0, i64 %35
  store i32 %32, ptr %36, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %27
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !15

40:                                               ; preds = %26
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TCOD_Frontier, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = getelementptr inbounds [5 x i32], ptr %10, i64 0, i64 0
  %45 = call i32 @TCOD_minheap_push(ptr noundef %42, i32 noundef %43, ptr noundef %44)
  store i32 0, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #3
  br label %46

46:                                               ; preds = %40, %14
  %47 = load i32, ptr %5, align 4
  ret i32 %47
}

declare i32 @TCOD_minheap_push(ptr noundef, i32 noundef, ptr noundef) #0

attributes #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 #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 = { 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_Frontier", !7, i64 0, !10, i64 4, !7, i64 8, !13, i64 24}
!13 = !{!"TCOD_Heap", !6, i64 0, !10, i64 8, !10, i64 12, !14, i64 16, !14, i64 24, !14, i64 32, !10, i64 40}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 [97 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1

declare i32 @TCOD_set_errorf(ptr noundef, ...) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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 range(i32 -2, 1) i32 @TCOD_frontier_push(ptr noalias noundef %0, ptr noalias nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [5 x i32], align 16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %6, label %8

6:                                                ; preds = %4
  %7 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 77, ptr noundef nonnull @.str.4) #4
  br label %15

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %5) #4
  store i32 %2, ptr %5, align 16, !tbaa !5
  %9 = load i8, ptr %0, align 8, !tbaa !9
  %10 = icmp sgt i8 %9, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %11 = zext nneg i8 %9 to i64
  %scevgep = getelementptr inbounds i8, ptr %5, i64 4
  %12 = shl nuw nsw i64 %11, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %scevgep, ptr align 4 %1, i64 %12, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %8
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = call i32 @TCOD_minheap_push(ptr noundef nonnull %13, i32 noundef %3, ptr noundef nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %5) #4
  br label %15

15:                                               ; preds = %._crit_edge, %6
  %.010 = phi i32 [ 0, %._crit_edge ], [ -2, %6 ]
  ret i32 %.010
}

declare i32 @TCOD_minheap_push(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #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 #1 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!10 = !{!"TCOD_Frontier", !7, i64 0, !6, i64 4, !7, i64 8, !11, i64 24}
!11 = !{!"TCOD_Heap", !12, i64 0, !6, i64 8, !6, i64 12, !13, i64 16, !13, i64 24, !13, i64 32, !6, i64 40}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass