; 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.91 = external hidden unnamed_addr constant [2 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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @ocl_print_device_details(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @ocl_basic_setup(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @ocl_ctx_init(i32 noundef %0, i32 noundef %1, i1 noundef zeroext %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = call noalias ptr @malloc(i64 noundef 560) #5
  store ptr %9, ptr %7, align 8, !tbaa !11
  %10 = load ptr, ptr %7, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.ocl_ctx, ptr %10, i32 0, i32 5
  store i64 0, ptr %11, align 8, !tbaa !13
  %12 = call noalias ptr @malloc(i64 noundef 160) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.ocl_ctx, ptr %13, i32 0, i32 6
  store ptr %12, ptr %14, align 8, !tbaa !16
  %15 = load ptr, ptr %7, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.ocl_ctx, ptr %15, i32 0, i32 7
  store i64 0, ptr %16, align 8, !tbaa !17
  %17 = call noalias ptr @malloc(i64 noundef 160) #5
  %18 = load ptr, ptr %7, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.ocl_ctx, ptr %18, i32 0, i32 8
  store ptr %17, ptr %19, align 8, !tbaa !18
  %20 = load ptr, ptr %7, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.ocl_ctx, ptr %20, i32 0, i32 3
  store i64 0, ptr %21, align 8, !tbaa !19
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.ocl_ctx, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %7, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.ocl_ctx, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %7, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.ocl_ctx, ptr %28, i32 0, i32 2
  %30 = call i32 @ocl_basic_setup(i32 noundef %22, i32 noundef %23, ptr noundef %25, ptr noundef %27, ptr noundef %29, i64 noundef 0, ptr noundef null)
  %31 = load ptr, ptr %7, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.ocl_ctx, ptr %31, i32 0, i32 10
  store i32 %30, ptr %32, align 8, !tbaa !20
  %33 = load ptr, ptr %7, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.ocl_ctx, ptr %33, i32 0, i32 10
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %3
  %38 = load i8, ptr %6, align 1, !tbaa !9, !range !21, !noundef !22
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %45

40:                                               ; preds = %37
  %41 = load ptr, ptr %7, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.ocl_ctx, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !23
  call void @ocl_print_device_details(ptr noundef %43, ptr noundef null)
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.91)
  br label %45

45:                                               ; preds = %40, %37, %3
  %46 = load ptr, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %46
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 allocsize(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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !15, i64 512}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !15, i64 24, !7, i64 32, !15, i64 512, !12, i64 520, !15, i64 528, !12, i64 536, !12, i64 544, !6, i64 552}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !12, i64 520}
!17 = !{!14, !15, i64 528}
!18 = !{!14, !12, i64 536}
!19 = !{!14, !15, i64 24}
!20 = !{!14, !6, i64 552}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!14, !12, i64 8}


; 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.91 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ocl_ctx_init(i32 noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = tail call noalias dereferenceable_or_null(560) ptr @malloc(i64 noundef 560) #3
  %5 = getelementptr inbounds i8, ptr %4, i64 512
  store i64 0, ptr %5, align 8, !tbaa !5
  %6 = tail call noalias dereferenceable_or_null(160) ptr @malloc(i64 noundef 160) #3
  %7 = getelementptr inbounds i8, ptr %4, i64 520
  store ptr %6, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %4, i64 528
  store i64 0, ptr %8, align 8, !tbaa !13
  %9 = tail call noalias dereferenceable_or_null(160) ptr @malloc(i64 noundef 160) #3
  %10 = getelementptr inbounds i8, ptr %4, i64 536
  store ptr %9, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %4, i64 24
  store i64 0, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %4, i64 8
  %13 = getelementptr inbounds i8, ptr %4, i64 16
  %14 = tail call i32 @ocl_basic_setup(i32 noundef %0, i32 noundef %1, ptr noundef %4, ptr noundef nonnull %12, ptr noundef nonnull %13, i64 noundef 0, ptr noundef null)
  %15 = getelementptr inbounds i8, ptr %4, i64 552
  store i32 %14, ptr %15, align 8, !tbaa !16
  %16 = icmp eq i32 %14, 0
  %brmerge.not = and i1 %16, %2
  br i1 %brmerge.not, label %17, label %20

17:                                               ; preds = %3
  %18 = load ptr, ptr %12, align 8, !tbaa !17
  tail call void @ocl_print_device_details(ptr noundef %18, ptr noundef null)
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.91)
  br label %20

20:                                               ; preds = %3, %17
  ret ptr %4
}

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { 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 allocsize(0) }

!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, !7, i64 520}
!13 = !{!6, !10, i64 528}
!14 = !{!6, !7, i64 536}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !11, i64 552}
!17 = !{!6, !7, i64 8}


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