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

; 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: nounwind uwtable
define dso_local void @adjustBrightness(ptr noundef %0, double noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %6 = load double, ptr %4, align 8, !tbaa !9
  %7 = fmul double %6, 2.550000e+00
  store double %7, ptr %4, align 8, !tbaa !9
  %8 = load double, ptr %4, align 8, !tbaa !9
  %9 = fcmp olt double %8, -2.550000e+02
  br i1 %9, label %10, label %11

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

11:                                               ; preds = %2
  %12 = load double, ptr %4, align 8, !tbaa !9
  %13 = fcmp ogt double %12, 2.550000e+02
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %14, %11
  br label %16

16:                                               ; preds = %15, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %91, %16
  %18 = load i32, ptr %5, align 4, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PPMImage, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.PPMImage, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = mul i32 %21, %24
  %26 = icmp ult i32 %18, %25
  br i1 %26, label %27, label %94

27:                                               ; preds = %17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PPMImage, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load i32, ptr %5, align 4, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %struct.PPMPixel, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.PPMPixel, ptr %33, i32 0, i32 0
  %35 = load i8, ptr %34, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = sitofp i32 %36 to double
  %38 = load double, ptr %4, align 8, !tbaa !9
  %39 = fadd double %37, %38
  %40 = call double @truncateRGB(double noundef %39)
  %41 = fptoui double %40 to i8
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.PPMImage, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %5, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.PPMPixel, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.PPMPixel, ptr %47, i32 0, i32 0
  store i8 %41, ptr %48, align 1, !tbaa !17
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.PPMImage, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load i32, ptr %5, align 4, !tbaa !11
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct.PPMPixel, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.PPMPixel, ptr %54, i32 0, i32 1
  %56 = load i8, ptr %55, align 1, !tbaa !19
  %57 = zext i8 %56 to i32
  %58 = sitofp i32 %57 to double
  %59 = load double, ptr %4, align 8, !tbaa !9
  %60 = fadd double %58, %59
  %61 = call double @truncateRGB(double noundef %60)
  %62 = fptoui double %61 to i8
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.PPMImage, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !16
  %66 = load i32, ptr %5, align 4, !tbaa !11
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds %struct.PPMPixel, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.PPMPixel, ptr %68, i32 0, i32 1
  store i8 %62, ptr %69, align 1, !tbaa !19
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.PPMImage, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !16
  %73 = load i32, ptr %5, align 4, !tbaa !11
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds %struct.PPMPixel, ptr %72, i64 %74
  %76 = getelementptr inbounds %struct.PPMPixel, ptr %75, i32 0, i32 2
  %77 = load i8, ptr %76, align 1, !tbaa !20
  %78 = zext i8 %77 to i32
  %79 = sitofp i32 %78 to double
  %80 = load double, ptr %4, align 8, !tbaa !9
  %81 = fadd double %79, %80
  %82 = call double @truncateRGB(double noundef %81)
  %83 = fptoui double %82 to i8
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.PPMImage, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !16
  %87 = load i32, ptr %5, align 4, !tbaa !11
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds %struct.PPMPixel, ptr %86, i64 %88
  %90 = getelementptr inbounds %struct.PPMPixel, ptr %89, i32 0, i32 2
  store i8 %83, ptr %90, align 1, !tbaa !20
  br label %91

91:                                               ; preds = %27
  %92 = load i32, ptr %5, align 4, !tbaa !11
  %93 = add i32 %92, 1
  store i32 %93, ptr %5, align 4, !tbaa !11
  br label %17, !llvm.loop !21

94:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  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 = { 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: nounwind uwtable
define dso_local void @adjustBrightness(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
  %.021 = phi double [ 2.550000e+02, %7 ], [ %3, %5 ], [ -2.550000e+02, %2 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %11 = load i32, ptr %9, align 4, !tbaa !11
  %12 = mul i32 %11, %10
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

14:                                               ; preds = %.lr.ph, %14
  %15 = phi ptr [ %.pre, %.lr.ph ], [ %38, %14 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %16 = getelementptr inbounds %struct.PPMPixel, ptr %15, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !13
  %18 = uitofp i8 %17 to double
  %19 = fadd double %.021, %18
  %20 = tail call double @truncateRGB(double noundef %19)
  %21 = fptoui double %20 to i8
  %22 = load ptr, ptr %13, align 8, !tbaa !12
  %23 = getelementptr inbounds %struct.PPMPixel, ptr %22, i64 %indvars.iv
  store i8 %21, ptr %23, align 1, !tbaa !13
  %24 = getelementptr inbounds %struct.PPMPixel, ptr %22, i64 %indvars.iv, i32 1
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = uitofp i8 %25 to double
  %27 = fadd double %.021, %26
  %28 = tail call double @truncateRGB(double noundef %27)
  %29 = fptoui double %28 to i8
  %30 = load ptr, ptr %13, align 8, !tbaa !12
  %31 = getelementptr inbounds %struct.PPMPixel, ptr %30, i64 %indvars.iv, i32 1
  store i8 %29, ptr %31, align 1, !tbaa !15
  %32 = getelementptr inbounds %struct.PPMPixel, ptr %30, i64 %indvars.iv, i32 2
  %33 = load i8, ptr %32, align 1, !tbaa !16
  %34 = uitofp i8 %33 to double
  %35 = fadd double %.021, %34
  %36 = tail call double @truncateRGB(double noundef %35)
  %37 = fptoui double %36 to i8
  %38 = load ptr, ptr %13, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.PPMPixel, ptr %38, i64 %indvars.iv, i32 2
  store i8 %37, ptr %39, align 1, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i32, ptr %0, align 8, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = mul i32 %41, %40
  %43 = zext i32 %42 to i64
  %44 = icmp ult i64 %indvars.iv.next, %43
  br i1 %44, label %14, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %14, %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" }

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass