; LLVM IR from google/latency-benchmark :: src/x11 (screenscraper)

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

@start_time_initialized = external hidden global i8, align 1
@start_time = external hidden global %struct.timeval, 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 i64 @get_nanoseconds() #1 {
  %1 = alloca %struct.timeval, align 8
  %2 = alloca %struct.timeval, align 8
  %3 = load i8, ptr @start_time_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc i8 %3 to i1
  br i1 %4, label %7, label %5

5:                                                ; preds = %0
  %6 = call i32 @gettimeofday(ptr noundef @start_time, ptr noundef null) #3
  store i8 1, ptr @start_time_initialized, align 1, !tbaa !5
  br label %7

7:                                                ; preds = %5, %0
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #3
  %8 = call i32 @gettimeofday(ptr noundef %1, ptr noundef null) #3
  br label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = load i64, ptr @start_time, align 8, !tbaa !11
  %13 = sub nsw i64 %11, %12
  %14 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 0
  store i64 %13, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.timeval, ptr %1, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = load i64, ptr getelementptr inbounds (%struct.timeval, ptr @start_time, i32 0, i32 1), align 8, !tbaa !14
  %18 = sub nsw i64 %16, %17
  %19 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  store i64 %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %30

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

30:                                               ; preds = %23, %9
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = mul nsw i64 %34, 1000000000
  %36 = getelementptr inbounds %struct.timeval, ptr %2, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !14
  %38 = mul nsw i64 %37, 1000
  %39 = add nsw i64 %35, %38
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #3
  ret i64 %39
}

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr 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 = { 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 }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 0}
!12 = !{!"timeval", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, 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 }

@start_time_initialized = external hidden local_unnamed_addr global i8, align 1
@start_time = external hidden global %struct.timeval, align 8

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local i64 @get_nanoseconds() local_unnamed_addr #1 {
  %1 = alloca %struct.timeval, align 8
  %2 = load i8, ptr @start_time_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %6, label %4

4:                                                ; preds = %0
  %5 = tail call i32 @gettimeofday(ptr noundef nonnull @start_time, ptr noundef null) #3
  store i8 1, ptr @start_time_initialized, align 1, !tbaa !5
  br label %6

6:                                                ; preds = %4, %0
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #3
  %7 = call i32 @gettimeofday(ptr noundef nonnull %1, ptr noundef null) #3
  %8 = load i64, ptr %1, align 8, !tbaa !11
  %9 = load i64, ptr @start_time, align 8, !tbaa !11
  %10 = sub i64 %8, %9
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @start_time, i64 8), align 8, !tbaa !14
  %14 = sub nsw i64 %12, %13
  %15 = icmp slt i64 %14, 0
  %16 = add nsw i64 %14, 1000000
  %.sroa.6.0 = select i1 %15, i64 %16, i64 %14
  %.lobit = ashr i64 %14, 63
  %.sroa.0.0 = add nsw i64 %10, %.lobit
  %17 = mul nsw i64 %.sroa.0.0, 1000000000
  %18 = mul nsw i64 %.sroa.6.0, 1000
  %19 = add nsw i64 %17, %18
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #3
  ret i64 %19
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 0}
!12 = !{!"timeval", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}


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