; LLVM IR from tsotchke/quantum_rng :: examples/finance (monte_carlo)

; 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.simulation_results_t = type { double, double, double, double, double, double, ptr }
%struct.simulation_config_t = type { i32, i32, %struct.asset_params_t, [256 x i8], i32, i32, i32, [1024 x i8], double }
%struct.asset_params_t = type { double, double, double, double }

@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [5 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @output_results_json(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str.19) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.simulation_results_t, ptr %11, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef @.str.20, double noundef %13) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.simulation_results_t, ptr %16, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !12
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.21, double noundef %18) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.simulation_results_t, ptr %21, i32 0, i32 2
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.22, double noundef %23) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.simulation_results_t, ptr %26, i32 0, i32 3
  %28 = load double, ptr %27, align 8, !tbaa !14
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.23, double noundef %28) #3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.24) #3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.simulation_config_t, ptr %33, i32 0, i32 8
  %35 = load double, ptr %34, align 8, !tbaa !15
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.25, double noundef %35) #3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.simulation_results_t, ptr %38, i32 0, i32 4
  %40 = load double, ptr %39, align 8, !tbaa !19
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str.26, double noundef %40) #3
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.simulation_results_t, ptr %43, i32 0, i32 5
  %45 = load double, ptr %44, align 8, !tbaa !20
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.27, double noundef %45) #3
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.28) #3
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str.29) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !21
  br label %51

51:                                               ; preds = %76, %3
  %52 = load i32, ptr %7, align 4, !tbaa !21
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.simulation_config_t, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !22
  %56 = icmp slt i32 %52, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %79

58:                                               ; preds = %51
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.simulation_results_t, ptr %60, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = load i32, ptr %7, align 4, !tbaa !21
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !24
  %67 = load i32, ptr %7, align 4, !tbaa !21
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.simulation_config_t, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !22
  %71 = sub nsw i32 %70, 1
  %72 = icmp slt i32 %67, %71
  %73 = zext i1 %72 to i64
  %74 = select i1 %72, ptr @.str.31, ptr @.str.32
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str.30, double noundef %66, ptr noundef %74) #3
  br label %76

76:                                               ; preds = %58
  %77 = load i32, ptr %7, align 4, !tbaa !21
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %7, align 4, !tbaa !21
  br label %51, !llvm.loop !25

79:                                               ; preds = %57
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str.33) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !6, i64 48}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 24}
!15 = !{!16, !11, i64 1336}
!16 = !{!"", !17, i64 0, !17, i64 4, !18, i64 8, !7, i64 40, !17, i64 296, !17, i64 300, !17, i64 304, !7, i64 308, !11, i64 1336}
!17 = !{!"int", !7, i64 0}
!18 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!19 = !{!10, !11, i64 32}
!20 = !{!10, !11, i64 40}
!21 = !{!17, !17, i64 0}
!22 = !{!16, !17, i64 0}
!23 = !{!10, !6, i64 48}
!24 = !{!11, !11, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @output_results_json(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.19) #2
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.20, double noundef %5) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.21, double noundef %8) #2
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !12
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.22, double noundef %11) #2
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load double, ptr %13, align 8, !tbaa !13
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.23, double noundef %14) #2
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.24) #2
  %17 = getelementptr inbounds i8, ptr %2, i64 1336
  %18 = load double, ptr %17, align 8, !tbaa !14
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.25, double noundef %18) #2
  %20 = getelementptr inbounds i8, ptr %1, i64 32
  %21 = load double, ptr %20, align 8, !tbaa !18
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.26, double noundef %21) #2
  %23 = getelementptr inbounds i8, ptr %1, i64 40
  %24 = load double, ptr %23, align 8, !tbaa !19
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.27, double noundef %24) #2
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.28) #2
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.29) #2
  %28 = load i32, ptr %2, align 8, !tbaa !20
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %30 = getelementptr inbounds i8, ptr %1, i64 48
  br label %32

._crit_edge:                                      ; preds = %32, %3
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.33) #2
  ret void

32:                                               ; preds = %.lr.ph, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %33 = phi i32 [ %28, %.lr.ph ], [ %42, %32 ]
  %34 = load ptr, ptr %30, align 8, !tbaa !21
  %35 = getelementptr inbounds double, ptr %34, i64 %indvars.iv
  %36 = load double, ptr %35, align 8, !tbaa !22
  %37 = add nsw i32 %33, -1
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv, %38
  %40 = select i1 %39, ptr @.str.31, ptr @.str.32
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.30, double noundef %36, ptr noundef nonnull %40) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr %2, align 8, !tbaa !20
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %32, label %._crit_edge, !llvm.loop !23
}

attributes #0 = { 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 #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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 24}
!14 = !{!15, !7, i64 1336}
!15 = !{!"", !16, i64 0, !16, i64 4, !17, i64 8, !8, i64 40, !16, i64 296, !16, i64 300, !16, i64 304, !8, i64 308, !7, i64 1336}
!16 = !{!"int", !8, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!18 = !{!6, !7, i64 32}
!19 = !{!6, !7, i64 40}
!20 = !{!15, !16, i64 0}
!21 = !{!6, !10, i64 48}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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