; LLVM IR from logicchains/LPATHBench :: c (main)

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

@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; 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
declare dso_local i32 @max_distance_branchless(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @read_graph_file(ptr noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.timeval, align 8
  %4 = alloca %struct.timeval, align 8
  %5 = alloca %struct.timeval, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %9 = call ptr @read_graph_file(ptr noundef @.str.2)
  store ptr %9, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  %10 = call i32 @gettimeofday(ptr noundef %3, ptr noundef null) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr @.str.8, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds ptr, ptr %12, i64 0
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = call i32 @max_distance_branchless(ptr noundef %11, ptr noundef %14)
  store i32 %15, ptr %7, align 4, !tbaa !9
  %16 = call i32 @gettimeofday(ptr noundef %4, ptr noundef null) #4
  br label %17

17:                                               ; preds = %0
  %18 = getelementptr inbounds %struct.timeval, ptr %4, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = sub nsw i64 %19, %21
  %23 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 0
  store i64 %22, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.timeval, ptr %4, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = sub nsw i64 %25, %27
  %29 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 1
  store i64 %28, ptr %29, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %40

33:                                               ; preds = %17
  %34 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr %34, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !14
  %39 = add nsw i64 %38, 1000000
  store i64 %39, ptr %37, align 8, !tbaa !14
  br label %40

40:                                               ; preds = %33, %17
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %43 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = mul nsw i64 %44, 1000
  %46 = getelementptr inbounds %struct.timeval, ptr %5, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !14
  %48 = sdiv i64 %47, 1000
  %49 = add nsw i64 %45, %48
  store i64 %49, ptr %8, align 8, !tbaa !15
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i64, ptr %8, align 8, !tbaa !15
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %50, ptr noundef %51, i64 noundef %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %54 = load i32, ptr %1, align 4
  ret i32 %54
}

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

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

%struct.timeval = type { i64, i64 }

@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; 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: nounwind uwtable
declare dso_local i32 @max_distance_branchless(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @read_graph_file(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca %struct.timeval, align 8
  %2 = alloca %struct.timeval, align 8
  %3 = tail call ptr @read_graph_file(ptr noundef nonnull @.str.2)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %4 = call i32 @gettimeofday(ptr noundef nonnull %1, ptr noundef null) #3
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = tail call i32 @max_distance_branchless(ptr noundef nonnull %3, ptr noundef %5)
  %7 = call i32 @gettimeofday(ptr noundef nonnull %2, ptr noundef null) #3
  %8 = load i64, ptr %2, align 8, !tbaa !9
  %9 = load i64, ptr %1, align 8, !tbaa !9
  %10 = sub i64 %8, %9
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = sub nsw i64 %12, %14
  %16 = icmp slt i64 %15, 0
  %17 = add nsw i64 %15, 1000000
  %.lobit = ashr i64 %15, 63
  %.sroa.0.0 = add nsw i64 %10, %.lobit
  %.sroa.6.0 = select i1 %16, i64 %17, i64 %15
  %18 = mul nsw i64 %.sroa.0.0, 1000
  %19 = sdiv i64 %.sroa.6.0, 1000
  %20 = add nsw i64 %18, %19
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %6, ptr noundef nonnull @.str.8, i64 noundef %20)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #3
  ret i32 0
}

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


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