; 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.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 }

@.str.66 = external hidden unnamed_addr constant [68 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @ocl_check_err(i32 noundef, ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare i32 @clReleaseMemObject(ptr noundef) #3

declare i32 @clFinish(ptr noundef) #3

declare i32 @clReleaseCommandQueue(ptr noundef) #3

declare i32 @clReleaseContext(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @ocl_ctx_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %35, %1
  %7 = load i64, ptr %3, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ocl_ctx, ptr %8, i32 0, i32 5
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = icmp ult i64 %7, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %38

13:                                               ; preds = %6
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ocl_ctx, ptr %14, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = getelementptr inbounds ptr, ptr %16, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = call i32 @clFlush(ptr noundef %19)
  call void @ocl_check_err(i32 noundef %20, ptr noundef @.str.66, i32 noundef 593)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ocl_ctx, ptr %21, i32 0, i32 6
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load i64, ptr %3, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = call i32 @clFinish(ptr noundef %26)
  call void @ocl_check_err(i32 noundef %27, ptr noundef @.str.66, i32 noundef 594)
  %28 = load ptr, ptr %2, 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 %3, align 8, !tbaa !9
  %32 = getelementptr inbounds ptr, ptr %30, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = call i32 @clReleaseCommandQueue(ptr noundef %33)
  br label %35

35:                                               ; preds = %13
  %36 = load i64, ptr %3, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %3, align 8, !tbaa !9
  br label %6, !llvm.loop !15

38:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %54, %38
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ocl_ctx, ptr %41, i32 0, i32 7
  %43 = load i64, ptr %42, align 8, !tbaa !17
  %44 = icmp ult i64 %40, %43
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %39
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ocl_ctx, ptr %47, i32 0, i32 8
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = getelementptr inbounds ptr, ptr %49, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = call i32 @clReleaseKernel(ptr noundef %52)
  br label %54

54:                                               ; preds = %46
  %55 = load i64, ptr %4, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %4, align 8, !tbaa !9
  br label %39, !llvm.loop !19

57:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %73, %57
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ocl_ctx, ptr %60, i32 0, i32 3
  %62 = load i64, ptr %61, align 8, !tbaa !20
  %63 = icmp ult i64 %59, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %76

65:                                               ; preds = %58
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ocl_ctx, ptr %66, i32 0, i32 4
  %68 = load i64, ptr %5, align 8, !tbaa !9
  %69 = getelementptr inbounds [20 x %struct.ocl_ctx_buf], ptr %67, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.ocl_ctx_buf, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = call i32 @clReleaseMemObject(ptr noundef %71)
  br label %73

73:                                               ; preds = %65
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %5, align 8, !tbaa !9
  br label %58, !llvm.loop !23

76:                                               ; preds = %64
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ocl_ctx, ptr %77, i32 0, i32 9
  %79 = load ptr, ptr %78, align 8, !tbaa !24
  %80 = call i32 @clReleaseProgram(ptr noundef %79)
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.ocl_ctx, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !25
  %84 = call i32 @clReleaseContext(ptr noundef %83)
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ocl_ctx, ptr %85, i32 0, i32 8
  %87 = load ptr, ptr %86, align 8, !tbaa !18
  call void @free(ptr noundef %87) #4
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ocl_ctx, ptr %88, i32 0, i32 6
  %90 = load ptr, ptr %89, align 8, !tbaa !14
  call void @free(ptr noundef %90) #4
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %91) #4
  ret void
}

declare i32 @clFlush(ptr noundef) #3

declare i32 @clReleaseKernel(ptr noundef) #3

declare i32 @clReleaseProgram(ptr noundef) #3

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 = { 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 #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, !10, i64 512}
!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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 528}
!18 = !{!12, !6, i64 536}
!19 = distinct !{!19, !16}
!20 = !{!12, !10, i64 24}
!21 = !{!22, !6, i64 0}
!22 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16}
!23 = distinct !{!23, !16}
!24 = !{!12, !6, i64 544}
!25 = !{!12, !6, 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.ocl_ctx_buf = type { ptr, i64, i64 }

@.str.66 = external hidden unnamed_addr constant [68 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @ocl_check_err(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

declare i32 @clReleaseMemObject(ptr noundef) local_unnamed_addr #2

declare i32 @clFinish(ptr noundef) local_unnamed_addr #2

declare i32 @clReleaseCommandQueue(ptr noundef) local_unnamed_addr #2

declare i32 @clReleaseContext(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @ocl_ctx_free(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 512
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.preheader25, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 520
  br label %8

.preheader25:                                     ; preds = %8, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 528
  %6 = load i64, ptr %5, align 8, !tbaa !12
  %.not31 = icmp eq i64 %6, 0
  br i1 %.not31, label %.preheader, label %.lr.ph28

.lr.ph28:                                         ; preds = %.preheader25
  %7 = getelementptr inbounds i8, ptr %0, i64 536
  br label %27

8:                                                ; preds = %.lr.ph, %8
  %.02426 = phi i64 [ 0, %.lr.ph ], [ %21, %8 ]
  %9 = load ptr, ptr %4, align 8, !tbaa !13
  %10 = getelementptr inbounds ptr, ptr %9, i64 %.02426
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = tail call i32 @clFlush(ptr noundef %11) #3
  tail call void @ocl_check_err(i32 noundef %12, ptr noundef nonnull @.str.66, i32 noundef 593)
  %13 = load ptr, ptr %4, align 8, !tbaa !13
  %14 = getelementptr inbounds ptr, ptr %13, i64 %.02426
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = tail call i32 @clFinish(ptr noundef %15) #3
  tail call void @ocl_check_err(i32 noundef %16, ptr noundef nonnull @.str.66, i32 noundef 594)
  %17 = load ptr, ptr %4, align 8, !tbaa !13
  %18 = getelementptr inbounds ptr, ptr %17, i64 %.02426
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = tail call i32 @clReleaseCommandQueue(ptr noundef %19) #3
  %21 = add nuw i64 %.02426, 1
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %8, label %.preheader25, !llvm.loop !15

.preheader:                                       ; preds = %27, %.preheader25
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load i64, ptr %24, align 8, !tbaa !17
  %.not32 = icmp eq i64 %25, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %.preheader
  %26 = getelementptr inbounds i8, ptr %0, i64 32
  br label %45

27:                                               ; preds = %.lr.ph28, %27
  %.02327 = phi i64 [ 0, %.lr.ph28 ], [ %32, %27 ]
  %28 = load ptr, ptr %7, align 8, !tbaa !18
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.02327
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = tail call i32 @clReleaseKernel(ptr noundef %30) #3
  %32 = add nuw i64 %.02327, 1
  %33 = load i64, ptr %5, align 8, !tbaa !12
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %27, label %.preheader, !llvm.loop !19

._crit_edge:                                      ; preds = %45, %.preheader
  %35 = getelementptr inbounds i8, ptr %0, i64 544
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = tail call i32 @clReleaseProgram(ptr noundef %36) #3
  %38 = getelementptr inbounds i8, ptr %0, i64 16
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = tail call i32 @clReleaseContext(ptr noundef %39) #3
  %41 = getelementptr inbounds i8, ptr %0, i64 536
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  tail call void @free(ptr noundef %42) #3
  %43 = getelementptr inbounds i8, ptr %0, i64 520
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  tail call void @free(ptr noundef %44) #3
  tail call void @free(ptr noundef nonnull %0) #3
  ret void

45:                                               ; preds = %.lr.ph30, %45
  %.029 = phi i64 [ 0, %.lr.ph30 ], [ %49, %45 ]
  %46 = getelementptr inbounds [20 x %struct.ocl_ctx_buf], ptr %26, i64 0, i64 %.029
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  %48 = tail call i32 @clReleaseMemObject(ptr noundef %47) #3
  %49 = add nuw i64 %.029, 1
  %50 = load i64, ptr %24, align 8, !tbaa !17
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %45, label %._crit_edge, !llvm.loop !24
}

declare i32 @clFlush(ptr noundef) local_unnamed_addr #2

declare i32 @clReleaseKernel(ptr noundef) local_unnamed_addr #2

declare i32 @clReleaseProgram(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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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, !10, i64 512}
!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 = !{!6, !10, i64 528}
!13 = !{!6, !7, i64 520}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !10, i64 24}
!18 = !{!6, !7, i64 536}
!19 = distinct !{!19, !16}
!20 = !{!6, !7, i64 544}
!21 = !{!6, !7, i64 16}
!22 = !{!23, !7, i64 0}
!23 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16}
!24 = distinct !{!24, !16}


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