; LLVM IR from mbheinen/bpa-ipf-tsp :: bpf (bpf_sub)

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

@bpf_sub.i = external hidden global i32, align 4
@bpf_sub.pfc_file = external hidden global [60 x i8], align 16
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @bpf_sub(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %19

7:                                                ; preds = %2
  store i32 0, ptr @bpf_sub.i, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %15, %7
  %9 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 60
  br i1 %10, label %11, label %18

11:                                               ; preds = %8
  %12 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [60 x i8], ptr @bpf_sub.pfc_file, i64 0, i64 %13
  store i8 32, ptr %14, align 1, !tbaa !11
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @bpf_sub.i, align 4, !tbaa !5
  br label %8, !llvm.loop !12

18:                                               ; preds = %8
  br label %57

19:                                               ; preds = %2
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 2
  br i1 %21, label %30, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 0
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 63
  br i1 %29, label %30, label %39

30:                                               ; preds = %22, %19
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, 2
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load ptr, ptr @stderr, align 8, !tbaa !9
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str) #5
  br label %36

36:                                               ; preds = %33, %30
  %37 = load ptr, ptr @stderr, align 8, !tbaa !9
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str.1) #5
  call void @exit(i32 noundef 1) #6
  unreachable

39:                                               ; preds = %22
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call ptr @strcpy(ptr noundef @bpf_sub.pfc_file, ptr noundef %42) #5
  %44 = call i64 @strlen(ptr noundef @bpf_sub.pfc_file) #7
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr @bpf_sub.i, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %49, %39
  %47 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %48 = icmp slt i32 %47, 60
  br i1 %48, label %49, label %55

49:                                               ; preds = %46
  %50 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [60 x i8], ptr @bpf_sub.pfc_file, i64 0, i64 %51
  store i8 32, ptr %52, align 1, !tbaa !11
  %53 = load i32, ptr @bpf_sub.i, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr @bpf_sub.i, align 4, !tbaa !5
  br label %46, !llvm.loop !14

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56, %18
  call void @pwrflo(ptr noundef @bpf_sub.pfc_file)
  call void @exit(i32 noundef 1) #6
  unreachable
}

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare void @pwrflo(ptr noundef) #4

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 = { 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 #2 = { 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 #3 = { nounwind willreturn memory(read) "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 = { "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 }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@bpf_sub.i = external hidden local_unnamed_addr global i32, align 4
@bpf_sub.pfc_file = external hidden global [60 x i8], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @bpf_sub(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  switch i32 %0, label %8 [
    i32 1, label %.preheader.preheader
    i32 2, label %3
  ]

.preheader.preheader:                             ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(60) @bpf_sub.pfc_file, i8 32, i64 60, i1 false), !tbaa !5
  br label %.loopexit7

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !8
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = icmp eq i8 %6, 63
  br i1 %7, label %.thread, label %15

8:                                                ; preds = %2
  %9 = icmp sgt i32 %0, 2
  br i1 %9, label %10, label %.thread

10:                                               ; preds = %8
  %11 = load ptr, ptr @stderr, align 8, !tbaa !8
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str) #7
  br label %.thread

.thread:                                          ; preds = %3, %10, %8
  %13 = load ptr, ptr @stderr, align 8, !tbaa !8
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.1) #7
  tail call void @exit(i32 noundef 1) #8
  unreachable

15:                                               ; preds = %3
  %16 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @bpf_sub.pfc_file, ptr noundef nonnull dereferenceable(1) %5) #9
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @bpf_sub.pfc_file) #10
  %18 = trunc i64 %17 to i32
  %19 = icmp slt i32 %18, 60
  br i1 %19, label %.lr.ph.preheader, label %.loopexit7

.lr.ph.preheader:                                 ; preds = %15
  %sext = shl i64 %17, 32
  %20 = ashr exact i64 %sext, 32
  %scevgep = getelementptr i8, ptr @bpf_sub.pfc_file, i64 %20
  %21 = sub i64 59, %17
  %22 = and i64 %21, 4294967295
  %23 = add nuw nsw i64 %22, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 32, i64 %23, i1 false), !tbaa !5
  br label %.loopexit7

.loopexit7:                                       ; preds = %15, %.lr.ph.preheader, %.preheader.preheader
  %storemerge = phi i32 [ 60, %.preheader.preheader ], [ %18, %15 ], [ 60, %.lr.ph.preheader ]
  store i32 %storemerge, ptr @bpf_sub.i, align 4, !tbaa !10
  tail call void @pwrflo(ptr noundef nonnull @bpf_sub.pfc_file) #9
  tail call void @exit(i32 noundef 1) #8
  unreachable
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

declare void @pwrflo(ptr noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

attributes #0 = { noreturn 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 = { 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 #2 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 memory(argmem: read) "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 nounwind willreturn memory(argmem: write) }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind }
attributes #10 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass