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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @__arm_2d_helper_time_liner_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
  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
  %16 = load ptr, ptr %11, align 8, !tbaa !11
  %17 = icmp ne ptr null, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  br label %20

19:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 247, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_time_liner_slider) #4
  unreachable

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

23:                                               ; preds = %20
  br label %25

24:                                               ; preds = %20
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 248, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_time_liner_slider) #4
  unreachable

25:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %26 = call i64 @arm_2d_helper_get_system_timestamp()
  store i64 %26, ptr %12, align 8, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %33

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

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

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

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

50:                                               ; preds = %42
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  store i32 %53, ptr %15, align 4, !tbaa !5
  %54 = load i64, ptr %14, align 8, !tbaa !9
  %55 = load i32, ptr %15, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %54, %56
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = sdiv i64 %57, %58
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %15, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %15, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %63, ptr %64, align 4, !tbaa !5
  br label %68

65:                                               ; preds = %42
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !11
  store i32 %66, ptr %67, align 4, !tbaa !5
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %69

68:                                               ; preds = %50
  store i32 0, ptr %13, align 4
  br label %69

69:                                               ; preds = %68, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %70 = load i32, ptr %13, align 4
  switch i32 %70, label %74 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71, %37
  br label %73

73:                                               ; preds = %72
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %74

74:                                               ; preds = %73, %69, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %75 = load i1, ptr %6, align 1
  ret i1 %75
}

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 = { noreturn nounwind }
attributes #5 = { 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}


; 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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @__arm_2d_helper_time_liner_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 = sext i32 %16 to i64
  %18 = mul nsw i64 %13, %17
  %19 = sdiv i64 %18, %2
  %20 = trunc i64 %19 to i32
  %21 = add nsw i32 %20, %0
  br label %.critedge

.critedge:                                        ; preds = %12, %5, %11, %15
  %.sink = phi i32 [ %0, %11 ], [ %21, %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,SROAPass,SimplifyCFGPass,TailCallElimPass