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

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

@s_tHelper = external hidden global %struct.anon, align 8
@__const.arm_2d_helper_init.c_chStartTime = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_init() #0 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [9 x i8], align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #5
  store i8 1, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store ptr null, ptr %3, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %15, %0
  %11 = load ptr, ptr %3, align 8, !tbaa !11
  %12 = getelementptr inbounds i32, ptr %11, i32 1
  store ptr %12, ptr %3, align 8, !tbaa !11
  %13 = icmp eq ptr %11, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %19

15:                                               ; preds = %10
  %16 = load i8, ptr @s_tHelper, align 8, !tbaa !13, !range !16, !noundef !17
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i8
  store i8 %18, ptr %1, align 1, !tbaa !5
  store i8 1, ptr @s_tHelper, align 8, !tbaa !13
  br label %10, !llvm.loop !18

19:                                               ; preds = %14
  %20 = load i8, ptr %1, align 1, !tbaa !5, !range !16, !noundef !17
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 1, ptr %4, align 4
  br label %60

23:                                               ; preds = %19
  %24 = call i32 @arm_2d_helper_get_reference_clock_frequency()
  %25 = zext i32 %24 to i64
  %26 = udiv i64 %25, 1000
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr getelementptr inbounds (%struct.anon, ptr @s_tHelper, i32 0, i32 1), align 4, !tbaa !20
  %28 = load i32, ptr getelementptr inbounds (%struct.anon, ptr @s_tHelper, i32 0, i32 1), align 4, !tbaa !20
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i32 1, ptr getelementptr inbounds (%struct.anon, ptr @s_tHelper, i32 0, i32 1), align 4, !tbaa !20
  br label %31

31:                                               ; preds = %30, %23
  call void @arm_2d_helper_built_in_init()
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 9, ptr %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 @__const.arm_2d_helper_init.c_chStartTime, i64 9, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  %33 = getelementptr inbounds [9 x i8], ptr %5, i64 0, i64 0
  %34 = call zeroext i8 @__convert_2digits_bdc(ptr noundef %33)
  store i8 %34, ptr %6, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  %35 = getelementptr inbounds [9 x i8], ptr %5, i64 0, i64 3
  %36 = call zeroext i8 @__convert_2digits_bdc(ptr noundef %35)
  store i8 %36, ptr %7, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  %37 = getelementptr inbounds [9 x i8], ptr %5, i64 0, i64 6
  %38 = call zeroext i8 @__convert_2digits_bdc(ptr noundef %37)
  store i8 %38, ptr %8, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %39 = load i8, ptr %8, align 1, !tbaa !21
  %40 = zext i8 %39 to i64
  %41 = mul i64 %40, 1000
  store i64 %41, ptr %9, align 8, !tbaa !22
  %42 = load i8, ptr %7, align 1, !tbaa !21
  %43 = zext i8 %42 to i64
  %44 = mul i64 %43, 60
  %45 = mul i64 %44, 1000
  %46 = load i64, ptr %9, align 8, !tbaa !22
  %47 = add i64 %46, %45
  store i64 %47, ptr %9, align 8, !tbaa !22
  %48 = load i8, ptr %6, align 1, !tbaa !21
  %49 = zext i8 %48 to i32
  %50 = mul nsw i32 %49, 3600
  %51 = sext i32 %50 to i64
  %52 = mul i64 %51, 1000
  %53 = load i64, ptr %9, align 8, !tbaa !22
  %54 = add i64 %53, %52
  store i64 %54, ptr %9, align 8, !tbaa !22
  %55 = load i64, ptr %9, align 8, !tbaa !22
  %56 = trunc i64 %55 to i32
  %57 = call i64 @arm_2d_helper_convert_ms_to_ticks(i32 noundef %56)
  store i64 %57, ptr getelementptr inbounds (%struct.anon, ptr @s_tHelper, i32 0, i32 2), align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 9, ptr %5) #5
  br label %58

58:                                               ; preds = %32
  br label %59

59:                                               ; preds = %58
  store i32 0, ptr %4, align 4
  br label %60

60:                                               ; preds = %59, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #5
  %61 = load i32, ptr %4, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @arm_2d_helper_get_reference_clock_frequency() #2

declare void @arm_2d_helper_built_in_init() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @__convert_2digits_bdc(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @arm_2d_helper_convert_ms_to_ticks(i32 noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !10, i64 4, !15, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!14, !10, i64 4}
!21 = !{!7, !7, i64 0}
!22 = !{!15, !15, i64 0}
!23 = !{!14, !15, i64 8}


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

@s_tHelper = external hidden local_unnamed_addr global %struct.anon, align 8
@__const.arm_2d_helper_init.c_chStartTime = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_init() local_unnamed_addr #0 {
  %1 = alloca [9 x i8], align 1
  %s_tHelper.promoted = load i8, ptr @s_tHelper, align 8, !tbaa !5
  %2 = trunc nuw i8 %s_tHelper.promoted to i1
  store i8 1, ptr @s_tHelper, align 8, !tbaa !5
  br i1 %2, label %21, label %3

3:                                                ; preds = %0
  %4 = tail call i32 @arm_2d_helper_get_reference_clock_frequency() #5
  %5 = udiv i32 %4, 1000
  %6 = icmp ult i32 %4, 1000
  %spec.store.select = select i1 %6, i32 1, i32 %5
  store i32 %spec.store.select, ptr getelementptr inbounds (i8, ptr @s_tHelper, i64 4), align 4
  tail call void @arm_2d_helper_built_in_init() #5
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %1, ptr noundef nonnull align 1 dereferenceable(9) @__const.arm_2d_helper_init.c_chStartTime, i64 9, i1 false)
  %7 = call zeroext i8 @__convert_2digits_bdc(ptr noundef nonnull %1)
  %8 = getelementptr inbounds i8, ptr %1, i64 3
  %9 = call zeroext i8 @__convert_2digits_bdc(ptr noundef nonnull %8)
  %10 = getelementptr inbounds i8, ptr %1, i64 6
  %11 = call zeroext i8 @__convert_2digits_bdc(ptr noundef nonnull %10)
  %12 = zext i8 %11 to i32
  %13 = mul nuw nsw i32 %12, 1000
  %14 = zext i8 %9 to i32
  %15 = mul nuw nsw i32 %14, 60000
  %16 = zext i8 %7 to i32
  %17 = mul nuw nsw i32 %16, 3600000
  %18 = add nuw nsw i32 %15, %17
  %19 = add nuw nsw i32 %18, %13
  %20 = call i64 @arm_2d_helper_convert_ms_to_ticks(i32 noundef %19)
  store i64 %20, ptr getelementptr inbounds (i8, ptr @s_tHelper, i64 8), align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %1) #5
  br label %21

21:                                               ; preds = %0, %3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @arm_2d_helper_get_reference_clock_frequency() local_unnamed_addr #2

declare void @arm_2d_helper_built_in_init() local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @__convert_2digits_bdc(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @arm_2d_helper_convert_ms_to_ticks(i32 noundef) local_unnamed_addr #0

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 willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !11, i64 8}


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