; LLVM IR from mickypaganini/SSI2016-jet-clustering :: spartyjet-4.0.2_mac/External/fastjet-3.0.0/plugins/SISCone/siscone/examples/ti_2090fb69 (spentv)

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

@time_start = external dso_local global %struct.timeval, align 8
@time_end = external dso_local global %struct.timeval, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z10time_spentv() #0 {
  %1 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #2
  %2 = load i64, ptr @time_end, align 8, !tbaa !5
  %3 = load i64, ptr @time_start, align 8, !tbaa !5
  %4 = sub nsw i64 %2, %3
  %5 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  store i64 %4, ptr %5, align 8, !tbaa !5
  %6 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_end, i32 0, i32 1), align 8, !tbaa !10
  %7 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_start, i32 0, i32 1), align 8, !tbaa !10
  %8 = icmp sgt i64 %6, %7
  br i1 %8, label %9, label %14

9:                                                ; preds = %0
  %10 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_end, i32 0, i32 1), align 8, !tbaa !10
  %11 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_start, i32 0, i32 1), align 8, !tbaa !10
  %12 = sub nsw i64 %10, %11
  %13 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  store i64 %12, ptr %13, align 8, !tbaa !10
  br label %23

14:                                               ; preds = %0
  %15 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %16, -1
  store i64 %17, ptr %15, align 8, !tbaa !5
  %18 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_end, i32 0, i32 1), align 8, !tbaa !10
  %19 = add nsw i64 1000000, %18
  %20 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @time_start, i32 0, i32 1), align 8, !tbaa !10
  %21 = sub nsw i64 %19, %20
  %22 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  store i64 %21, ptr %22, align 8, !tbaa !10
  br label %23

23:                                               ; preds = %14, %9
  %24 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = mul nsw i64 1000000, %25
  %27 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !10
  %29 = add nsw i64 %26, %28
  %30 = trunc i64 %29 to i32
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #2
  ret i32 %30
}

; 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

attributes #0 = { mustprogress 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 = { 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 = !{!"_ZTS7timeval", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, 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.timeval = type { i64, i64 }

@time_start = external dso_local local_unnamed_addr global %struct.timeval, align 8
@time_end = external dso_local local_unnamed_addr global %struct.timeval, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z10time_spentv() local_unnamed_addr #0 {
  %1 = load i64, ptr @time_end, align 8, !tbaa !5
  %2 = load i64, ptr @time_start, align 8, !tbaa !5
  %3 = sub i64 %1, %2
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @time_end, i64 8), align 8, !tbaa !10
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @time_start, i64 8), align 8, !tbaa !10
  %6 = icmp sle i64 %4, %5
  %7 = add nsw i64 %4, 1000000
  %.pn = select i1 %6, i64 %7, i64 %4
  %8 = sext i1 %6 to i64
  %.sroa.0.0 = add nsw i64 %3, %8
  %.sroa.6.0 = sub i64 %.pn, %5
  %9 = mul nsw i64 %.sroa.0.0, 1000000
  %10 = add nsw i64 %.sroa.6.0, %9
  %11 = trunc i64 %10 to i32
  ret i32 %11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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" }

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


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