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

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @TCOD_map_in_bounds(ptr noundef, i32 noundef, i32 noundef) #1

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

17:                                               ; preds = %6
  %18 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 172, ptr noundef @.str.4)
  store i32 -2, ptr %7, align 4
  br label %82

19:                                               ; preds = %6
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = call zeroext i1 @TCOD_map_in_bounds(ptr noundef %20, i32 noundef %21, i32 noundef %22)
  br i1 %23, label %28, label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 176, i32 noundef %25, i32 noundef %26)
  store i32 -2, ptr %7, align 4
  br label %82

28:                                               ; preds = %19
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TCOD_map_clear_fov(ptr noundef %29)
  %30 = load i32, ptr %13, align 4, !tbaa !9
  switch i32 %30, label %81 [
    i32 0, label %31
    i32 1, label %39
    i32 2, label %47
    i32 3, label %55
    i32 4, label %55
    i32 5, label %55
    i32 6, label %55
    i32 7, label %55
    i32 8, label %55
    i32 9, label %55
    i32 10, label %55
    i32 11, label %55
    i32 12, label %65
    i32 13, label %73
  ]

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %37 = trunc i8 %36 to i1
  %38 = call i32 @TCOD_map_compute_fov_circular_raycasting(ptr noundef %32, i32 noundef %33, i32 noundef %34, i32 noundef %35, i1 noundef zeroext %37)
  store i32 %38, ptr %7, align 4
  br label %82

39:                                               ; preds = %28
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %45 = trunc i8 %44 to i1
  %46 = call i32 @TCOD_map_compute_fov_diamond_raycasting(ptr noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %43, i1 noundef zeroext %45)
  store i32 %46, ptr %7, align 4
  br label %82

47:                                               ; preds = %28
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %53 = trunc i8 %52 to i1
  %54 = call i32 @TCOD_map_compute_fov_recursive_shadowcasting(ptr noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef %51, i1 noundef zeroext %53)
  store i32 %54, ptr %7, align 4
  br label %82

55:                                               ; preds = %28, %28, %28, %28, %28, %28, %28, %28, %28
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %61 = trunc i8 %60 to i1
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = sub i32 %62, 3
  %64 = call i32 @TCOD_map_compute_fov_permissive2(ptr noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59, i1 noundef zeroext %61, i32 noundef %63)
  store i32 %64, ptr %7, align 4
  br label %82

65:                                               ; preds = %28
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %71 = trunc i8 %70 to i1
  %72 = call i32 @TCOD_map_compute_fov_restrictive_shadowcasting(ptr noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69, i1 noundef zeroext %71)
  store i32 %72, ptr %7, align 4
  br label %82

73:                                               ; preds = %28
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %79 = trunc i8 %78 to i1
  %80 = call i32 @TCOD_map_compute_fov_symmetric_shadowcast(ptr noundef %74, i32 noundef %75, i32 noundef %76, i32 noundef %77, i1 noundef zeroext %79)
  store i32 %80, ptr %7, align 4
  br label %82

81:                                               ; preds = %28
  store i32 -2, ptr %7, align 4
  br label %82

82:                                               ; preds = %81, %73, %65, %55, %47, %39, %31, %24, %17
  %83 = load i32, ptr %7, align 4
  ret i32 %83
}

; Function Attrs: nounwind uwtable
declare hidden void @TCOD_map_clear_fov(ptr noalias noundef) #2

declare i32 @TCOD_map_compute_fov_circular_raycasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

declare i32 @TCOD_map_compute_fov_diamond_raycasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

declare i32 @TCOD_map_compute_fov_recursive_shadowcasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

declare i32 @TCOD_map_compute_fov_permissive2(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext, i32 noundef) #0

declare i32 @TCOD_map_compute_fov_restrictive_shadowcasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

declare i32 @TCOD_map_compute_fov_symmetric_shadowcast(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #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 = { inlinehint 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 = { 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" }

!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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @TCOD_map_in_bounds(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_map_compute_fov(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef %5) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %9

7:                                                ; preds = %6
  %8 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 172, ptr noundef nonnull @.str.4) #3
  br label %27

9:                                                ; preds = %6
  %10 = tail call zeroext i1 @TCOD_map_in_bounds(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2)
  br i1 %10, label %13, label %11

11:                                               ; preds = %9
  %12 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 176, i32 noundef %1, i32 noundef %2) #3
  br label %27

13:                                               ; preds = %9
  tail call void @TCOD_map_clear_fov(ptr noundef nonnull %0)
  switch i32 %5, label %27 [
    i32 0, label %14
    i32 1, label %16
    i32 2, label %18
    i32 3, label %20
    i32 4, label %20
    i32 5, label %20
    i32 6, label %20
    i32 7, label %20
    i32 8, label %20
    i32 9, label %20
    i32 10, label %20
    i32 11, label %20
    i32 12, label %23
    i32 13, label %25
  ]

14:                                               ; preds = %13
  %15 = tail call i32 @TCOD_map_compute_fov_circular_raycasting(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #3
  br label %27

16:                                               ; preds = %13
  %17 = tail call i32 @TCOD_map_compute_fov_diamond_raycasting(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #3
  br label %27

18:                                               ; preds = %13
  %19 = tail call i32 @TCOD_map_compute_fov_recursive_shadowcasting(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #3
  br label %27

20:                                               ; preds = %13, %13, %13, %13, %13, %13, %13, %13, %13
  %21 = add nsw i32 %5, -3
  %22 = tail call i32 @TCOD_map_compute_fov_permissive2(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef %21) #3
  br label %27

23:                                               ; preds = %13
  %24 = tail call i32 @TCOD_map_compute_fov_restrictive_shadowcasting(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #3
  br label %27

25:                                               ; preds = %13
  %26 = tail call i32 @TCOD_map_compute_fov_symmetric_shadowcast(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #3
  br label %27

27:                                               ; preds = %13, %25, %23, %20, %18, %16, %14, %11, %7
  %.0 = phi i32 [ %26, %25 ], [ %24, %23 ], [ %22, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ -2, %11 ], [ -2, %7 ], [ -2, %13 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @TCOD_map_clear_fov(ptr noalias noundef) local_unnamed_addr #2

declare i32 @TCOD_map_compute_fov_circular_raycasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @TCOD_map_compute_fov_diamond_raycasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @TCOD_map_compute_fov_recursive_shadowcasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @TCOD_map_compute_fov_permissive2(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #0

declare i32 @TCOD_map_compute_fov_restrictive_shadowcasting(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @TCOD_map_compute_fov_symmetric_shadowcast(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #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 = { inlinehint 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 = { 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass