; LLVM IR from ARM-software/Arm-2D :: Helper/Source/arm_2d_helper.ll_ (arm_2d_helper_time_half_cos_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 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_helper_time_half_cos_slider = external hidden unnamed_addr constant [92 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

declare i64 @arm_2d_helper_get_system_timestamp() #2

declare float @arm_cos_f32(float noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @__arm_2d_helper_time_half_cos_slider(i32 noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4) #3 {
  %6 = alloca i1, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca float, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %17 = call i64 @arm_2d_helper_get_system_timestamp()
  store i64 %17, ptr %12, align 8, !tbaa !9
  %18 = load ptr, ptr %11, align 8, !tbaa !11
  %19 = icmp ne ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  br label %22

21:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 398, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_time_half_cos_slider) #5
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr %10, align 8, !tbaa !11
  %24 = icmp ne ptr null, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  br label %27

26:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 399, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_time_half_cos_slider) #5
  unreachable

27:                                               ; preds = %25
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %27
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %32, ptr %33, align 4, !tbaa !5
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %83

34:                                               ; preds = %27
  %35 = load ptr, ptr %11, align 8, !tbaa !11
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = icmp eq i64 0, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %34
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !11
  store i64 %39, ptr %40, align 8, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %41, ptr %42, align 4, !tbaa !5
  br label %81

43:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !11
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = sub nsw i64 %44, %46
  store i64 %47, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !5
  %48 = load i64, ptr %14, align 8, !tbaa !9
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = icmp slt i64 %48, %49
  br i1 %50, label %51, label %74

51:                                               ; preds = %43
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  store i32 %54, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %55 = load i64, ptr %14, align 8, !tbaa !9
  %56 = sitofp i64 %55 to float
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = sitofp i64 %57 to float
  %59 = fdiv float %56, %58
  %60 = fmul float %59, 0x400921FB40000000
  store float %60, ptr %16, align 4, !tbaa !13
  %61 = load float, ptr %16, align 4, !tbaa !13
  %62 = call float @arm_cos_f32(float noundef %61)
  %63 = fsub float 1.000000e+00, %62
  %64 = load i32, ptr %15, align 4, !tbaa !5
  %65 = sitofp i32 %64 to float
  %66 = fmul float %63, %65
  %67 = fptosi float %66 to i32
  store i32 %67, ptr %15, align 4, !tbaa !5
  %68 = load i32, ptr %15, align 4, !tbaa !5
  %69 = ashr i32 %68, 1
  store i32 %69, ptr %15, align 4, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %15, align 4, !tbaa !5
  %72 = add nsw i32 %70, %71
  %73 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %72, ptr %73, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %77

74:                                               ; preds = %43
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %75, ptr %76, align 4, !tbaa !5
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %78

77:                                               ; preds = %51
  store i32 0, ptr %13, align 4
  br label %78

78:                                               ; preds = %77, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %79 = load i32, ptr %13, align 4
  switch i32 %79, label %83 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80, %38
  br label %82

82:                                               ; preds = %81
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %83

83:                                               ; preds = %82, %78, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %84 = load i1, ptr %6, align 1
  ret i1 %84
}

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 = { "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 = { 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 #4 = { nounwind }
attributes #5 = { 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)"}
!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}


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

declare i64 @arm_2d_helper_get_system_timestamp() local_unnamed_addr #0

declare float @arm_cos_f32(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @__arm_2d_helper_time_half_cos_slider(i32 noundef %0, i32 noundef %1, i64 noundef %2, ptr nocapture noundef nonnull writeonly %3, ptr nocapture noundef nonnull %4) local_unnamed_addr #1 {
  %6 = tail call i64 @arm_2d_helper_get_system_timestamp() #2
  %7 = icmp eq i32 %0, %1
  br i1 %7, label %.critedge, label %8

8:                                                ; preds = %5
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  store i64 %6, ptr %4, align 8, !tbaa !5
  br label %.critedge

12:                                               ; preds = %8
  %13 = sub nsw i64 %6, %9
  %14 = icmp slt i64 %13, %2
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %12
  %16 = sub nsw i32 %1, %0
  %17 = sitofp i64 %13 to float
  %18 = sitofp i64 %2 to float
  %19 = fdiv float %17, %18
  %20 = fmul float %19, 0x400921FB40000000
  %21 = tail call float @arm_cos_f32(float noundef %20) #2
  %22 = fsub float 1.000000e+00, %21
  %23 = sitofp i32 %16 to float
  %24 = fmul float %22, %23
  %25 = fptosi float %24 to i32
  %26 = ashr i32 %25, 1
  %27 = add nsw i32 %26, %0
  br label %.critedge

.critedge:                                        ; preds = %12, %5, %11, %15
  %.sink = phi i32 [ %0, %11 ], [ %27, %15 ], [ %0, %5 ], [ %1, %12 ]
  %.1 = phi i1 [ false, %11 ], [ false, %15 ], [ true, %5 ], [ true, %12 ]
  store i32 %.sink, ptr %3, align 4, !tbaa !9
  ret i1 %.1
}

attributes #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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