; LLVM IR from CMU-SAFARI/prim-benchmarks :: BS/baselines/cpu (bs_omp)

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

; Function Attrs: nounwind uwtable
define dso_local void @create_test_file(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 -1, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %13 = call i64 @time(ptr noundef null) #3
  %14 = trunc i64 %13 to i32
  call void @srand(i32 noundef %14) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds i64, ptr %15, i64 0
  store i64 1, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 1, ptr %11, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %36, %4
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %39

22:                                               ; preds = %17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = sub i64 %24, 1
  %26 = getelementptr inbounds i64, ptr %23, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = call i32 @rand() #3
  %29 = srem i32 %28, 10
  %30 = sext i32 %29 to i64
  %31 = add i64 %27, %30
  %32 = add i64 %31, 1
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = getelementptr inbounds i64, ptr %33, i64 %34
  store i64 %32, ptr %35, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %22
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %11, align 8, !tbaa !9
  br label %17, !llvm.loop !11

39:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %57, %39
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %60

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call i32 @rand() #3
  %48 = sext i32 %47 to i64
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = sub i64 %49, 2
  %51 = urem i64 %48, %50
  %52 = getelementptr inbounds i64, ptr %46, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i64, ptr %12, align 8, !tbaa !9
  %56 = getelementptr inbounds i64, ptr %54, i64 %55
  store i64 %53, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %45
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %12, align 8, !tbaa !9
  br label %40, !llvm.loop !13

60:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @rand() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nounwind uwtable
define dso_local void @create_test_file(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i64 @time(ptr noundef null) #2
  %6 = trunc i64 %5 to i32
  tail call void @srand(i32 noundef %6) #2
  store i64 1, ptr %0, align 8, !tbaa !5
  %7 = icmp ugt i64 %1, 1
  br i1 %7, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %4
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph18

.lr.ph18:                                         ; preds = %.preheader
  %8 = add i64 %1, -2
  br label %18

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.01416 = phi i64 [ %17, %.lr.ph ], [ 1, %4 ]
  %9 = getelementptr i64, ptr %0, i64 %.01416
  %10 = getelementptr i8, ptr %9, i64 -8
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = tail call i32 @rand() #2
  %13 = srem i32 %12, 10
  %14 = sext i32 %13 to i64
  %15 = add i64 %11, 1
  %16 = add i64 %15, %14
  store i64 %16, ptr %9, align 8, !tbaa !5
  %17 = add nuw i64 %.01416, 1
  %exitcond.not = icmp eq i64 %17, %1
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %18, %.preheader
  ret void

18:                                               ; preds = %.lr.ph18, %18
  %.017 = phi i64 [ 0, %.lr.ph18 ], [ %25, %18 ]
  %19 = tail call i32 @rand() #2
  %20 = sext i32 %19 to i64
  %21 = urem i64 %20, %8
  %22 = getelementptr inbounds i64, ptr %0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i64, ptr %2, i64 %.017
  store i64 %23, ptr %24, align 8, !tbaa !5
  %25 = add nuw i64 %.017, 1
  %exitcond19.not = icmp eq i64 %25, %3
  br i1 %exitcond19.not, label %._crit_edge, label %18, !llvm.loop !11
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass