; 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
define dso_local void @TCOD_heightmap_add_fbm(ptr noundef %0, ptr noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6, float noundef %7, float noundef %8) #2 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca float, align 4
  %19 = alloca float, align 4
  %20 = alloca float, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca [2 x float], align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store float %2, ptr %12, align 4, !tbaa !9
  store float %3, ptr %13, align 4, !tbaa !9
  store float %4, ptr %14, align 4, !tbaa !9
  store float %5, ptr %15, align 4, !tbaa !9
  store float %6, ptr %16, align 4, !tbaa !9
  store float %7, ptr %17, align 4, !tbaa !9
  store float %8, ptr %18, align 4, !tbaa !9
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %9
  br label %99

28:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %29 = load float, ptr %12, align 4, !tbaa !9
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = sitofp i32 %32 to float
  %34 = fdiv float %29, %33
  store float %34, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %35 = load float, ptr %13, align 4, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = sitofp i32 %38 to float
  %40 = fdiv float %35, %39
  store float %40, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !15
  br label %41

41:                                               ; preds = %95, %28
  %42 = load i32, ptr %21, align 4, !tbaa !15
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  store i32 2, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %98

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  store i32 0, ptr %23, align 4, !tbaa !15
  br label %49

49:                                               ; preds = %91, %48
  %50 = load i32, ptr %23, align 4, !tbaa !15
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %49
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  br label %94

56:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #4
  %57 = load i32, ptr %23, align 4, !tbaa !15
  %58 = sitofp i32 %57 to float
  %59 = load float, ptr %14, align 4, !tbaa !9
  %60 = fadd float %58, %59
  %61 = load float, ptr %19, align 4, !tbaa !9
  %62 = fmul float %60, %61
  store float %62, ptr %24, align 4, !tbaa !9
  %63 = getelementptr inbounds float, ptr %24, i64 1
  %64 = load i32, ptr %21, align 4, !tbaa !15
  %65 = sitofp i32 %64 to float
  %66 = load float, ptr %15, align 4, !tbaa !9
  %67 = fadd float %65, %66
  %68 = load float, ptr %20, align 4, !tbaa !9
  %69 = fmul float %67, %68
  store float %69, ptr %63, align 4, !tbaa !9
  %70 = load float, ptr %17, align 4, !tbaa !9
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds [2 x float], ptr %24, i64 0, i64 0
  %73 = load float, ptr %16, align 4, !tbaa !9
  %74 = call float @TCOD_noise_get_fbm(ptr noundef %71, ptr noundef %72, float noundef %73)
  %75 = load float, ptr %18, align 4, !tbaa !9
  %76 = call float @llvm.fmuladd.f32(float %74, float %75, float %70)
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load i32, ptr %23, align 4, !tbaa !15
  %81 = load i32, ptr %21, align 4, !tbaa !15
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.TCOD_heightmap_t, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !11
  %85 = mul nsw i32 %81, %84
  %86 = add nsw i32 %80, %85
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds float, ptr %79, i64 %87
  %89 = load float, ptr %88, align 4, !tbaa !9
  %90 = fadd float %89, %76
  store float %90, ptr %88, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #4
  br label %91

91:                                               ; preds = %56
  %92 = load i32, ptr %23, align 4, !tbaa !15
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %23, align 4, !tbaa !15
  br label %49, !llvm.loop !17

94:                                               ; preds = %55
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %21, align 4, !tbaa !15
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %21, align 4, !tbaa !15
  br label %41, !llvm.loop !19

98:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %99

99:                                               ; preds = %98, %27
  ret void
}

declare float @TCOD_noise_get_fbm(ptr noundef, ptr noundef, float 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 = { "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}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_heightmap_add_fbm(ptr noundef readonly %0, ptr noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6, float noundef %7, float noundef %8) local_unnamed_addr #2 {
  %10 = alloca [2 x float], align 4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %11

11:                                               ; preds = %9
  %12 = load i32, ptr %0, align 8, !tbaa !5
  %13 = sitofp i32 %12 to float
  %14 = fdiv float %2, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = sitofp i32 %16 to float
  %18 = fdiv float %3, %17
  %19 = icmp sgt i32 %16, 0
  br i1 %19, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %11
  %20 = getelementptr inbounds i8, ptr %10, i64 4
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = icmp sgt i32 %12, 0
  br i1 %22, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %23 = phi i32 [ %29, %._crit_edge ], [ %16, %.preheader.lr.ph ]
  %24 = phi i32 [ %30, %._crit_edge ], [ %12, %.preheader.lr.ph ]
  %.02427 = phi i32 [ %31, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %26 = uitofp nneg i32 %.02427 to float
  %27 = fadd float %26, %5
  %28 = fmul float %18, %27
  br label %33

._crit_edge.loopexit:                             ; preds = %33
  %.pre = load i32, ptr %15, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %29 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %23, %.preheader ]
  %30 = phi i32 [ %40, %._crit_edge.loopexit ], [ %24, %.preheader ]
  %31 = add nuw nsw i32 %.02427, 1
  %32 = icmp slt i32 %31, %29
  br i1 %32, label %.preheader, label %.loopexit, !llvm.loop !12

33:                                               ; preds = %.lr.ph, %33
  %.026 = phi i32 [ 0, %.lr.ph ], [ %47, %33 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  %34 = uitofp nneg i32 %.026 to float
  %35 = fadd float %34, %4
  %36 = fmul float %14, %35
  store float %36, ptr %10, align 4, !tbaa !15
  store float %28, ptr %20, align 4, !tbaa !15
  %37 = call float @TCOD_noise_get_fbm(ptr noundef %1, ptr noundef nonnull %10, float noundef %6) #4
  %38 = call float @llvm.fmuladd.f32(float %37, float %8, float %7)
  %39 = load ptr, ptr %21, align 8, !tbaa !17
  %40 = load i32, ptr %0, align 8, !tbaa !5
  %41 = mul nsw i32 %40, %.02427
  %42 = add nsw i32 %41, %.026
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %39, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !15
  %46 = fadd float %38, %45
  store float %46, ptr %44, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  %47 = add nuw nsw i32 %.026, 1
  %48 = icmp slt i32 %47, %40
  br i1 %48, label %33, label %._crit_edge.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %._crit_edge, %.preheader.lr.ph, %11, %9
  ret void
}

declare float @TCOD_noise_get_fbm(ptr noundef, ptr noundef, float noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!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 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.unswitch.partial.disable"}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = !{!6, !10, i64 8}
!18 = distinct !{!18, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass