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

; 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_Map = type { i32, i32, i32, ptr }
%struct.TCOD_MapCell = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [105 x i8], align 1

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

20:                                               ; preds = %5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 120, i32 noundef %21, i32 noundef %22)
  store i32 -2, ptr %6, align 4
  br label %103

24:                                               ; preds = %5
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = icmp sle i32 %25, 0
  br i1 %26, label %27, label %73

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TCOD_Map, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sub nsw i32 %30, %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp sgt i32 %32, %33
  br i1 %34, label %35, label %41

35:                                               ; preds = %27
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TCOD_Map, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sub nsw i32 %38, %39
  br label %43

41:                                               ; preds = %27
  %42 = load i32, ptr %8, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %41, %35
  %44 = phi i32 [ %40, %35 ], [ %42, %41 ]
  store i32 %44, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TCOD_Map, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %43
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TCOD_Map, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = sub nsw i32 %55, %56
  br label %60

58:                                               ; preds = %43
  %59 = load i32, ptr %9, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %58, %52
  %61 = phi i32 [ %57, %52 ], [ %59, %58 ]
  store i32 %61, ptr %13, align 4, !tbaa !9
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = mul nsw i32 %62, %63
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = mul nsw i32 %65, %66
  %68 = add nsw i32 %64, %67
  %69 = sitofp i32 %68 to double
  %70 = call double @sqrt(double noundef %69) #5
  %71 = fptosi double %70 to i32
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %73

73:                                               ; preds = %60, %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %86, %73
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = icmp slt i32 %75, 8
  br i1 %76, label %78, label %77

77:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %89

78:                                               ; preds = %74
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = load i32, ptr %14, align 4, !tbaa !9
  %84 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %85 = trunc i8 %84 to i1
  call void @cast_light(ptr noundef %79, i32 noundef %80, i32 noundef %81, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %82, i32 noundef %83, i1 noundef zeroext %85)
  br label %86

86:                                               ; preds = %78
  %87 = load i32, ptr %14, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %14, align 4, !tbaa !9
  br label %74, !llvm.loop !18

89:                                               ; preds = %77
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.TCOD_Map, ptr %90, i32 0, i32 3
  %92 = load ptr, ptr %91, align 8, !tbaa !20
  %93 = load i32, ptr %8, align 4, !tbaa !9
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.TCOD_Map, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 8, !tbaa !13
  %98 = mul nsw i32 %94, %97
  %99 = add nsw i32 %93, %98
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds %struct.TCOD_MapCell, ptr %92, i64 %100
  %102 = getelementptr inbounds %struct.TCOD_MapCell, ptr %101, i32 0, i32 2
  store i8 1, ptr %102, align 1, !tbaa !21
  store i32 0, ptr %6, align 4
  br label %103

103:                                              ; preds = %89, %20
  %104 = load i32, ptr %6, align 4
  ret i32 %104
}

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

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

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

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

; Function Attrs: nounwind uwtable
declare hidden void @cast_light(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, float noundef, float noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #0

attributes #0 = { 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 #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 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"TCOD_Map", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!15 = !{!14, !10, i64 4}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!14, !6, i64 16}
!21 = !{!22, !12, i64 2}
!22 = !{!"TCOD_MapCell", !12, i64 0, !12, i64 1, !12, i64 2}


; 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"

%struct.TCOD_MapCell = type { i8, i8, i8 }

@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [105 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @TCOD_map_compute_fov_recursive_shadowcasting(ptr noalias noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = tail call zeroext i1 @TCOD_map_in_bounds(ptr noundef %0, i32 noundef %1, i32 noundef %2)
  br i1 %6, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 120, i32 noundef %1, i32 noundef %2) #4
  br label %32

9:                                                ; preds = %5
  %10 = icmp slt i32 %3, 1
  br i1 %10, label %11, label %24

11:                                               ; preds = %9
  %12 = load i32, ptr %0, align 8, !tbaa !5
  %13 = sub nsw i32 %12, %1
  %. = tail call i32 @llvm.smax.i32(i32 %13, i32 %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sub nsw i32 %15, %2
  %17 = tail call i32 @llvm.smax.i32(i32 %16, i32 %2)
  %18 = mul nsw i32 %., %.
  %19 = mul nsw i32 %17, %17
  %20 = add nuw nsw i32 %19, %18
  %21 = uitofp nneg i32 %20 to double
  %sqrt = tail call double @llvm.sqrt.f64(double %21)
  %22 = fptosi double %sqrt to i32
  %23 = add nsw i32 %22, 1
  br label %24

24:                                               ; preds = %11, %9
  %.035 = phi i32 [ %23, %11 ], [ %3, %9 ]
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 0, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 1, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 2, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 3, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 4, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 5, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 6, i1 noundef zeroext %4)
  tail call void @cast_light(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef 1, float noundef 1.000000e+00, float noundef 0.000000e+00, i32 noundef %.035, i32 noundef 7, i1 noundef zeroext %4)
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = load i32, ptr %0, align 8, !tbaa !5
  %28 = mul nsw i32 %27, %2
  %29 = add nsw i32 %28, %1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.TCOD_MapCell, ptr %26, i64 %30, i32 2
  store i8 1, ptr %31, align 1, !tbaa !13
  br label %32

32:                                               ; preds = %24, %7
  %.034 = phi i32 [ 0, %24 ], [ -2, %7 ]
  ret i32 %.034
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @cast_light(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, float noundef, float noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #3

attributes #0 = { 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 #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 = { "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 nosync nounwind speculatable willreturn memory(none) }
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_Map", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 16}
!13 = !{!14, !15, i64 2}
!14 = !{!"TCOD_MapCell", !15, i64 0, !15, i64 1, !15, i64 2}
!15 = !{!"_Bool", !8, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass