; LLVM IR from freakout42/macrocalc :: arx/src (dbf_from)

; 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.DBF = type { [1024 x i8], [1024 x i8], ptr, ptr, i32, i32, i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, ptr, ptr, %struct.DBFPROLOG }
%struct.DBFPROLOG = type { i8, i8, i8, i8, i32, i16, i16, i16, i8, i8, [12 x i8], i8, [3 x i8] }
%struct.FIELD_RECORD = type { [11 x i8], i8, i32, i8, i8, [14 x i8] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dbf_from(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %61

9:                                                ; preds = %2
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i8 1, ptr %5, align 1, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.DBF, ptr %11, i32 0, i32 16
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  store ptr %13, ptr %6, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %54, %9
  %15 = load i8, ptr %5, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.DBF, ptr %17, i32 0, i32 15
  %19 = load i8, ptr %18, align 8, !tbaa !16
  %20 = zext i8 %19 to i32
  %21 = icmp sle i32 %16, %20
  br i1 %21, label %22, label %59

22:                                               ; preds = %14
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.FIELD_RECORD, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [11 x i8], ptr %24, i64 0, i64 0
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.FIELD_RECORD, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [11 x i8], ptr %27, i64 0, i64 0
  %29 = call i64 @strlen(ptr noundef %28) #5
  %30 = trunc i64 %29 to i32
  %31 = sub nsw i32 11, %30
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.FIELD_RECORD, ptr %32, i32 0, i32 1
  %34 = load i8, ptr %33, align 1, !tbaa !17
  %35 = zext i8 %34 to i32
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.FIELD_RECORD, ptr %36, i32 0, i32 3
  %38 = load i8, ptr %37, align 4, !tbaa !19
  %39 = zext i8 %38 to i32
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.FIELD_RECORD, ptr %40, i32 0, i32 4
  %42 = load i8, ptr %41, align 1, !tbaa !20
  %43 = zext i8 %42 to i32
  %44 = load i8, ptr %5, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.DBF, ptr %46, i32 0, i32 15
  %48 = load i8, ptr %47, align 8, !tbaa !16
  %49 = zext i8 %48 to i32
  %50 = icmp eq i32 %45, %49
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 32, i32 44
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %25, i32 noundef %31, ptr noundef @.str.2, i32 noundef %35, i32 noundef %39, i32 noundef %43, i32 noundef %52)
  br label %54

54:                                               ; preds = %22
  %55 = load i8, ptr %5, align 1, !tbaa !11
  %56 = add i8 %55, 1
  store i8 %56, ptr %5, align 1, !tbaa !11
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.FIELD_RECORD, ptr %57, i32 1
  store ptr %58, ptr %6, align 8, !tbaa !5
  br label %14, !llvm.loop !21

59:                                               ; preds = %14
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %98

61:                                               ; preds = %2
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i8 1, ptr %5, align 1, !tbaa !11
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.DBF, ptr %64, i32 0, i32 16
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  store ptr %66, ptr %6, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %92, %61
  %68 = load i8, ptr %5, align 1, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.DBF, ptr %70, i32 0, i32 15
  %72 = load i8, ptr %71, align 8, !tbaa !16
  %73 = zext i8 %72 to i32
  %74 = icmp sle i32 %69, %73
  br i1 %74, label %75, label %97

75:                                               ; preds = %67
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.FIELD_RECORD, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [11 x i8], ptr %77, i64 0, i64 0
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.FIELD_RECORD, ptr %79, i32 0, i32 1
  %81 = load i8, ptr %80, align 1, !tbaa !17
  %82 = zext i8 %81 to i32
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.FIELD_RECORD, ptr %83, i32 0, i32 3
  %85 = load i8, ptr %84, align 4, !tbaa !19
  %86 = zext i8 %85 to i32
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.FIELD_RECORD, ptr %87, i32 0, i32 4
  %89 = load i8, ptr %88, align 1, !tbaa !20
  %90 = zext i8 %89 to i32
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %78, i32 noundef %82, i32 noundef %86, i32 noundef %90)
  br label %92

92:                                               ; preds = %75
  %93 = load i8, ptr %5, align 1, !tbaa !11
  %94 = add i8 %93, 1
  store i8 %94, ptr %5, align 1, !tbaa !11
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.FIELD_RECORD, ptr %95, i32 1
  store ptr %96, ptr %6, align 8, !tbaa !5
  br label %67, !llvm.loop !23

97:                                               ; preds = %67
  br label %98

98:                                               ; preds = %97, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  ret void
}

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

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

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

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

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 = { "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 = { nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 2096}
!13 = !{!"DBF", !7, i64 0, !7, i64 1024, !6, i64 2048, !6, i64 2056, !10, i64 2064, !10, i64 2068, !7, i64 2072, !7, i64 2073, !7, i64 2074, !7, i64 2075, !7, i64 2076, !7, i64 2077, !7, i64 2078, !10, i64 2080, !10, i64 2084, !7, i64 2088, !6, i64 2096, !6, i64 2104, !14, i64 2112}
!14 = !{!"DBFPROLOG", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4, !15, i64 8, !15, i64 10, !15, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 28, !7, i64 29}
!15 = !{!"short", !7, i64 0}
!16 = !{!13, !7, i64 2088}
!17 = !{!18, !7, i64 11}
!18 = !{!"FIELD_RECORD", !7, i64 0, !7, i64 11, !10, i64 12, !7, i64 16, !7, i64 17, !7, i64 18}
!19 = !{!18, !7, i64 16}
!20 = !{!18, !7, i64 17}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @dbf_from(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 1
  br i1 %3, label %4, label %30

4:                                                ; preds = %2
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %6 = getelementptr inbounds i8, ptr %0, i64 2088
  %7 = load i8, ptr %6, align 8, !tbaa !5
  %.not2529 = icmp eq i8 %7, 0
  br i1 %.not2529, label %._crit_edge, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 2096
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %10 = phi i8 [ %28, %.lr.ph32 ], [ %7, %.lr.ph32.preheader ]
  %.031 = phi ptr [ %27, %.lr.ph32 ], [ %9, %.lr.ph32.preheader ]
  %.02130 = phi i8 [ %26, %.lr.ph32 ], [ 1, %.lr.ph32.preheader ]
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.031) #3
  %12 = trunc i64 %11 to i32
  %13 = sub nsw i32 11, %12
  %14 = getelementptr inbounds i8, ptr %.031, i64 11
  %15 = load i8, ptr %14, align 1, !tbaa !14
  %16 = zext i8 %15 to i32
  %17 = getelementptr inbounds i8, ptr %.031, i64 16
  %18 = load i8, ptr %17, align 4, !tbaa !16
  %19 = zext i8 %18 to i32
  %20 = getelementptr inbounds i8, ptr %.031, i64 17
  %21 = load i8, ptr %20, align 1, !tbaa !17
  %22 = zext i8 %21 to i32
  %23 = icmp eq i8 %.02130, %10
  %24 = select i1 %23, i32 32, i32 44
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %.031, i32 noundef %13, ptr noundef nonnull @.str.2, i32 noundef %16, i32 noundef %19, i32 noundef %22, i32 noundef %24)
  %26 = add i8 %.02130, 1
  %27 = getelementptr inbounds i8, ptr %.031, i64 32
  %28 = load i8, ptr %6, align 8, !tbaa !5
  %.not25 = icmp ugt i8 %26, %28
  br i1 %.not25, label %._crit_edge, label %.lr.ph32, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph32, %4
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.loopexit

30:                                               ; preds = %2
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %33 = getelementptr inbounds i8, ptr %0, i64 2088
  %34 = load i8, ptr %33, align 8, !tbaa !5
  %.not26 = icmp eq i8 %34, 0
  br i1 %.not26, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %30
  %35 = getelementptr inbounds i8, ptr %0, i64 2096
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.128 = phi ptr [ %48, %.lr.ph ], [ %36, %.lr.ph.preheader ]
  %.12227 = phi i8 [ %47, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %37 = getelementptr inbounds i8, ptr %.128, i64 11
  %38 = load i8, ptr %37, align 1, !tbaa !14
  %39 = zext i8 %38 to i32
  %40 = getelementptr inbounds i8, ptr %.128, i64 16
  %41 = load i8, ptr %40, align 4, !tbaa !16
  %42 = zext i8 %41 to i32
  %43 = getelementptr inbounds i8, ptr %.128, i64 17
  %44 = load i8, ptr %43, align 1, !tbaa !17
  %45 = zext i8 %44 to i32
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %.128, i32 noundef %39, i32 noundef %42, i32 noundef %45)
  %47 = add i8 %.12227, 1
  %48 = getelementptr inbounds i8, ptr %.128, i64 32
  %49 = load i8, ptr %33, align 8, !tbaa !5
  %.not = icmp ugt i8 %47, %49
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph, %30, %._crit_edge
  ret void
}

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

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

attributes #0 = { nofree 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 = { 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 #3 = { 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, !7, i64 2088}
!6 = !{!"DBF", !7, i64 0, !7, i64 1024, !9, i64 2048, !9, i64 2056, !10, i64 2064, !10, i64 2068, !7, i64 2072, !7, i64 2073, !7, i64 2074, !7, i64 2075, !7, i64 2076, !7, i64 2077, !7, i64 2078, !10, i64 2080, !10, i64 2084, !7, i64 2088, !9, i64 2096, !9, i64 2104, !11, i64 2112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"DBFPROLOG", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4, !12, i64 8, !12, i64 10, !12, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 28, !7, i64 29}
!12 = !{!"short", !7, i64 0}
!13 = !{!6, !9, i64 2096}
!14 = !{!15, !7, i64 11}
!15 = !{!"FIELD_RECORD", !7, i64 0, !7, i64 11, !10, i64 12, !7, i64 16, !7, i64 17, !7, i64 18}
!16 = !{!15, !7, i64 16}
!17 = !{!15, !7, i64 17}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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