; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Labs/Lab3 (testMultiQ)

; 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 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.timeval, align 8
  %8 = alloca %struct.timeval, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 2
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %72

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str.1)
  store ptr %19, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %15
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %71

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %25 = call i32 @gettimeofday(ptr noundef %7, ptr noundef null) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = call ptr @loadData(ptr noundef %26)
  store ptr %27, ptr %10, align 8, !tbaa !9
  %28 = call i32 @gettimeofday(ptr noundef %8, ptr noundef null) #4
  %29 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = sub nsw i64 %30, %32
  %34 = sitofp i64 %33 to double
  %35 = fmul double %34, 1.000000e+03
  store double %35, ptr %9, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !16
  %40 = sub nsw i64 %37, %39
  %41 = sitofp i64 %40 to double
  %42 = fdiv double %41, 1.000000e+03
  %43 = load double, ptr %9, align 8, !tbaa !14
  %44 = fadd double %43, %42
  store double %44, ptr %9, align 8, !tbaa !14
  %45 = load double, ptr %9, align 8, !tbaa !14
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %45)
  %47 = call i32 @gettimeofday(ptr noundef %7, ptr noundef null) #4
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  call void @testDel(ptr noundef %48, i32 noundef 10)
  %49 = call i32 @gettimeofday(ptr noundef %8, ptr noundef null) #4
  %50 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = sub nsw i64 %51, %53
  %55 = sitofp i64 %54 to double
  %56 = fmul double %55, 1.000000e+03
  store double %56, ptr %9, align 8, !tbaa !14
  %57 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !16
  %59 = getelementptr inbounds %struct.timeval, ptr %7, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !16
  %61 = sub nsw i64 %58, %60
  %62 = sitofp i64 %61 to double
  %63 = fdiv double %62, 1.000000e+03
  %64 = load double, ptr %9, align 8, !tbaa !14
  %65 = fadd double %64, %63
  store double %65, ptr %9, align 8, !tbaa !14
  %66 = load double, ptr %9, align 8, !tbaa !14
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, double noundef %66)
  %68 = load double, ptr %9, align 8, !tbaa !14
  %69 = fdiv double %68, 1.000000e+01
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, double noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %71

71:                                               ; preds = %24, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %72

72:                                               ; preds = %71, %13
  ret i32 0
}

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

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @loadData(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @testDel(ptr noundef, i32 noundef) #0

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

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

@.str = external hidden unnamed_addr constant [33 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.timeval, align 8
  %4 = alloca %struct.timeval, align 8
  %5 = icmp slt i32 %0, 2
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %49

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call noalias ptr @fopen(ptr noundef %10, ptr noundef nonnull @.str.1)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %49

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %16 = call i32 @gettimeofday(ptr noundef nonnull %3, ptr noundef null) #3
  %17 = tail call ptr @loadData(ptr noundef nonnull %11)
  %18 = call i32 @gettimeofday(ptr noundef nonnull %4, ptr noundef null) #3
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = sub nsw i64 %19, %20
  %22 = sitofp i64 %21 to double
  %23 = fmul double %22, 1.000000e+03
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %3, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = sub nsw i64 %25, %27
  %29 = sitofp i64 %28 to double
  %30 = fdiv double %29, 1.000000e+03
  %31 = fadd double %23, %30
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %31)
  %33 = call i32 @gettimeofday(ptr noundef nonnull %3, ptr noundef null) #3
  tail call void @testDel(ptr noundef %17, i32 noundef 10)
  %34 = call i32 @gettimeofday(ptr noundef nonnull %4, ptr noundef null) #3
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = load i64, ptr %3, align 8, !tbaa !9
  %37 = sub nsw i64 %35, %36
  %38 = sitofp i64 %37 to double
  %39 = fmul double %38, 1.000000e+03
  %40 = load i64, ptr %24, align 8, !tbaa !12
  %41 = load i64, ptr %26, align 8, !tbaa !12
  %42 = sub nsw i64 %40, %41
  %43 = sitofp i64 %42 to double
  %44 = fdiv double %43, 1.000000e+03
  %45 = fadd double %39, %44
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, double noundef %45)
  %47 = fdiv double %45, 1.000000e+01
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, double noundef %47)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  br label %49

49:                                               ; preds = %13, %15, %6
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @loadData(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @testDel(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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,SROAPass,SimplifyCFGPass,TailCallElimPass