; LLVM IR from tezc/sc :: timer (sc_timer)

; 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.sc_timer = type { i64, i32, i32, ptr }
%struct.sc_timer_data = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__PRETTY_FUNCTION__.sc_timer_add = external hidden unnamed_addr constant [69 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 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: nounwind uwtable
define dso_local i64 @sc_timer_add(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = udiv i64 %17, 16
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sc_timer, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = zext i32 %21 to i64
  %23 = add i64 %18, %22
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %25 = load i32, ptr %10, align 4, !tbaa !14
  %26 = and i32 %25, 15
  store i32 %26, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %27 = load i32, ptr %11, align 4, !tbaa !14
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sc_timer, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !15
  %31 = mul i32 %27, %30
  store i32 %31, ptr %15, align 4, !tbaa !14
  store i32 0, ptr %13, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %53, %4
  %33 = load i32, ptr %13, align 4, !tbaa !14
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.sc_timer, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = icmp ult i32 %33, %36
  br i1 %37, label %38, label %56

38:                                               ; preds = %32
  %39 = load i32, ptr %15, align 4, !tbaa !14
  %40 = load i32, ptr %13, align 4, !tbaa !14
  %41 = add i32 %39, %40
  store i32 %41, ptr %14, align 4, !tbaa !14
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.sc_timer, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %14, align 4, !tbaa !14
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.sc_timer_data, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.sc_timer_data, ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !17
  %50 = icmp eq i64 %49, -1
  br i1 %50, label %51, label %52

51:                                               ; preds = %38
  br label %80

52:                                               ; preds = %38
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %13, align 4, !tbaa !14
  %55 = add i32 %54, 1
  store i32 %55, ptr %13, align 4, !tbaa !14
  br label %32, !llvm.loop !19

56:                                               ; preds = %32
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = call zeroext i1 @expand(ptr noundef %57)
  br i1 %58, label %60, label %59

59:                                               ; preds = %56
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %16, align 4
  br label %121

60:                                               ; preds = %56
  %61 = load i32, ptr %11, align 4, !tbaa !14
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sc_timer, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !15
  %65 = mul i32 %61, %64
  %66 = load i32, ptr %13, align 4, !tbaa !14
  %67 = add i32 %65, %66
  store i32 %67, ptr %14, align 4, !tbaa !14
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.sc_timer, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  %71 = load i32, ptr %14, align 4, !tbaa !14
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds %struct.sc_timer_data, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.sc_timer_data, ptr %73, i32 0, i32 0
  %75 = load i64, ptr %74, align 8, !tbaa !17
  %76 = icmp eq i64 %75, -1
  br i1 %76, label %77, label %78

77:                                               ; preds = %60
  br label %79

78:                                               ; preds = %60
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 135, ptr noundef @__PRETTY_FUNCTION__.sc_timer_add) #4
  unreachable

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %51
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.sc_timer, ptr %82, i32 0, i32 0
  %84 = load i64, ptr %83, align 8, !tbaa !21
  %85 = add i64 %81, %84
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sc_timer, ptr %86, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = load i32, ptr %14, align 4, !tbaa !14
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds %struct.sc_timer_data, ptr %88, i64 %90
  %92 = getelementptr inbounds %struct.sc_timer_data, ptr %91, i32 0, i32 0
  store i64 %85, ptr %92, align 8, !tbaa !17
  %93 = load i64, ptr %8, align 8, !tbaa !9
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.sc_timer, ptr %94, i32 0, i32 3
  %96 = load ptr, ptr %95, align 8, !tbaa !16
  %97 = load i32, ptr %14, align 4, !tbaa !14
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds %struct.sc_timer_data, ptr %96, i64 %98
  %100 = getelementptr inbounds %struct.sc_timer_data, ptr %99, i32 0, i32 1
  store i64 %93, ptr %100, align 8, !tbaa !22
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.sc_timer, ptr %102, i32 0, i32 3
  %104 = load ptr, ptr %103, align 8, !tbaa !16
  %105 = load i32, ptr %14, align 4, !tbaa !14
  %106 = zext i32 %105 to i64
  %107 = getelementptr inbounds %struct.sc_timer_data, ptr %104, i64 %106
  %108 = getelementptr inbounds %struct.sc_timer_data, ptr %107, i32 0, i32 2
  store ptr %101, ptr %108, align 8, !tbaa !23
  %109 = load i32, ptr %13, align 4, !tbaa !14
  %110 = zext i32 %109 to i64
  %111 = shl i64 %110, 32
  %112 = load i32, ptr %11, align 4, !tbaa !14
  %113 = zext i32 %112 to i64
  %114 = or i64 %111, %113
  store i64 %114, ptr %12, align 8, !tbaa !9
  %115 = load i64, ptr %12, align 8, !tbaa !9
  %116 = icmp ne i64 %115, -1
  br i1 %116, label %117, label %118

117:                                              ; preds = %80
  br label %119

118:                                              ; preds = %80
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 143, ptr noundef @__PRETTY_FUNCTION__.sc_timer_add) #4
  unreachable

119:                                              ; preds = %117
  %120 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %120, ptr %5, align 8
  store i32 1, ptr %16, align 4
  br label %121

121:                                              ; preds = %119, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %122 = load i64, ptr %5, align 8
  ret i64 %122
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @expand(ptr noundef) #1

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

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 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"any pointer", !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, !13, i64 8}
!12 = !{!"sc_timer", !10, i64 0, !13, i64 8, !13, i64 12, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 12}
!16 = !{!12, !6, i64 16}
!17 = !{!18, !10, i64 0}
!18 = !{!"sc_timer_data", !10, i64 0, !10, i64 8, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 0}
!22 = !{!18, !10, i64 8}
!23 = !{!18, !6, i64 16}


; 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.sc_timer_data = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__PRETTY_FUNCTION__.sc_timer_add = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @sc_timer_add(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = trunc i64 %1 to i32
  %8 = lshr i32 %7, 4
  %9 = add i32 %6, %8
  %10 = and i32 %9, 15
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = mul i32 %10, %12
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %wide.trip.count = zext i32 %12 to i64
  br label %16

16:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %17 = trunc nuw i64 %indvars.iv to i32
  %18 = add i32 %13, %17
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds %struct.sc_timer_data, ptr %15, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = icmp eq i64 %21, -1
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !16

._crit_edge:                                      ; preds = %23, %4
  %24 = tail call zeroext i1 @expand(ptr noundef nonnull %0)
  br i1 %24, label %25, label %46

25:                                               ; preds = %._crit_edge
  %26 = load i32, ptr %11, align 4, !tbaa !12
  %27 = mul i32 %26, %10
  %28 = add i32 %27, %12
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = zext i32 %28 to i64
  %32 = getelementptr inbounds %struct.sc_timer_data, ptr %30, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !14
  %34 = icmp eq i64 %33, -1
  br i1 %34, label %.loopexit, label %35

35:                                               ; preds = %25
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 135, ptr noundef nonnull @__PRETTY_FUNCTION__.sc_timer_add) #2
  unreachable

.loopexit:                                        ; preds = %16, %25
  %.pre-phi = phi i64 [ %31, %25 ], [ %19, %16 ]
  %36 = phi ptr [ %30, %25 ], [ %15, %16 ]
  %.03335 = phi i32 [ %12, %25 ], [ %17, %16 ]
  %37 = load i64, ptr %0, align 8, !tbaa !18
  %38 = add i64 %37, %1
  %39 = getelementptr inbounds %struct.sc_timer_data, ptr %36, i64 %.pre-phi
  store i64 %38, ptr %39, align 8, !tbaa !14
  %40 = getelementptr inbounds %struct.sc_timer_data, ptr %36, i64 %.pre-phi, i32 1
  store i64 %2, ptr %40, align 8, !tbaa !19
  %41 = getelementptr inbounds %struct.sc_timer_data, ptr %36, i64 %.pre-phi, i32 2
  store ptr %3, ptr %41, align 8, !tbaa !20
  %42 = zext i32 %.03335 to i64
  %43 = shl nuw i64 %42, 32
  %44 = zext nneg i32 %10 to i64
  %45 = or disjoint i64 %43, %44
  br label %46

46:                                               ; preds = %._crit_edge, %.loopexit
  %.0 = phi i64 [ %45, %.loopexit ], [ -1, %._crit_edge ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @expand(ptr noundef) local_unnamed_addr #0

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

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 = { 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 = { 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, !10, i64 8}
!6 = !{!"sc_timer", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 12}
!13 = !{!6, !11, i64 16}
!14 = !{!15, !7, i64 0}
!15 = !{!"sc_timer_data", !7, i64 0, !7, i64 8, !11, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 0}
!19 = !{!15, !7, i64 8}
!20 = !{!15, !11, i64 16}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass