; LLVM IR from Nigh/Basic-Compression-Library :: src (systimer)

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

@global_timer = external hidden global %struct.systimer_t, align 8

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local double @GetTime() #1 {
  %1 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #4
  %2 = call i32 @gettimeofday(ptr noundef %1, ptr noundef null) #4
  %3 = load i64, ptr @global_timer, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = sub nsw i64 %5, %3
  store i64 %6, ptr %4, align 8, !tbaa !11
  %7 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @global_timer, i32 0, i32 1), align 8, !tbaa !12
  %8 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = sub nsw i64 %9, %7
  store i64 %10, ptr %8, align 8, !tbaa !13
  %11 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %21

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

21:                                               ; preds = %14, %0
  %22 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = sitofp i64 %23 to double
  %25 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = sitofp i64 %26 to double
  %28 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %27, double %24)
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #4
  ret double %28
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"", !7, i64 0}
!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}


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

@global_timer = external hidden local_unnamed_addr global %struct.systimer_t, align 8

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local double @GetTime() local_unnamed_addr #1 {
  %1 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  %2 = call i32 @gettimeofday(ptr noundef nonnull %1, ptr noundef null) #4
  %3 = load i64, ptr @global_timer, align 8, !tbaa !5
  %4 = load i64, ptr %1, align 8, !tbaa !11
  %5 = sub nsw i64 %4, %3
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @global_timer, i64 8), align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !13
  %9 = sub nsw i64 %8, %6
  %10 = icmp slt i64 %9, 0
  %11 = add nsw i64 %9, 1000000
  %12 = select i1 %10, i64 %11, i64 %9
  %.lobit = ashr i64 %9, 63
  %13 = add nsw i64 %5, %.lobit
  %14 = sitofp i64 %13 to double
  %15 = sitofp i64 %12 to double
  %16 = tail call double @llvm.fmuladd.f64(double %15, double 0x3EB0C6F7A0B5ED8D, double %14)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  ret double %16
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

attributes #0 = { nofree 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 #1 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"", !7, i64 0}
!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}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SimplifyCFGPass,TailCallElimPass