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

; 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 [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_map_compute_fov_restrictive_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 ptr, align 8
  %14 = alloca ptr, align 8
  %15 = 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
  %16 = zext i1 %4 to i8
  store i8 %16, ptr %11, align 1, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = call zeroext i1 @TCOD_map_in_bounds(ptr noundef %17, i32 noundef %18, i32 noundef %19)
  br i1 %20, label %25, label %21

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

25:                                               ; preds = %5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TCOD_Map, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TCOD_Map, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = mul nsw i32 %30, %33
  %35 = add nsw i32 %29, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.TCOD_MapCell, ptr %28, i64 %36
  %38 = getelementptr inbounds %struct.TCOD_MapCell, ptr %37, i32 0, i32 2
  store i8 1, ptr %38, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TCOD_Map, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !18
  %42 = sdiv i32 %41, 7
  store i32 %42, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = mul i64 %44, 8
  %46 = call noalias ptr @malloc(i64 noundef %45) #7
  store ptr %46, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = mul i64 %48, 8
  %50 = call noalias ptr @malloc(i64 noundef %49) #7
  store ptr %50, ptr %14, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %56

53:                                               ; preds = %25
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %60, label %56

56:                                               ; preds = %53, %25
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  call void @free(ptr noundef %57) #6
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %58) #6
  %59 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 253, ptr noundef @.str.3)
  store i32 -3, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %95

60:                                               ; preds = %53
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load i8, ptr %11, align 1, !tbaa !11, !range !19, !noundef !20
  %66 = trunc i8 %65 to i1
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  call void @compute_quadrant(ptr noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i1 noundef zeroext %66, i32 noundef 1, i32 noundef 1, ptr noundef %67, ptr noundef %68)
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = load i8, ptr %11, align 1, !tbaa !11, !range !19, !noundef !20
  %74 = trunc i8 %73 to i1
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  call void @compute_quadrant(ptr noundef %69, i32 noundef %70, i32 noundef %71, i32 noundef %72, i1 noundef zeroext %74, i32 noundef 1, i32 noundef -1, ptr noundef %75, ptr noundef %76)
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = load i8, ptr %11, align 1, !tbaa !11, !range !19, !noundef !20
  %82 = trunc i8 %81 to i1
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  call void @compute_quadrant(ptr noundef %77, i32 noundef %78, i32 noundef %79, i32 noundef %80, i1 noundef zeroext %82, i32 noundef -1, i32 noundef 1, ptr noundef %83, ptr noundef %84)
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = load i8, ptr %11, align 1, !tbaa !11, !range !19, !noundef !20
  %90 = trunc i8 %89 to i1
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = load ptr, ptr %14, align 8, !tbaa !5
  call void @compute_quadrant(ptr noundef %85, i32 noundef %86, i32 noundef %87, i32 noundef %88, i1 noundef zeroext %90, i32 noundef -1, i32 noundef -1, ptr noundef %91, ptr noundef %92)
  %93 = load ptr, ptr %14, align 8, !tbaa !5
  call void @free(ptr noundef %93) #6
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %94) #6
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %95

95:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %96

96:                                               ; preds = %95, %21
  %97 = load i32, ptr %6, align 4
  ret i32 %97
}

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !6, i64 16}
!14 = !{!"TCOD_Map", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!17, !12, i64 2}
!17 = !{!"TCOD_MapCell", !12, i64 0, !12, i64 1, !12, i64 2}
!18 = !{!14, !10, i64 8}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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 [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -3, 1) i32 @TCOD_map_compute_fov_restrictive_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 240, i32 noundef %1, i32 noundef %2) #5
  br label %29

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = load i32, ptr %0, align 8, !tbaa !11
  %13 = mul nsw i32 %12, %2
  %14 = add nsw i32 %13, %1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %struct.TCOD_MapCell, ptr %11, i64 %15, i32 2
  store i8 1, ptr %16, align 1, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = sdiv i32 %18, 7
  %20 = sext i32 %19 to i64
  %21 = shl nsw i64 %20, 3
  %22 = tail call noalias ptr @malloc(i64 noundef %21) #6
  %23 = tail call noalias ptr @malloc(i64 noundef %21) #6
  %24 = icmp ne ptr %22, null
  %25 = icmp ne ptr %23, null
  %or.cond = and i1 %24, %25
  br i1 %or.cond, label %28, label %26

26:                                               ; preds = %9
  tail call void @free(ptr noundef %23) #5
  tail call void @free(ptr noundef %22) #5
  %27 = tail call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 253, ptr noundef nonnull @.str.3) #5
  br label %29

28:                                               ; preds = %9
  tail call void @compute_quadrant(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef 1, i32 noundef 1, ptr noundef nonnull %22, ptr noundef nonnull %23)
  tail call void @compute_quadrant(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef 1, i32 noundef -1, ptr noundef nonnull %22, ptr noundef nonnull %23)
  tail call void @compute_quadrant(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef -1, i32 noundef 1, ptr noundef nonnull %22, ptr noundef nonnull %23)
  tail call void @compute_quadrant(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4, i32 noundef -1, i32 noundef -1, ptr noundef nonnull %22, ptr noundef nonnull %23)
  tail call void @free(ptr noundef nonnull %23) #5
  tail call void @free(ptr noundef nonnull %22) #5
  br label %29

29:                                               ; preds = %26, %28, %7
  %.1 = phi i32 [ -2, %7 ], [ 0, %28 ], [ -3, %26 ]
  ret i32 %.1
}

; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @compute_quadrant(ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext, i32 noundef, i32 noundef, ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #6 = { nounwind allocsize(0) }

!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, !10, i64 16}
!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 0}
!12 = !{!13, !14, i64 2}
!13 = !{!"TCOD_MapCell", !14, i64 0, !14, i64 1, !14, i64 2}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!6, !7, i64 8}


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