; LLVM IR from dmalyuta/FlyARocket_GNC :: master_funcs (check_time)

; 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 }

; Function Attrs: nounwind uwtable
define dso_local void @check_time(ptr noundef %0, i64 %1, i64 %2, i64 %3, i64 %4, ptr noundef %5) #0 {
  %7 = alloca %struct.timeval, align 8
  %8 = alloca %struct.timeval, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  store i64 %1, ptr %11, align 8
  %12 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  store i64 %2, ptr %12, align 8
  %13 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %3, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %4, ptr %14, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %5, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = call i32 @gettimeofday(ptr noundef %15, ptr noundef null) #2
  %17 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.timeval, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp sgt i64 %18, %21
  br i1 %22, label %23, label %32

23:                                               ; preds = %6
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.timeval, ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = add nsw i64 %26, 1000000
  store i64 %27, ptr %25, align 8, !tbaa !9
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.timeval, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = add nsw i64 %30, -1
  store i64 %31, ptr %29, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %23, %6
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.timeval, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i64 %35, %37
  %39 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 1
  store i64 %38, ptr %39, align 8, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.timeval, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !12
  %43 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = sub nsw i64 %42, %44
  %46 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 0
  store i64 %45, ptr %46, align 8, !tbaa !12
  %47 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !12
  %49 = mul nsw i64 %48, 1000000
  %50 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = add nsw i64 %49, %51
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !13
  ret void
}

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #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 = { 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 = { 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, !11, i64 8}
!10 = !{!"timeval", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}


; 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"

; Function Attrs: nofree nounwind uwtable
define dso_local void @check_time(ptr nocapture noundef %0, i64 %1, i64 %2, i64 %3, i64 %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = tail call i32 @gettimeofday(ptr noundef %0, ptr noundef null) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp slt i64 %9, %2
  %.pre = load i64, ptr %0, align 8, !tbaa !10
  br i1 %10, label %11, label %14

11:                                               ; preds = %6
  %12 = add nsw i64 %9, 1000000
  store i64 %12, ptr %8, align 8, !tbaa !5
  %13 = add nsw i64 %.pre, -1
  store i64 %13, ptr %0, align 8, !tbaa !10
  br label %14

14:                                               ; preds = %11, %6
  %15 = phi i64 [ %13, %11 ], [ %.pre, %6 ]
  %16 = phi i64 [ %12, %11 ], [ %9, %6 ]
  %17 = sub i64 %16, %2
  %18 = sub nsw i64 %15, %1
  %19 = mul nsw i64 %18, 1000000
  %20 = add nsw i64 %17, %19
  store i64 %20, ptr %5, align 8, !tbaa !11
  ret void
}

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

attributes #0 = { 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 #1 = { 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 #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 8}
!6 = !{!"timeval", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !8, i64 0}


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