; LLVM IR from arasgungore/filters-and-fractals :: main (adjustContrast)

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

; 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: nounwind uwtable
declare dso_local double @truncateRGB(double noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @adjustContrast(ptr noundef %0, double noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fmul double %10, 2.550000e+00
  store double %11, ptr %4, align 8, !tbaa !9
  %12 = load double, ptr %4, align 8, !tbaa !9
  %13 = fcmp olt double %12, -2.550000e+02
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store double -2.550000e+02, ptr %4, align 8, !tbaa !9
  br label %20

15:                                               ; preds = %2
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = fcmp ogt double %16, 2.550000e+02
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store double 2.550000e+02, ptr %4, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %18, %15
  br label %20

20:                                               ; preds = %19, %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %21 = load double, ptr %4, align 8, !tbaa !9
  %22 = fadd double %21, 2.550000e+02
  %23 = fmul double 2.590000e+02, %22
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fsub double 2.590000e+02, %24
  %26 = fmul double 2.550000e+02, %25
  %27 = fdiv double %23, %26
  store double %27, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %108, %20
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.PPMImage, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PPMImage, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = mul i32 %32, %35
  %37 = icmp ult i32 %29, %36
  br i1 %37, label %38, label %111

38:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %39 = load double, ptr %5, align 8, !tbaa !9
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PPMImage, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load i32, ptr %6, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.PPMPixel, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.PPMPixel, ptr %45, i32 0, i32 0
  %47 = load i8, ptr %46, align 1, !tbaa !17
  %48 = zext i8 %47 to i32
  %49 = sub nsw i32 %48, 128
  %50 = sitofp i32 %49 to double
  %51 = call double @llvm.fmuladd.f64(double %39, double %50, double 1.280000e+02)
  store double %51, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.PPMImage, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load i32, ptr %6, align 4, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds %struct.PPMPixel, ptr %55, i64 %57
  %59 = getelementptr inbounds %struct.PPMPixel, ptr %58, i32 0, i32 1
  %60 = load i8, ptr %59, align 1, !tbaa !19
  %61 = zext i8 %60 to i32
  %62 = sub nsw i32 %61, 128
  %63 = sitofp i32 %62 to double
  %64 = call double @llvm.fmuladd.f64(double %52, double %63, double 1.280000e+02)
  store double %64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %65 = load double, ptr %5, align 8, !tbaa !9
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.PPMImage, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = load i32, ptr %6, align 4, !tbaa !11
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds %struct.PPMPixel, ptr %68, i64 %70
  %72 = getelementptr inbounds %struct.PPMPixel, ptr %71, i32 0, i32 2
  %73 = load i8, ptr %72, align 1, !tbaa !20
  %74 = zext i8 %73 to i32
  %75 = sub nsw i32 %74, 128
  %76 = sitofp i32 %75 to double
  %77 = call double @llvm.fmuladd.f64(double %65, double %76, double 1.280000e+02)
  store double %77, ptr %9, align 8, !tbaa !9
  %78 = load double, ptr %7, align 8, !tbaa !9
  %79 = call double @truncateRGB(double noundef %78)
  %80 = fptoui double %79 to i8
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.PPMImage, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !16
  %84 = load i32, ptr %6, align 4, !tbaa !11
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds %struct.PPMPixel, ptr %83, i64 %85
  %87 = getelementptr inbounds %struct.PPMPixel, ptr %86, i32 0, i32 0
  store i8 %80, ptr %87, align 1, !tbaa !17
  %88 = load double, ptr %8, align 8, !tbaa !9
  %89 = call double @truncateRGB(double noundef %88)
  %90 = fptoui double %89 to i8
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.PPMImage, ptr %91, i32 0, i32 2
  %93 = load ptr, ptr %92, align 8, !tbaa !16
  %94 = load i32, ptr %6, align 4, !tbaa !11
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds %struct.PPMPixel, ptr %93, i64 %95
  %97 = getelementptr inbounds %struct.PPMPixel, ptr %96, i32 0, i32 1
  store i8 %90, ptr %97, align 1, !tbaa !19
  %98 = load double, ptr %9, align 8, !tbaa !9
  %99 = call double @truncateRGB(double noundef %98)
  %100 = fptoui double %99 to i8
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.PPMImage, ptr %101, i32 0, i32 2
  %103 = load ptr, ptr %102, align 8, !tbaa !16
  %104 = load i32, ptr %6, align 4, !tbaa !11
  %105 = zext i32 %104 to i64
  %106 = getelementptr inbounds %struct.PPMPixel, ptr %103, i64 %105
  %107 = getelementptr inbounds %struct.PPMPixel, ptr %106, i32 0, i32 2
  store i8 %100, ptr %107, align 1, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %108

108:                                              ; preds = %38
  %109 = load i32, ptr %6, align 4, !tbaa !11
  %110 = add i32 %109, 1
  store i32 %110, ptr %6, align 4, !tbaa !11
  br label %28, !llvm.loop !21

111:                                              ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !6, i64 8}
!15 = !{!14, !12, i64 4}
!16 = !{!14, !6, i64 8}
!17 = !{!18, !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!19 = !{!18, !7, i64 1}
!20 = !{!18, !7, i64 2}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
declare dso_local double @truncateRGB(double noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @adjustContrast(ptr nocapture noundef readonly %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fmul double %1, 2.550000e+00
  %4 = fcmp olt double %3, -2.550000e+02
  br i1 %4, label %8, label %5

5:                                                ; preds = %2
  %6 = fcmp ogt double %3, 2.550000e+02
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  br label %8

8:                                                ; preds = %2, %5, %7
  %.0 = phi double [ 2.550000e+02, %7 ], [ %3, %5 ], [ -2.550000e+02, %2 ]
  %9 = fadd double %.0, 2.550000e+02
  %10 = fmul double %9, 2.590000e+02
  %11 = fsub double 2.590000e+02, %.0
  %12 = fmul double %11, 2.550000e+02
  %13 = fdiv double %10, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %0, align 8, !tbaa !5
  %16 = load i32, ptr %14, align 4, !tbaa !11
  %17 = mul i32 %16, %15
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %18, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %20 = phi ptr [ %.pre, %.lr.ph ], [ %49, %19 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %21 = getelementptr inbounds %struct.PPMPixel, ptr %20, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !13
  %23 = zext i8 %22 to i32
  %24 = add nsw i32 %23, -128
  %25 = sitofp i32 %24 to double
  %26 = tail call double @llvm.fmuladd.f64(double %13, double %25, double 1.280000e+02)
  %27 = getelementptr inbounds i8, ptr %21, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  %30 = add nsw i32 %29, -128
  %31 = sitofp i32 %30 to double
  %32 = tail call double @llvm.fmuladd.f64(double %13, double %31, double 1.280000e+02)
  %33 = getelementptr inbounds i8, ptr %21, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = zext i8 %34 to i32
  %36 = add nsw i32 %35, -128
  %37 = sitofp i32 %36 to double
  %38 = tail call double @llvm.fmuladd.f64(double %13, double %37, double 1.280000e+02)
  %39 = tail call double @truncateRGB(double noundef %26)
  %40 = fptoui double %39 to i8
  %41 = load ptr, ptr %18, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.PPMPixel, ptr %41, i64 %indvars.iv
  store i8 %40, ptr %42, align 1, !tbaa !13
  %43 = tail call double @truncateRGB(double noundef %32)
  %44 = fptoui double %43 to i8
  %45 = load ptr, ptr %18, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.PPMPixel, ptr %45, i64 %indvars.iv, i32 1
  store i8 %44, ptr %46, align 1, !tbaa !15
  %47 = tail call double @truncateRGB(double noundef %38)
  %48 = fptoui double %47 to i8
  %49 = load ptr, ptr %18, align 8, !tbaa !12
  %50 = getelementptr inbounds %struct.PPMPixel, ptr %49, i64 %indvars.iv, i32 2
  store i8 %48, ptr %50, align 1, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = load i32, ptr %0, align 8, !tbaa !5
  %52 = load i32, ptr %14, align 4, !tbaa !11
  %53 = mul i32 %52, %51
  %54 = zext i32 %53 to i64
  %55 = icmp ult i64 %indvars.iv.next, %54
  br i1 %55, label %19, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %19, %8
  ret void
}

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 = { 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 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 = !{!6, !10, i64 8}
!13 = !{!14, !8, i64 0}
!14 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!15 = !{!14, !8, i64 1}
!16 = !{!14, !8, i64 2}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass