; LLVM IR from mbheinen/bpa-ipf-tsp :: cflow (convtbl)

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

@tmpbuf = external hidden global [200 x i8], align 16
@_ft = external global [27 x [26 x %struct.fld_table]], align 16
@record = external hidden global i32, align 4
@field = external hidden global i32, align 4
@cv_error = external dso_local global i32, align 4
@.str.13 = external hidden unnamed_addr constant [33 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden void @conv_error(i32 noundef, i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @f2a(float noundef, i32 noundef, i32 noundef) #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @cv_rec_b2a(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %13, ptr @record, align 4, !tbaa !9
  store i32 0, ptr @cv_error, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %102, %3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [27 x [26 x %struct.fld_table]], ptr @_ft, i64 0, i64 %16
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [26 x %struct.fld_table], ptr %17, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.fld_table, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %113

24:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [27 x [26 x %struct.fld_table]], ptr @_ft, i64 0, i64 %26
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [26 x %struct.fld_table], ptr %27, i64 0, i64 %29
  store ptr %30, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.fld_table, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %31, i64 %35
  store ptr %36, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.fld_table, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %37, i64 %41
  store ptr %42, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.fld_table, ptr %43, i32 0, i32 4
  %45 = load i32, ptr %44, align 4, !tbaa !11
  store i32 %45, ptr %11, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %46, ptr @field, align 4, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.fld_table, ptr %47, i32 0, i32 0
  %49 = load i8, ptr %48, align 4, !tbaa !15
  %50 = sext i8 %49 to i32
  switch i32 %50, label %98 [
    i32 115, label %51
    i32 102, label %84
    i32 108, label %92
  ]

51:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.fld_table, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 4, !tbaa !11
  store i32 %54, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  call void @llvm.memset.p0.i64(ptr align 16 @tmpbuf, i8 32, i64 %56, i1 false)
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = call i64 @strlen(ptr noundef %57) #7
  %59 = trunc i64 %58 to i32
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %51
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = call i64 @strlen(ptr noundef %63) #7
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %12, align 4, !tbaa !9
  br label %70

66:                                               ; preds = %51
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = call i64 @strlen(ptr noundef %67) #7
  %69 = trunc i64 %68 to i32
  call void @conv_error(i32 noundef %69, i32 noundef 3)
  br label %70

70:                                               ; preds = %66, %62
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.fld_table, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !16
  %74 = load i32, ptr %12, align 4, !tbaa !9
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %80

76:                                               ; preds = %70
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.fld_table, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 4, !tbaa !16
  store i32 %79, ptr %12, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %76, %70
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @tmpbuf, ptr align 1 %81, i64 %83, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %102

84:                                               ; preds = %24
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = load float, ptr %85, align 4, !tbaa !17
  %87 = load i32, ptr %11, align 4, !tbaa !9
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.fld_table, ptr %88, i32 0, i32 5
  %90 = load i32, ptr %89, align 4, !tbaa !19
  %91 = call ptr @f2a(float noundef %86, i32 noundef %87, i32 noundef %90)
  br label %102

92:                                               ; preds = %24
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load i32, ptr %93, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = load i32, ptr %11, align 4, !tbaa !9
  %97 = call ptr @l2a(i64 noundef %95, i32 noundef %96)
  br label %102

98:                                               ; preds = %24
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %99, i32 noundef %100)
  br label %102

102:                                              ; preds = %98, %92, %84, %80
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.fld_table, ptr %104, i32 0, i32 3
  %106 = load i32, ptr %105, align 4, !tbaa !13
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds i8, ptr %103, i64 %107
  %109 = load i32, ptr %11, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %108, ptr align 16 @tmpbuf, i64 %110, i1 false)
  %111 = load i32, ptr %7, align 4, !tbaa !9
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %14, !llvm.loop !20

113:                                              ; preds = %14
  %114 = load i32, ptr @cv_error, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  ret i32 %114
}

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 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!"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, !10, i64 16}
!12 = !{!"fld_table", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !7, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = !{!12, !10, i64 20}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.fld_table = type { i8, i32, i32, i32, i32, i32 }

@tmpbuf = external hidden local_unnamed_addr global [200 x i8], align 16
@_ft = external local_unnamed_addr global [27 x [26 x %struct.fld_table]], align 16
@record = external hidden local_unnamed_addr global i32, align 4
@field = external hidden local_unnamed_addr global i32, align 4
@cv_error = external dso_local local_unnamed_addr global i32, align 4
@.str.13 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @conv_error(i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @cv_rec_b2a(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  store i32 %2, ptr @record, align 4, !tbaa !5
  store i32 0, ptr @cv_error, align 4, !tbaa !5
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [27 x [26 x %struct.fld_table]], ptr @_ft, i64 0, i64 %4, i64 1
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %39
  %indvars.iv = phi i64 [ %indvars.iv.next, %39 ], [ 1, %3 ]
  %9 = phi i32 [ %46, %39 ], [ %7, %3 ]
  %10 = phi ptr [ %44, %39 ], [ %5, %3 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 12
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %1, i64 %14
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %16, ptr @field, align 4, !tbaa !5
  %17 = load i8, ptr %10, align 4, !tbaa !12
  switch i8 %17, label %37 [
    i8 115, label %18
    i8 102, label %28
    i8 108, label %33
  ]

18:                                               ; preds = %.lr.ph
  %19 = zext nneg i32 %9 to i64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) @tmpbuf, i8 32, i64 %19, i1 false)
  %20 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %15) #6
  %21 = trunc i64 %20 to i32
  %22 = icmp sgt i32 %9, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  tail call void @conv_error(i32 noundef %21, i32 noundef 3)
  br label %24

24:                                               ; preds = %18, %23
  %.0 = phi i32 [ %9, %23 ], [ %21, %18 ]
  %25 = getelementptr inbounds i8, ptr %10, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %spec.select = tail call i32 @llvm.smin.i32(i32 %26, i32 %.0)
  %27 = sext i32 %spec.select to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @tmpbuf, ptr align 1 %15, i64 %27, i1 false)
  br label %39

28:                                               ; preds = %.lr.ph
  %29 = load float, ptr %15, align 4, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %10, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = tail call ptr @f2a(float noundef %29, i32 noundef %9, i32 noundef %31)
  br label %39

33:                                               ; preds = %.lr.ph
  %34 = load i32, ptr %15, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = tail call ptr @l2a(i64 noundef %35, i32 noundef %9)
  br label %39

37:                                               ; preds = %.lr.ph
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %2, i32 noundef %16)
  br label %39

39:                                               ; preds = %37, %33, %28, %24
  %40 = load i32, ptr %11, align 4, !tbaa !17
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %0, i64 %41
  %43 = zext nneg i32 %9 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %42, ptr noundef nonnull align 16 dereferenceable(1) @tmpbuf, i64 %43, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = getelementptr inbounds [27 x [26 x %struct.fld_table]], ptr @_ft, i64 0, i64 %4, i64 %indvars.iv.next
  %45 = getelementptr inbounds i8, ptr %44, i64 16
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %39
  %.pre = load i32, ptr @cv_error, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %48 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %3 ]
  ret i32 %48
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #5

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 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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, !6, i64 16}
!10 = !{!"fld_table", !7, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!10, !6, i64 20}
!17 = !{!10, !6, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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