; LLVM IR from stfc/PSycloneBench :: benchmarks/nemo/nemolite2d/manual_versions/psykal_c_opencl (opencl_utils)

; 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"

@stdout = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.68 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.70 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.72 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [1 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: nounwind uwtable
declare dso_local void @check_status(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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

; Function Attrs: nounwind
declare void @free(ptr 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
define dso_local ptr @get_binary_kernel(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 1, ptr %8, align 4, !tbaa !9
  %14 = call ptr @llvm.stacksave.p0()
  store ptr %14, ptr %9, align 8
  %15 = alloca ptr, i64 1, align 16
  %16 = alloca i64, i64 1, align 16
  %17 = alloca i32, i64 1, align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str.69)
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %26, label %22

22:                                               ; preds = %3
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.70, ptr noundef %24) #7
  call void @exit(i32 noundef 1) #8
  unreachable

26:                                               ; preds = %3
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i32 @fseek(ptr noundef %27, i64 noundef 0, i32 noundef 2)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call i64 @ftell(ptr noundef %29)
  %31 = getelementptr inbounds i64, ptr %16, i64 0
  store i64 %30, ptr %31, align 16, !tbaa !11
  %32 = getelementptr inbounds i64, ptr %16, i64 0
  %33 = load i64, ptr %32, align 16, !tbaa !11
  %34 = mul i64 1, %33
  %35 = call noalias ptr @malloc(i64 noundef %34) #9
  %36 = getelementptr inbounds ptr, ptr %15, i64 0
  store ptr %35, ptr %36, align 16, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  call void @rewind(ptr noundef %37)
  %38 = getelementptr inbounds ptr, ptr %15, i64 0
  %39 = load ptr, ptr %38, align 16, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %16, i64 0
  %41 = load i64, ptr %40, align 16, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i64 @fread(ptr noundef %39, i64 noundef %41, i64 noundef 1, ptr noundef %42)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = call i32 @fclose(ptr noundef %44)
  %46 = load ptr, ptr @stdout, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %16, i64 0
  %48 = load i64, ptr %47, align 16, !tbaa !11
  %49 = trunc i64 %48 to i32
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.71, i32 noundef %49, ptr noundef %50) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call ptr @clCreateProgramWithBinary(ptr noundef %52, i32 noundef 1, ptr noundef %53, ptr noundef %16, ptr noundef %15, ptr noundef %17, ptr noundef %11)
  store ptr %54, ptr %12, align 8, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !9
  call void @check_status(ptr noundef @.str.72, i32 noundef %55)
  %56 = getelementptr inbounds i32, ptr %17, i64 0
  %57 = load i32, ptr %56, align 16, !tbaa !9
  call void @check_status(ptr noundef @.str.73, i32 noundef %57)
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = call i32 @clBuildProgram(ptr noundef %58, i32 noundef 0, ptr noundef null, ptr noundef @.str.74, ptr noundef null, ptr noundef null)
  store i32 %59, ptr %11, align 4, !tbaa !9
  %60 = load i32, ptr %11, align 4, !tbaa !9
  call void @check_status(ptr noundef @.str.68, i32 noundef %60)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %70, %26
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = icmp slt i32 %62, 1
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %73

65:                                               ; preds = %61
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %15, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  call void @free(ptr noundef %69) #7
  br label %70

70:                                               ; preds = %65
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %13, align 4, !tbaa !9
  br label %61, !llvm.loop !13

73:                                               ; preds = %64
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %75 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %75)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  ret ptr %74
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #5

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #5

declare i32 @fclose(ptr noundef) #5

declare i32 @clBuildProgram(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #6

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #5

declare i64 @ftell(ptr noundef) #5

declare void @rewind(ptr noundef) #5

declare ptr @clCreateProgramWithBinary(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 "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 = { 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 #4 = { 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 #5 = { "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 #6 = { nocallback nofree nosync nounwind willreturn }
attributes #7 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.68 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.70 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.72 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [1 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @get_binary_kernel(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 16
  %6 = alloca i64, align 16
  %7 = alloca i32, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  %8 = tail call noalias ptr @fopen(ptr noundef %2, ptr noundef nonnull @.str.69)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %.critedge

9:                                                ; preds = %3
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.70, ptr noundef %2) #8
  tail call void @exit(i32 noundef 1) #9
  unreachable

.critedge:                                        ; preds = %3
  %12 = tail call i32 @fseek(ptr noundef nonnull %8, i64 noundef 0, i32 noundef 2)
  %13 = tail call i64 @ftell(ptr noundef nonnull %8)
  store i64 %13, ptr %6, align 16, !tbaa !9
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #10
  store ptr %14, ptr %5, align 16, !tbaa !5
  tail call void @rewind(ptr noundef nonnull %8)
  %15 = tail call i64 @fread(ptr noundef %14, i64 noundef %13, i64 noundef 1, ptr noundef nonnull %8)
  %16 = tail call i32 @fclose(ptr noundef nonnull %8)
  %17 = load ptr, ptr @stdout, align 8, !tbaa !5
  %18 = trunc i64 %13 to i32
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.71, i32 noundef %18, ptr noundef %2) #7
  %20 = call ptr @clCreateProgramWithBinary(ptr noundef %0, i32 noundef 1, ptr noundef %1, ptr noundef nonnull %6, ptr noundef nonnull %5, ptr noundef nonnull %7, ptr noundef nonnull %4) #7
  %21 = load i32, ptr %4, align 4, !tbaa !11
  call void @check_status(ptr noundef nonnull @.str.72, i32 noundef %21)
  %22 = load i32, ptr %7, align 16, !tbaa !11
  call void @check_status(ptr noundef nonnull @.str.73, i32 noundef %22)
  %23 = call i32 @clBuildProgram(ptr noundef %20, i32 noundef 0, ptr noundef null, ptr noundef nonnull @.str.74, ptr noundef null, ptr noundef null) #7
  store i32 %23, ptr %4, align 4, !tbaa !11
  call void @check_status(ptr noundef nonnull @.str.68, i32 noundef %23)
  %24 = load ptr, ptr %5, align 16, !tbaa !5
  call void @free(ptr noundef %24) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  ret ptr %20
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

declare i32 @clBuildProgram(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @ftell(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @clCreateProgramWithBinary(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #3 = { 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 #4 = { 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 #5 = { 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 #6 = { "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 #7 = { nounwind }
attributes #8 = { cold nounwind }
attributes #9 = { noreturn nounwind }
attributes #10 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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