; 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.34 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [9 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_csv(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.34) #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.35, 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.36, 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.37, 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.38, double noundef %28) #3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.simulation_config_t, ptr %31, i32 0, i32 8
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.39, double noundef %33) #3
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.simulation_results_t, ptr %36, i32 0, i32 4
  %38 = load double, ptr %37, align 8, !tbaa !19
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.40, double noundef %38) #3
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.simulation_results_t, ptr %41, i32 0, i32 5
  %43 = load double, ptr %42, align 8, !tbaa !20
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str.41, double noundef %43) #3
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.42) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !21
  br label %47

47:                                               ; preds = %66, %3
  %48 = load i32, ptr %7, align 4, !tbaa !21
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.simulation_config_t, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !22
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %54, label %53

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

54:                                               ; preds = %47
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !21
  %57 = add nsw i32 %56, 1
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.simulation_results_t, ptr %58, i32 0, i32 6
  %60 = load ptr, ptr %59, align 8, !tbaa !23
  %61 = load i32, ptr %7, align 4, !tbaa !21
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !24
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.43, i32 noundef %57, double noundef %64) #3
  br label %66

66:                                               ; preds = %54
  %67 = load i32, ptr %7, align 4, !tbaa !21
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !21
  br label %47, !llvm.loop !25

69:                                               ; preds = %53
  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.34 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [9 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_csv(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.34) #2
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.35, 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.36, 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.37, 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.38, double noundef %14) #2
  %16 = getelementptr inbounds i8, ptr %2, i64 1336
  %17 = load double, ptr %16, align 8, !tbaa !14
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.39, double noundef %17) #2
  %19 = getelementptr inbounds i8, ptr %1, i64 32
  %20 = load double, ptr %19, align 8, !tbaa !18
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.40, double noundef %20) #2
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  %23 = load double, ptr %22, align 8, !tbaa !19
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.41, double noundef %23) #2
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.42) #2
  %26 = load i32, ptr %2, align 8, !tbaa !20
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %29, %3
  ret void

29:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = load ptr, ptr %28, align 8, !tbaa !21
  %31 = getelementptr inbounds double, ptr %30, i64 %indvars.iv
  %32 = load double, ptr %31, align 8, !tbaa !22
  %33 = trunc nuw nsw i64 %indvars.iv.next to i32
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.43, i32 noundef %33, double noundef %32) #2
  %35 = load i32, ptr %2, align 8, !tbaa !20
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next, %36
  br i1 %37, label %29, 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