; LLVM IR from stivalaa/EstimNetDirected :: src/Random123-1.09/examples (pi_capi)

; 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.r123array2x64 = type { [2 x i64] }
%union.anon = type { %struct.r123array2x64 }

@.str.6 = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pi_check(i64 noundef, i64 noundef) #0

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.r123array2x64, align 8
  %10 = alloca %struct.r123array2x64, align 8
  %11 = alloca %union.anon, align 8
  %12 = alloca i64, align 8
  %13 = alloca %struct.r123array2x64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 4611686018427387904, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #6
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #6
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 16, i1 false)
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i64 noundef 10000000)
  br label %19

19:                                               ; preds = %71, %2
  %20 = load i64, ptr %7, align 8, !tbaa !11
  %21 = icmp ult i64 %20, 10000000
  br i1 %21, label %22, label %72

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %23 = getelementptr inbounds %struct.r123array2x64, ptr %10, i32 0, i32 0
  %24 = getelementptr inbounds [2 x i64], ptr %23, i64 0, i64 0
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = add i64 %25, 1
  store i64 %26, ptr %24, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #6
  %27 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %28 = load i64, ptr %27, align 8
  %29 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %30 = load i64, ptr %29, align 8
  %31 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %32 = load i64, ptr %31, align 8
  %33 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %34 = load i64, ptr %33, align 8
  %35 = call { i64, i64 } @threefry2x64_R(i32 noundef 20, i64 %28, i64 %30, i64 %32, i64 %34)
  %36 = getelementptr inbounds %struct.r123array2x64, ptr %13, i32 0, i32 0
  %37 = getelementptr inbounds { i64, i64 }, ptr %36, i32 0, i32 0
  %38 = extractvalue { i64, i64 } %35, 0
  store i64 %38, ptr %37, align 8
  %39 = getelementptr inbounds { i64, i64 }, ptr %36, i32 0, i32 1
  %40 = extractvalue { i64, i64 } %35, 1
  store i64 %40, ptr %39, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #6
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %68, %22
  %42 = load i64, ptr %12, align 8, !tbaa !11
  %43 = icmp ult i64 %42, 4
  br i1 %43, label %44, label %71

44:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %45 = load i64, ptr %12, align 8, !tbaa !11
  %46 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  store i64 %48, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %49 = load i64, ptr %12, align 8, !tbaa !11
  %50 = add i64 %49, 1
  %51 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !14
  %53 = sext i32 %52 to i64
  store i64 %53, ptr %15, align 8, !tbaa !11
  %54 = load i64, ptr %14, align 8, !tbaa !11
  %55 = load i64, ptr %14, align 8, !tbaa !11
  %56 = mul nsw i64 %54, %55
  %57 = load i64, ptr %15, align 8, !tbaa !11
  %58 = load i64, ptr %15, align 8, !tbaa !11
  %59 = mul nsw i64 %57, %58
  %60 = add nsw i64 %56, %59
  %61 = icmp slt i64 %60, 4611686018427387904
  br i1 %61, label %62, label %65

62:                                               ; preds = %44
  %63 = load i64, ptr %6, align 8, !tbaa !11
  %64 = add i64 %63, 1
  store i64 %64, ptr %6, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %62, %44
  %66 = load i64, ptr %7, align 8, !tbaa !11
  %67 = add i64 %66, 1
  store i64 %67, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %68

68:                                               ; preds = %65
  %69 = load i64, ptr %12, align 8, !tbaa !11
  %70 = add i64 %69, 2
  store i64 %70, ptr %12, align 8, !tbaa !11
  br label %41, !llvm.loop !15

71:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #6
  br label %19, !llvm.loop !17

72:                                               ; preds = %19
  %73 = load i64, ptr %6, align 8, !tbaa !11
  %74 = load i64, ptr %7, align 8, !tbaa !11
  %75 = call i32 @pi_check(i64 noundef %73, i64 noundef %74)
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  ret i32 %75
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden { i64, i64 } @threefry2x64_R(i32 noundef, i64, i64, i64, i64) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { alwaysinline 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 16, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@.str.6 = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pi_check(i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i64 noundef 10000000)
  br label %4

4:                                                ; preds = %2, %4
  %.027 = phi i64 [ 0, %2 ], [ %spec.select.1, %4 ]
  %.sroa.08.025 = phi i64 [ 0, %2 ], [ %5, %4 ]
  %5 = add nuw nsw i64 %.sroa.08.025, 1
  %6 = tail call { i64, i64 } @threefry2x64_R(i32 noundef 20, i64 %5, i64 0, i64 0, i64 0)
  %7 = extractvalue { i64, i64 } %6, 0
  %8 = extractvalue { i64, i64 } %6, 1
  %sext = shl i64 %7, 32
  %9 = ashr exact i64 %sext, 32
  %10 = ashr i64 %7, 32
  %11 = mul nsw i64 %9, %9
  %12 = mul nsw i64 %10, %10
  %13 = add nuw nsw i64 %12, %11
  %14 = icmp ult i64 %13, 4611686018427387904
  %15 = zext i1 %14 to i64
  %spec.select = add i64 %.027, %15
  %sext29 = shl i64 %8, 32
  %16 = ashr exact i64 %sext29, 32
  %17 = ashr i64 %8, 32
  %18 = mul nsw i64 %16, %16
  %19 = mul nsw i64 %17, %17
  %20 = add nuw nsw i64 %19, %18
  %21 = icmp ult i64 %20, 4611686018427387904
  %22 = zext i1 %21 to i64
  %spec.select.1 = add i64 %spec.select, %22
  %exitcond.not = icmp eq i64 %5, 5000000
  br i1 %exitcond.not, label %23, label %4, !llvm.loop !5

23:                                               ; preds = %4
  %24 = tail call i32 @pi_check(i64 noundef %spec.select.1, i64 noundef 10000000)
  ret i32 %24
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden { i64, i64 } @threefry2x64_R(i32 noundef, i64, i64, i64, i64) local_unnamed_addr #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 = { alwaysinline 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass