; LLVM IR from ARM-software/Arm-2D :: Helper/Source/arm_2d_helper.ll_ (arm_2d_helper_colour_slider)

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

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_helper_colour_slider = external hidden unnamed_addr constant [77 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

21:                                               ; preds = %4
  br label %23

22:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 346, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_colour_slider) #3
  unreachable

23:                                               ; preds = %21
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp sge i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %28, ptr %5, align 4
  br label %77

29:                                               ; preds = %23
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp sle i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %33, ptr %5, align 4
  br label %77

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr %6, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr %7, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store ptr %10, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %72, %34
  %36 = load i32, ptr %14, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 4
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %75

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = zext i8 %44 to i64
  store i64 %45, ptr %15, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = load i32, ptr %14, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = zext i8 %50 to i64
  store i64 %51, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %52 = load i64, ptr %16, align 8, !tbaa !12
  %53 = load i64, ptr %15, align 8, !tbaa !12
  %54 = sub nsw i64 %52, %53
  store i64 %54, ptr %17, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %55 = load i64, ptr %17, align 8, !tbaa !12
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %55, %57
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = sdiv i64 %58, %60
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %18, align 4, !tbaa !5
  %63 = load i32, ptr %18, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = load i64, ptr %15, align 8, !tbaa !12
  %66 = add nsw i64 %64, %65
  %67 = trunc i64 %66 to i8
  %68 = load ptr, ptr %13, align 8, !tbaa !9
  %69 = load i32, ptr %14, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %68, i64 %70
  store i8 %67, ptr %71, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %72

72:                                               ; preds = %39
  %73 = load i32, ptr %14, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %14, align 4, !tbaa !5
  br label %35, !llvm.loop !14

75:                                               ; preds = %38
  %76 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %76, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %77

77:                                               ; preds = %75, %32, %27
  %78 = load i32, ptr %5, align 4
  ret i32 %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #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 = { noreturn nounwind }
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 = !{!"int", !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_helper_colour_slider = external hidden unnamed_addr constant [77 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @__arm_2d_helper_colour_slider(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %.sroa.226.0.extract.shift = lshr i32 %0, 8
  %.sroa.327.0.extract.shift = lshr i32 %0, 16
  %.sroa.428.0.extract.shift = lshr i32 %0, 24
  %.sroa.2.0.extract.shift = lshr i32 %1, 8
  %.sroa.3.0.extract.shift = lshr i32 %1, 16
  %.sroa.4.0.extract.shift = lshr i32 %1, 24
  %.sroa.4.0.extract.trunc = zext nneg i32 %.sroa.4.0.extract.shift to i64
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 346, ptr noundef nonnull @__PRETTY_FUNCTION__.__arm_2d_helper_colour_slider) #2
  unreachable

7:                                                ; preds = %4
  %.not = icmp slt i32 %3, %2
  br i1 %.not, label %8, label %43

8:                                                ; preds = %7
  %9 = icmp slt i32 %3, 1
  br i1 %9, label %43, label %10

10:                                               ; preds = %8
  %11 = zext nneg i32 %3 to i64
  %12 = zext nneg i32 %2 to i64
  %.sroa.025.0.extract.trunc.mask = and i32 %0, 255
  %13 = zext nneg i32 %.sroa.025.0.extract.trunc.mask to i64
  %14 = and i32 %1, 255
  %15 = zext nneg i32 %14 to i64
  %16 = sub nsw i64 %15, %13
  %17 = mul nsw i64 %16, %11
  %18 = sdiv i64 %17, %12
  %19 = trunc i64 %18 to i32
  %20 = add i32 %19, %0
  %.sroa.226.0.extract.trunc.mask = and i32 %.sroa.226.0.extract.shift, 255
  %21 = zext nneg i32 %.sroa.226.0.extract.trunc.mask to i64
  %22 = and i32 %.sroa.2.0.extract.shift, 255
  %23 = zext nneg i32 %22 to i64
  %24 = sub nsw i64 %23, %21
  %25 = mul nsw i64 %24, %11
  %26 = sdiv i64 %25, %12
  %27 = trunc i64 %26 to i32
  %28 = add i32 %.sroa.226.0.extract.shift, %27
  %.sroa.327.0.extract.trunc.mask = and i32 %.sroa.327.0.extract.shift, 255
  %29 = zext nneg i32 %.sroa.327.0.extract.trunc.mask to i64
  %30 = and i32 %.sroa.3.0.extract.shift, 255
  %31 = zext nneg i32 %30 to i64
  %32 = sub nsw i64 %31, %29
  %33 = mul nsw i64 %32, %11
  %34 = sdiv i64 %33, %12
  %35 = trunc i64 %34 to i32
  %36 = add i32 %.sroa.327.0.extract.shift, %35
  %37 = zext nneg i32 %.sroa.428.0.extract.shift to i64
  %38 = sub nsw i64 %.sroa.4.0.extract.trunc, %37
  %39 = mul nsw i64 %38, %11
  %40 = sdiv i64 %39, %12
  %41 = trunc i64 %40 to i32
  %42 = add i32 %.sroa.428.0.extract.shift, %41
  %.sroa.7.0.insert.ext = shl i32 %42, 24
  %.sroa.6.0.insert.ext = shl i32 %36, 16
  %.sroa.6.0.insert.shift = and i32 %.sroa.6.0.insert.ext, 16711680
  %.sroa.6.0.insert.insert = or disjoint i32 %.sroa.7.0.insert.ext, %.sroa.6.0.insert.shift
  %.sroa.5.0.insert.ext = shl i32 %28, 8
  %.sroa.5.0.insert.shift = and i32 %.sroa.5.0.insert.ext, 65280
  %.sroa.5.0.insert.insert = or disjoint i32 %.sroa.6.0.insert.insert, %.sroa.5.0.insert.shift
  %.sroa.0.0.insert.ext = and i32 %20, 255
  %.sroa.0.0.insert.insert = or disjoint i32 %.sroa.5.0.insert.insert, %.sroa.0.0.insert.ext
  br label %43

43:                                               ; preds = %8, %7, %10
  %.0 = phi i32 [ %.sroa.0.0.insert.insert, %10 ], [ %1, %7 ], [ %0, %8 ]
  ret i32 %.0
}

attributes #0 = { noreturn 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 #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 = { noreturn 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass