; LLVM IR from rantala/string-sorting :: src/util (timing)

; 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.rusage = type { %struct.timeval, %struct.timeval, %union.anon, %union.anon.0, %union.anon.1, %union.anon.2, %union.anon.3, %union.anon.4, %union.anon.5, %union.anon.6, %union.anon.7, %union.anon.8, %union.anon.9, %union.anon.10, %union.anon.11, %union.anon.12 }
%struct.timeval = type { i64, i64 }
%union.anon = type { i64 }
%union.anon.0 = type { i64 }
%union.anon.1 = type { i64 }
%union.anon.2 = type { i64 }
%union.anon.3 = type { i64 }
%union.anon.4 = type { i64 }
%union.anon.5 = type { i64 }
%union.anon.6 = type { i64 }
%union.anon.7 = type { i64 }
%union.anon.8 = type { i64 }
%union.anon.9 = type { i64 }
%union.anon.10 = type { i64 }
%union.anon.11 = type { i64 }
%union.anon.12 = type { i64 }

@startclock = external hidden global %struct.rusage, align 8
@stopclock = external hidden global %struct.rusage, align 8

; 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 double @gettime_user_sys() #1 {
  %1 = alloca %struct.timeval, align 8
  %2 = alloca %struct.timeval, align 8
  %3 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #2
  br label %4

4:                                                ; preds = %0
  %5 = load i64, ptr @stopclock, align 8, !tbaa !5
  %6 = load i64, ptr @startclock, align 8, !tbaa !5
  %7 = sub nsw i64 %5, %6
  %8 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  store i64 %7, ptr %8, align 8, !tbaa !11
  %9 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @stopclock, i32 0, i32 1), align 8, !tbaa !12
  %10 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @startclock, i32 0, i32 1), align 8, !tbaa !12
  %11 = sub nsw i64 %9, %10
  %12 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  store i64 %11, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp slt i64 %14, 0
  br i1 %15, label %16, label %23

16:                                               ; preds = %4
  %17 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = add nsw i64 %18, -1
  store i64 %19, ptr %17, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = add nsw i64 %21, 1000000
  store i64 %22, ptr %20, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %16, %4
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load i64, ptr getelementptr inbounds (%struct.rusage, ptr @stopclock, i32 0, i32 1), align 8, !tbaa !14
  %28 = load i64, ptr getelementptr inbounds (%struct.rusage, ptr @startclock, i32 0, i32 1), align 8, !tbaa !14
  %29 = sub nsw i64 %27, %28
  %30 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 0
  store i64 %29, ptr %30, align 8, !tbaa !11
  %31 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr getelementptr inbounds (%struct.rusage, ptr @stopclock, i32 0, i32 1), i32 0, i32 1), align 8, !tbaa !15
  %32 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr getelementptr inbounds (%struct.rusage, ptr @startclock, i32 0, i32 1), i32 0, i32 1), align 8, !tbaa !15
  %33 = sub nsw i64 %31, %32
  %34 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  store i64 %33, ptr %34, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %26
  %39 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = add nsw i64 %40, -1
  store i64 %41, ptr %39, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = add nsw i64 %43, 1000000
  store i64 %44, ptr %42, align 8, !tbaa !13
  br label %45

45:                                               ; preds = %38, %26
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 0
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = add nsw i64 %50, %52
  %54 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 0
  store i64 %53, ptr %54, align 8, !tbaa !11
  %55 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !13
  %59 = add nsw i64 %56, %58
  %60 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  store i64 %59, ptr %60, align 8, !tbaa !13
  %61 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !13
  %63 = icmp sge i64 %62, 1000000
  br i1 %63, label %64, label %71

64:                                               ; preds = %48
  %65 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %65, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  %69 = load i64, ptr %68, align 8, !tbaa !13
  %70 = sub nsw i64 %69, 1000000
  store i64 %70, ptr %68, align 8, !tbaa !13
  br label %71

71:                                               ; preds = %64, %48
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 0
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = mul nsw i64 %75, 1000
  %77 = sitofp i64 %76 to double
  %78 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  %79 = load i64, ptr %78, align 8, !tbaa !13
  %80 = sitofp i64 %79 to double
  %81 = fdiv double %80, 1.000000e+03
  %82 = fadd double %77, %81
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #2
  ret double %82
}

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 = { 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, !8, i64 0}
!6 = !{!"rusage", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136}
!7 = !{!"timeval", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!7, !8, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!7, !8, i64 8}
!14 = !{!6, !8, i64 16}
!15 = !{!6, !8, i64 24}


; 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.rusage = type { %struct.timeval, %struct.timeval, %union.anon, %union.anon.0, %union.anon.1, %union.anon.2, %union.anon.3, %union.anon.4, %union.anon.5, %union.anon.6, %union.anon.7, %union.anon.8, %union.anon.9, %union.anon.10, %union.anon.11, %union.anon.12 }
%struct.timeval = type { i64, i64 }
%union.anon = type { i64 }
%union.anon.0 = type { i64 }
%union.anon.1 = type { i64 }
%union.anon.2 = type { i64 }
%union.anon.3 = type { i64 }
%union.anon.4 = type { i64 }
%union.anon.5 = type { i64 }
%union.anon.6 = type { i64 }
%union.anon.7 = type { i64 }
%union.anon.8 = type { i64 }
%union.anon.9 = type { i64 }
%union.anon.10 = type { i64 }
%union.anon.11 = type { i64 }
%union.anon.12 = type { i64 }

@startclock = external hidden local_unnamed_addr global %struct.rusage, align 8
@stopclock = external hidden local_unnamed_addr global %struct.rusage, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local double @gettime_user_sys() local_unnamed_addr #0 {
  %1 = load i64, ptr @stopclock, align 8, !tbaa !5
  %2 = load i64, ptr @startclock, align 8, !tbaa !5
  %3 = load i64, ptr getelementptr inbounds (i8, ptr @stopclock, i64 8), align 8, !tbaa !11
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @startclock, i64 8), align 8, !tbaa !11
  %5 = sub nsw i64 %3, %4
  %6 = icmp slt i64 %5, 0
  %7 = add nsw i64 %5, 1000000
  %.sroa.611.0 = select i1 %6, i64 %7, i64 %5
  %.lobit = ashr i64 %5, 63
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @stopclock, i64 16), align 8, !tbaa !12
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @startclock, i64 16), align 8, !tbaa !12
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @stopclock, i64 24), align 8, !tbaa !13
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @startclock, i64 24), align 8, !tbaa !13
  %12 = sub nsw i64 %10, %11
  %13 = icmp slt i64 %12, 0
  %14 = add nsw i64 %12, 1000000
  %.sroa.66.0 = select i1 %13, i64 %14, i64 %12
  %.lobit18 = ashr i64 %12, 63
  %15 = add nsw i64 %.sroa.66.0, %.sroa.611.0
  %16 = icmp sgt i64 %15, 999999
  %17 = add nsw i64 %15, -1000000
  %.sroa.6.0 = select i1 %16, i64 %17, i64 %15
  %18 = zext i1 %16 to i64
  %19 = sub i64 %1, %2
  %.sroa.04.0 = add i64 %19, %8
  %20 = add i64 %.sroa.04.0, %.lobit
  %.sroa.09.0 = sub i64 %20, %9
  %21 = add i64 %.sroa.09.0, %.lobit18
  %.sroa.0.0 = add nsw i64 %21, %18
  %22 = mul nsw i64 %.sroa.0.0, 1000
  %23 = sitofp i64 %22 to double
  %24 = sitofp i64 %.sroa.6.0 to double
  %25 = fdiv double %24, 1.000000e+03
  %26 = fadd double %25, %23
  ret double %26
}

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, !8, i64 0}
!6 = !{!"rusage", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136}
!7 = !{!"timeval", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !8, i64 8}
!12 = !{!6, !8, i64 16}
!13 = !{!6, !8, i64 24}


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