; LLVM IR from bjourne/fast_snn_fpga :: src (main)

; 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.sim_result = type { i32, i64, ptr }
%struct.sim_config = type { i32, ptr, i8, ptr, i32, i32, i8, i32, i32, i8, double, double, double, double, double, double, double, i8, i32, ptr, i32, ptr, ptr, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [103 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [66 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [23 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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.sim_result, align 8
  %10 = alloca %struct.sim_result, align 8
  %11 = alloca %struct.sim_result, align 8
  %12 = alloca double, align 8
  %13 = alloca double, 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) #5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call ptr @sim_config_init(i32 noundef %14, ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %74

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  call void @sim_config_print(ptr noundef %21)
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.sim_config, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  store i32 %25, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.sim_config, ptr %27, i32 0, i32 23
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = icmp ugt i32 %26, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %20
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.sim_config, ptr %33, i32 0, i32 23
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %32, i32 noundef %35)
  br label %37

37:                                               ; preds = %31, %20
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  call void @sim_config_print_banner(ptr noundef %38)
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.sim_config, ptr %39, i32 0, i32 2
  %41 = load i8, ptr %40, align 8, !tbaa !16, !range !17, !noundef !18
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %45

43:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #5
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  call void @sim_config_run_on_cpu(ptr dead_on_unwind writable sret(%struct.sim_result) align 8 %10, ptr noundef %44)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %10, i64 24, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #5
  br label %47

45:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #5
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  call void @sim_config_run_on_opencl(ptr dead_on_unwind writable sret(%struct.sim_result) align 8 %11, ptr noundef %46)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %11, i64 24, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #5
  br label %47

47:                                               ; preds = %45, %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %48 = getelementptr inbounds %struct.sim_result, ptr %9, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !22
  %50 = call double @nanos_to_secs(i64 noundef %49)
  store double %50, ptr %12, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %51 = load double, ptr %12, align 8, !tbaa !24
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = uitofp i32 %52 to double
  %54 = fdiv double %53, 1.000000e+04
  %55 = fdiv double %51, %54
  store double %55, ptr %13, align 8, !tbaa !24
  %56 = getelementptr inbounds %struct.sim_result, ptr %9, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !25
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load double, ptr %12, align 8, !tbaa !24
  %60 = load double, ptr %13, align 8, !tbaa !24
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %57, i32 noundef %58, double noundef %59, double noundef %60)
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.sim_result, ptr %9, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !26
  call void @sim_config_save_spikes(ptr noundef %62, ptr noundef %64)
  %65 = getelementptr inbounds %struct.sim_result, ptr %9, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !26
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %69

68:                                               ; preds = %47
  br label %70

69:                                               ; preds = %47
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 57, ptr noundef @__PRETTY_FUNCTION__.main) #6
  unreachable

70:                                               ; preds = %68
  %71 = getelementptr inbounds %struct.sim_result, ptr %9, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !26
  call void @npy_free(ptr noundef %72)
  %73 = load ptr, ptr %6, align 8, !tbaa !9
  call void @sim_config_free(ptr noundef %73)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %74

74:                                               ; preds = %70, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %75 = load i32, ptr %3, align 4
  ret i32 %75
}

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

declare ptr @sim_config_init(i32 noundef, ptr noundef) #2

declare void @sim_config_print(ptr noundef) #2

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

declare void @sim_config_print_banner(ptr noundef) #2

declare void @sim_config_run_on_cpu(ptr dead_on_unwind writable sret(%struct.sim_result) align 8, ptr noundef) #2

; 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) #3

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

declare void @sim_config_run_on_opencl(ptr dead_on_unwind writable sret(%struct.sim_result) align 8, ptr noundef) #2

declare double @nanos_to_secs(i64 noundef) #2

declare void @sim_config_save_spikes(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare void @npy_free(ptr noundef) #2

declare void @sim_config_free(ptr noundef) #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 = { 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: readwrite) }
attributes #4 = { noreturn 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !6, i64 32, !6, i64 36, !13, i64 40, !6, i64 44, !6, i64 48, !13, i64 52, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !7, i64 112, !6, i64 116, !10, i64 120, !6, i64 128, !10, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !10, i64 168}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !6, i64 152}
!16 = !{!12, !13, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{i64 0, i64 4, !5, i64 8, i64 8, !20, i64 16, i64 8, !9}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!23, !21, i64 8}
!23 = !{!"", !6, i64 0, !21, i64 8, !10, i64 16}
!24 = !{!14, !14, i64 0}
!25 = !{!23, !6, i64 0}
!26 = !{!23, !10, i64 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"

%struct.sim_result = type { i32, i64, ptr }

@.str = external hidden unnamed_addr constant [103 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [66 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.sim_result, align 8
  %4 = alloca %struct.sim_result, align 8
  %5 = tail call ptr @sim_config_init(i32 noundef %0, ptr noundef %1) #5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %28, label %6

6:                                                ; preds = %2
  tail call void @sim_config_print(ptr noundef nonnull %5) #5
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %8 = load i32, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 152
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp ugt i32 %8, %10
  br i1 %11, label %12, label %14

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

14:                                               ; preds = %12, %6
  tail call void @sim_config_print_banner(ptr noundef nonnull %5) #5
  %15 = getelementptr inbounds i8, ptr %5, i64 16
  %16 = load i8, ptr %15, align 8, !tbaa !14, !range !15, !noundef !16
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @sim_config_run_on_cpu(ptr dead_on_unwind nonnull writable sret(%struct.sim_result) align 8 %3, ptr noundef nonnull %5) #5
  %.sroa.0.0.copyload = load i32, ptr %3, align 8, !tbaa !17
  %.sroa.56.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.56.0.copyload = load i64, ptr %.sroa.56.0..sroa_idx, align 8, !tbaa !18
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 16
  %.sroa.6.0.copyload = load ptr, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  br label %20

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  call void @sim_config_run_on_opencl(ptr dead_on_unwind nonnull writable sret(%struct.sim_result) align 8 %4, ptr noundef nonnull %5) #5
  %.sroa.0.0.copyload3 = load i32, ptr %4, align 8, !tbaa !17
  %.sroa.56.0..sroa_idx7 = getelementptr inbounds i8, ptr %4, i64 8
  %.sroa.56.0.copyload8 = load i64, ptr %.sroa.56.0..sroa_idx7, align 8, !tbaa !18
  %.sroa.6.0..sroa_idx9 = getelementptr inbounds i8, ptr %4, i64 16
  %.sroa.6.0.copyload10 = load ptr, ptr %.sroa.6.0..sroa_idx9, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  br label %20

20:                                               ; preds = %19, %18
  %.sroa.6.0 = phi ptr [ %.sroa.6.0.copyload, %18 ], [ %.sroa.6.0.copyload10, %19 ]
  %.sroa.56.0 = phi i64 [ %.sroa.56.0.copyload, %18 ], [ %.sroa.56.0.copyload8, %19 ]
  %.sroa.0.0 = phi i32 [ %.sroa.0.0.copyload, %18 ], [ %.sroa.0.0.copyload3, %19 ]
  %21 = call double @nanos_to_secs(i64 noundef %.sroa.56.0) #5
  %22 = uitofp i32 %8 to double
  %23 = fdiv double %22, 1.000000e+04
  %24 = fdiv double %21, %23
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.sroa.0.0, i32 noundef %8, double noundef %21, double noundef %24)
  call void @sim_config_save_spikes(ptr noundef nonnull %5, ptr noundef %.sroa.6.0) #5
  %.not33 = icmp eq ptr %.sroa.6.0, null
  br i1 %.not33, label %26, label %27

26:                                               ; preds = %20
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 57, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #6
  unreachable

27:                                               ; preds = %20
  call void @npy_free(ptr noundef nonnull %.sroa.6.0) #5
  call void @sim_config_free(ptr noundef nonnull %5) #5
  br label %28

28:                                               ; preds = %2, %27
  %.0 = phi i32 [ 0, %27 ], [ 1, %2 ]
  ret i32 %.0
}

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

declare ptr @sim_config_init(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @sim_config_print(ptr noundef) local_unnamed_addr #2

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

declare void @sim_config_print_banner(ptr noundef) local_unnamed_addr #2

declare void @sim_config_run_on_cpu(ptr dead_on_unwind writable sret(%struct.sim_result) align 8, ptr noundef) local_unnamed_addr #2

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

declare void @sim_config_run_on_opencl(ptr dead_on_unwind writable sret(%struct.sim_result) align 8, ptr noundef) local_unnamed_addr #2

declare double @nanos_to_secs(i64 noundef) local_unnamed_addr #2

declare void @sim_config_save_spikes(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

declare void @npy_free(ptr noundef) local_unnamed_addr #2

declare void @sim_config_free(ptr noundef) 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 = { mustprogress 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 = { 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 #4 = { noreturn 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !10, i64 8, !11, i64 16, !10, i64 24, !7, i64 32, !7, i64 36, !11, i64 40, !7, i64 44, !7, i64 48, !11, i64 52, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !8, i64 112, !7, i64 116, !10, i64 120, !7, i64 128, !10, i64 136, !10, i64 144, !7, i64 152, !10, i64 160, !10, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!6, !7, i64 152}
!14 = !{!6, !11, i64 16}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !8, i64 0}
!20 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass