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

; 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.__va_list_tag = type { i32, i32, ptr, ptr }
%struct.ocl_ctx = type { ptr, ptr, ptr, i64, [20 x %struct.ocl_ctx_buf], i64, ptr, i64, ptr, ptr, i32 }
%struct.ocl_ctx_buf = type { ptr, i64, i64 }

; 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: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @set_kernel_arguments(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

declare i32 @clEnqueueNDRangeKernel(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @ocl_poll_event_until(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ocl_ctx_run_kernel(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ...) #2 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca [1 x %struct.__va_list_tag], align 16
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ocl_ctx, ptr %22, i32 0, i32 8
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %24, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  store ptr %27, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ocl_ctx, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds ptr, ptr %30, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr %33, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %18) #4
  %34 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %18, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %34)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %35 = load ptr, ptr %16, align 8, !tbaa !5
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = trunc i64 %36 to i32
  %38 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %18, i64 0, i64 0
  %39 = call i32 @set_kernel_arguments(ptr noundef %35, i32 noundef %37, ptr noundef %38)
  store i32 %39, ptr %19, align 4, !tbaa !15
  %40 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %18, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %40)
  %41 = load i32, ptr %19, align 4, !tbaa !15
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %7
  %44 = load i32, ptr %19, align 4, !tbaa !15
  store i32 %44, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %61

45:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %46 = load ptr, ptr %17, align 8, !tbaa !5
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = trunc i64 %48 to i32
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = call i32 @clEnqueueNDRangeKernel(ptr noundef %46, ptr noundef %47, i32 noundef %49, ptr noundef null, ptr noundef %50, ptr noundef %51, i32 noundef 0, ptr noundef null, ptr noundef %21)
  store i32 %52, ptr %19, align 4, !tbaa !15
  %53 = load i32, ptr %19, align 4, !tbaa !15
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %45
  %56 = load i32, ptr %19, align 4, !tbaa !15
  store i32 %56, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %60

57:                                               ; preds = %45
  %58 = load ptr, ptr %21, align 8, !tbaa !5
  %59 = call i32 @ocl_poll_event_until(ptr noundef %58, i32 noundef 0, i32 noundef 10)
  store i32 %59, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %60

60:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  br label %61

61:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %62 = load i32, ptr %8, align 4
  ret i32 %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
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 = { "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 = { 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 = !{!12, !6, i64 536}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !7, i64 32, !10, i64 512, !6, i64 520, !10, i64 528, !6, i64 536, !6, i64 544, !13, i64 552}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 520}
!15 = !{!13, !13, i64 0}


; 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.__va_list_tag = type { i32, i32, ptr, ptr }

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @set_kernel_arguments(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

declare i32 @clEnqueueNDRangeKernel(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @ocl_poll_event_until(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ocl_ctx_run_kernel(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ...) local_unnamed_addr #2 {
  %8 = alloca [1 x %struct.__va_list_tag], align 16
  %9 = alloca ptr, align 8
  %10 = getelementptr inbounds i8, ptr %0, i64 536
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds ptr, ptr %11, i64 %2
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 520
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds ptr, ptr %15, i64 %1
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #4
  call void @llvm.va_start.p0(ptr nonnull %8)
  %18 = trunc i64 %6 to i32
  %19 = call i32 @set_kernel_arguments(ptr noundef %13, i32 noundef %18, ptr noundef nonnull %8)
  call void @llvm.va_end.p0(ptr nonnull %8)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %27

20:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %21 = trunc i64 %3 to i32
  %22 = call i32 @clEnqueueNDRangeKernel(ptr noundef %17, ptr noundef %13, i32 noundef %21, ptr noundef null, ptr noundef %4, ptr noundef %5, i32 noundef 0, ptr noundef null, ptr noundef nonnull %9) #4
  %.not17 = icmp eq i32 %22, 0
  br i1 %.not17, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr %9, align 8, !tbaa !12
  %25 = call i32 @ocl_poll_event_until(ptr noundef %24, i32 noundef 0, i32 noundef 10)
  br label %26

26:                                               ; preds = %20, %23
  %.0 = phi i32 [ %25, %23 ], [ %22, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  br label %27

27:                                               ; preds = %7, %26
  %.1 = phi i32 [ %.0, %26 ], [ %19, %7 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #4
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = { "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 = { 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 536}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !8, i64 32, !10, i64 512, !7, i64 520, !10, i64 528, !7, i64 536, !7, i64 544, !11, i64 552}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 520}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass