; LLVM IR from csc-training/mpi-introduction :: heat-equation/common (pngwriter)

; 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.pixel_t = type { i8, i8, i8 }

@heat_colormap = external hidden global [256 x [3 x i32]], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @cmap(double noundef %0, double noundef %1, double noundef %2, ptr noundef %3) #1 {
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store double %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !5
  store double %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load double, ptr %5, align 8, !tbaa !5
  %11 = load double, ptr %6, align 8, !tbaa !5
  %12 = load double, ptr %7, align 8, !tbaa !5
  %13 = call double @llvm.fmuladd.f64(double %10, double %11, double %12)
  %14 = fptosi double %13 to i32
  store i32 %14, ptr %9, align 4, !tbaa !11
  %15 = load i32, ptr %9, align 4, !tbaa !11
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.pixel_t, ptr %18, i32 0, i32 0
  store i8 0, ptr %19, align 1, !tbaa !13
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.pixel_t, ptr %20, i32 0, i32 1
  store i8 0, ptr %21, align 1, !tbaa !15
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.pixel_t, ptr %22, i32 0, i32 2
  store i8 -1, ptr %23, align 1, !tbaa !16
  br label %60

24:                                               ; preds = %4
  %25 = load i32, ptr %9, align 4, !tbaa !11
  %26 = icmp sgt i32 %25, 255
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.pixel_t, ptr %28, i32 0, i32 0
  store i8 -1, ptr %29, align 1, !tbaa !13
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.pixel_t, ptr %30, i32 0, i32 1
  store i8 0, ptr %31, align 1, !tbaa !15
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.pixel_t, ptr %32, i32 0, i32 2
  store i8 0, ptr %33, align 1, !tbaa !16
  br label %59

34:                                               ; preds = %24
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x [3 x i32]], ptr @heat_colormap, i64 0, i64 %36
  %38 = getelementptr inbounds [3 x i32], ptr %37, i64 0, i64 0
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = trunc i32 %39 to i8
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.pixel_t, ptr %41, i32 0, i32 0
  store i8 %40, ptr %42, align 1, !tbaa !13
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [256 x [3 x i32]], ptr @heat_colormap, i64 0, i64 %44
  %46 = getelementptr inbounds [3 x i32], ptr %45, i64 0, i64 1
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %8, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.pixel_t, ptr %49, i32 0, i32 1
  store i8 %48, ptr %50, align 1, !tbaa !15
  %51 = load i32, ptr %9, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [256 x [3 x i32]], ptr @heat_colormap, i64 0, i64 %52
  %54 = getelementptr inbounds [3 x i32], ptr %53, i64 0, i64 2
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = trunc i32 %55 to i8
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.pixel_t, ptr %57, i32 0, i32 2
  store i8 %56, ptr %58, align 1, !tbaa !16
  br label %59

59:                                               ; preds = %34, %27
  br label %60

60:                                               ; preds = %59, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; 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 double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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) }
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!14, !7, i64 1}
!16 = !{!14, !7, 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"

@heat_colormap = external hidden local_unnamed_addr global [256 x [3 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @cmap(double noundef %0, double noundef %1, double noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call double @llvm.fmuladd.f64(double %0, double %1, double %2)
  %6 = fptosi double %5 to i32
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  store i8 0, ptr %3, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 0, ptr %9, align 1, !tbaa !9
  br label %26

10:                                               ; preds = %4
  %11 = icmp ugt i32 %6, 255
  br i1 %11, label %12, label %14

12:                                               ; preds = %10
  store i8 -1, ptr %3, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 0, ptr %13, align 1, !tbaa !9
  br label %26

14:                                               ; preds = %10
  %15 = zext nneg i32 %6 to i64
  %16 = getelementptr inbounds [256 x [3 x i32]], ptr @heat_colormap, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !10
  %18 = trunc i32 %17 to i8
  store i8 %18, ptr %3, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %16, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %21, ptr %22, align 1, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %16, i64 8
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = trunc i32 %24 to i8
  br label %26

26:                                               ; preds = %12, %14, %8
  %.sink = phi i8 [ 0, %12 ], [ %25, %14 ], [ -1, %8 ]
  %27 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %.sink, ptr %27, align 1, !tbaa !12
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) 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 = { mustprogress 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 1}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!6, !7, i64 2}


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