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

%struct.TCOD_heightmap_t = type { i32, i32, ptr }

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
declare dso_local float @TCOD_heightmap_get_interpolated_value(ptr noundef, float noundef, float noundef) #2

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

18:                                               ; preds = %5
  br label %131

19:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds float, ptr %20, i64 0
  store float 0.000000e+00, ptr %21, align 4, !tbaa !9
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds float, ptr %22, i64 1
  store float 0.000000e+00, ptr %23, align 4, !tbaa !9
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds float, ptr %24, i64 2
  store float 1.000000e+00, ptr %25, align 4, !tbaa !9
  %26 = load float, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = sub nsw i32 %29, 1
  %31 = sitofp i32 %30 to float
  %32 = fcmp oge float %26, %31
  br i1 %32, label %41, label %33

33:                                               ; preds = %19
  %34 = load float, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = sub nsw i32 %37, 1
  %39 = sitofp i32 %38 to float
  %40 = fcmp oge float %34, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %33, %19
  store i32 1, ptr %15, align 4
  br label %129

42:                                               ; preds = %33
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load float, ptr %7, align 4, !tbaa !9
  %45 = load float, ptr %8, align 4, !tbaa !9
  %46 = call float @TCOD_heightmap_get_interpolated_value(ptr noundef %43, float noundef %44, float noundef %45)
  store float %46, ptr %11, align 4, !tbaa !9
  %47 = load float, ptr %11, align 4, !tbaa !9
  %48 = load float, ptr %10, align 4, !tbaa !9
  %49 = fcmp olt float %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %42
  %51 = load float, ptr %10, align 4, !tbaa !9
  store float %51, ptr %11, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %50, %42
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load float, ptr %7, align 4, !tbaa !9
  %55 = fadd float %54, 1.000000e+00
  %56 = load float, ptr %8, align 4, !tbaa !9
  %57 = call float @TCOD_heightmap_get_interpolated_value(ptr noundef %53, float noundef %55, float noundef %56)
  store float %57, ptr %12, align 4, !tbaa !9
  %58 = load float, ptr %12, align 4, !tbaa !9
  %59 = load float, ptr %10, align 4, !tbaa !9
  %60 = fcmp olt float %58, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %52
  %62 = load float, ptr %10, align 4, !tbaa !9
  store float %62, ptr %12, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %61, %52
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load float, ptr %7, align 4, !tbaa !9
  %66 = load float, ptr %8, align 4, !tbaa !9
  %67 = fadd float %66, 1.000000e+00
  %68 = call float @TCOD_heightmap_get_interpolated_value(ptr noundef %64, float noundef %65, float noundef %67)
  store float %68, ptr %13, align 4, !tbaa !9
  %69 = load float, ptr %13, align 4, !tbaa !9
  %70 = load float, ptr %10, align 4, !tbaa !9
  %71 = fcmp olt float %69, %70
  br i1 %71, label %72, label %74

72:                                               ; preds = %63
  %73 = load float, ptr %10, align 4, !tbaa !9
  store float %73, ptr %13, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %72, %63
  %75 = load float, ptr %11, align 4, !tbaa !9
  %76 = load float, ptr %12, align 4, !tbaa !9
  %77 = fsub float %75, %76
  %78 = fmul float 2.550000e+02, %77
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds float, ptr %79, i64 0
  store float %78, ptr %80, align 4, !tbaa !9
  %81 = load float, ptr %11, align 4, !tbaa !9
  %82 = load float, ptr %13, align 4, !tbaa !9
  %83 = fsub float %81, %82
  %84 = fmul float 2.550000e+02, %83
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds float, ptr %85, i64 1
  store float %84, ptr %86, align 4, !tbaa !9
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = getelementptr inbounds float, ptr %87, i64 2
  store float 1.600000e+01, ptr %88, align 4, !tbaa !9
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds float, ptr %89, i64 0
  %91 = load float, ptr %90, align 4, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds float, ptr %92, i64 0
  %94 = load float, ptr %93, align 4, !tbaa !9
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = getelementptr inbounds float, ptr %95, i64 1
  %97 = load float, ptr %96, align 4, !tbaa !9
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = getelementptr inbounds float, ptr %98, i64 1
  %100 = load float, ptr %99, align 4, !tbaa !9
  %101 = fmul float %97, %100
  %102 = call float @llvm.fmuladd.f32(float %91, float %94, float %101)
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  %104 = getelementptr inbounds float, ptr %103, i64 2
  %105 = load float, ptr %104, align 4, !tbaa !9
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = getelementptr inbounds float, ptr %106, i64 2
  %108 = load float, ptr %107, align 4, !tbaa !9
  %109 = call float @llvm.fmuladd.f32(float %105, float %108, float %102)
  %110 = fpext float %109 to double
  %111 = call double @sqrt(double noundef %110) #4
  %112 = fptrunc double %111 to float
  %113 = fdiv float 1.000000e+00, %112
  store float %113, ptr %14, align 4, !tbaa !9
  %114 = load float, ptr %14, align 4, !tbaa !9
  %115 = load ptr, ptr %9, align 8, !tbaa !5
  %116 = getelementptr inbounds float, ptr %115, i64 0
  %117 = load float, ptr %116, align 4, !tbaa !9
  %118 = fmul float %117, %114
  store float %118, ptr %116, align 4, !tbaa !9
  %119 = load float, ptr %14, align 4, !tbaa !9
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  %121 = getelementptr inbounds float, ptr %120, i64 1
  %122 = load float, ptr %121, align 4, !tbaa !9
  %123 = fmul float %122, %119
  store float %123, ptr %121, align 4, !tbaa !9
  %124 = load float, ptr %14, align 4, !tbaa !9
  %125 = load ptr, ptr %9, align 8, !tbaa !5
  %126 = getelementptr inbounds float, ptr %125, i64 2
  %127 = load float, ptr %126, align 4, !tbaa !9
  %128 = fmul float %127, %124
  store float %128, ptr %126, align 4, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %129

129:                                              ; preds = %74, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %130 = load i32, ptr %15, align 4
  switch i32 %130, label %132 [
    i32 0, label %131
    i32 1, label %131
  ]

131:                                              ; preds = %129, %129, %18
  ret void

132:                                              ; preds = %129
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 "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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nounwind uwtable
declare dso_local float @TCOD_heightmap_get_interpolated_value(ptr noundef, float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_heightmap_get_normal(ptr noundef %0, float noundef %1, float noundef %2, ptr nocapture noundef writeonly %3, float noundef %4) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %45, label %6

6:                                                ; preds = %5
  store <2 x float> zeroinitializer, ptr %3, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store float 1.000000e+00, ptr %7, align 4, !tbaa !5
  %8 = load i32, ptr %0, align 8, !tbaa !9
  %9 = add nsw i32 %8, -1
  %10 = sitofp i32 %9 to float
  %11 = fcmp ugt float %10, %1
  br i1 %11, label %12, label %45

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = add nsw i32 %14, -1
  %16 = sitofp i32 %15 to float
  %17 = fcmp ugt float %16, %2
  br i1 %17, label %18, label %45

18:                                               ; preds = %12
  %19 = tail call float @TCOD_heightmap_get_interpolated_value(ptr noundef nonnull %0, float noundef %1, float noundef %2)
  %20 = fcmp olt float %19, %4
  %.0 = select i1 %20, float %4, float %19
  %21 = fadd float %1, 1.000000e+00
  %22 = tail call float @TCOD_heightmap_get_interpolated_value(ptr noundef nonnull %0, float noundef %21, float noundef %2)
  %23 = fadd float %2, 1.000000e+00
  %24 = tail call float @TCOD_heightmap_get_interpolated_value(ptr noundef nonnull %0, float noundef %1, float noundef %23)
  %25 = insertelement <2 x float> poison, float %22, i64 0
  %26 = insertelement <2 x float> %25, float %24, i64 1
  %27 = insertelement <2 x float> poison, float %4, i64 0
  %28 = shufflevector <2 x float> %27, <2 x float> poison, <2 x i32> zeroinitializer
  %29 = fcmp olt <2 x float> %26, %28
  %30 = select <2 x i1> %29, <2 x float> %28, <2 x float> %26
  %31 = insertelement <2 x float> poison, float %.0, i64 0
  %32 = shufflevector <2 x float> %31, <2 x float> poison, <2 x i32> zeroinitializer
  %33 = fsub <2 x float> %32, %30
  %34 = fmul <2 x float> %33, <float 2.550000e+02, float 2.550000e+02>
  %35 = fmul <2 x float> %34, %34
  %36 = extractelement <2 x float> %35, i64 1
  %37 = extractelement <2 x float> %34, i64 0
  %38 = tail call float @llvm.fmuladd.f32(float %37, float %37, float %36)
  %39 = fadd float %38, 2.560000e+02
  %sqrt = tail call float @llvm.sqrt.f32(float %39)
  %40 = fdiv float 1.000000e+00, %sqrt
  %41 = insertelement <2 x float> poison, float %40, i64 0
  %42 = shufflevector <2 x float> %41, <2 x float> poison, <2 x i32> zeroinitializer
  %43 = fmul <2 x float> %34, %42
  store <2 x float> %43, ptr %3, align 4, !tbaa !5
  %44 = fmul float %40, 1.600000e+01
  store float %44, ptr %7, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %18, %12, %6, %5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !11, i64 4}


; Effective O3 passes: AggressiveInstCombinePass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass