; 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
@.str.5 = external hidden unnamed_addr constant [15 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_pop(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [5 x i32], align 16
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %10, label %8

8:                                                ; preds = %1
  %9 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 59, ptr noundef @.str.4)
  store i32 -2, ptr %2, align 4
  br label %49

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TCOD_Frontier, ptr %11, i32 0, i32 3
  %13 = getelementptr inbounds %struct.TCOD_Heap, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %10
  %17 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 63, ptr noundef @.str.5)
  store i32 -1, ptr %2, align 4
  br label %49

18:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 20, ptr %4) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TCOD_Frontier, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds [5 x i32], ptr %4, i64 0, i64 0
  call void @TCOD_minheap_pop(ptr noundef %20, ptr noundef %21)
  %22 = getelementptr inbounds [5 x i32], ptr %4, i64 0, i64 0
  %23 = load i32, ptr %22, align 16, !tbaa !14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_Frontier, ptr %24, i32 0, i32 1
  store i32 %23, ptr %25, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %26

26:                                               ; preds = %45, %18
  %27 = load i32, ptr %5, align 4, !tbaa !14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TCOD_Frontier, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 8, !tbaa !16
  %31 = sext i8 %30 to i32
  %32 = icmp slt i32 %27, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %26
  %35 = load i32, ptr %5, align 4, !tbaa !14
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5 x i32], ptr %4, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TCOD_Frontier, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %5, align 4, !tbaa !14
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4 x i32], ptr %41, i64 0, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !14
  br label %45

45:                                               ; preds = %34
  %46 = load i32, ptr %5, align 4, !tbaa !14
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !14
  br label %26, !llvm.loop !17

48:                                               ; preds = %33
  store i32 0, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 20, ptr %4) #3
  br label %49

49:                                               ; preds = %48, %16, %8
  %50 = load i32, ptr %2, align 4
  ret i32 %50
}

declare void @TCOD_minheap_pop(ptr 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, !11, i64 32}
!10 = !{!"TCOD_Frontier", !7, i64 0, !11, i64 4, !7, i64 8, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"TCOD_Heap", !6, i64 0, !11, i64 8, !11, i64 12, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = !{!10, !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"

@.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
@.str.5 = external hidden unnamed_addr constant [15 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_pop(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [5 x i32], align 16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 59, ptr noundef nonnull @.str.4) #4
  br label %20

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 63, ptr noundef nonnull @.str.5) #4
  br label %20

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #4
  call void @TCOD_minheap_pop(ptr noundef nonnull %12, ptr noundef nonnull %2) #4
  %13 = load i32, ptr %2, align 16, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %13, ptr %14, align 4, !tbaa !14
  %15 = load i8, ptr %0, align 8, !tbaa !15
  %16 = icmp sgt i8 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11
  %17 = zext nneg i8 %15 to i64
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %scevgep = getelementptr inbounds i8, ptr %2, i64 4
  %19 = shl nuw nsw i64 %17, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %18, ptr nonnull align 4 %scevgep, i64 %19, i1 false), !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %11
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #4
  br label %20

20:                                               ; preds = %._crit_edge, %9, %3
  %.010 = phi i32 [ -1, %9 ], [ 0, %._crit_edge ], [ -2, %3 ]
  ret i32 %.010
}

declare void @TCOD_minheap_pop(ptr 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, !9, i64 32}
!6 = !{!"TCOD_Frontier", !7, i64 0, !9, i64 4, !7, i64 8, !10, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"TCOD_Heap", !11, i64 0, !9, i64 8, !9, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !9, i64 40}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !9, i64 4}
!15 = !{!6, !7, i64 0}


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