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

; 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] }

@__const.dbf_afix.noiso8859 = external hidden unnamed_addr constant [75 x i8], align 16
@__const.dbf_afix.codepg850 = external hidden unnamed_addr constant [75 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @dbf_afix(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca [75 x i8], align 16
  %9 = alloca [75 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 75, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %8, ptr align 16 @__const.dbf_afix.noiso8859, i64 75, i1 false)
  call void @llvm.lifetime.start.p0(i64 75, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 16 @__const.dbf_afix.codepg850, i64 75, i1 false)
  store i32 0, ptr %7, align 4, !tbaa !9
  store i8 0, ptr %3, align 1, !tbaa !11
  br label %10

10:                                               ; preds = %72, %1
  %11 = load i8, ptr %3, align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DBF, ptr %13, i32 0, i32 15
  %15 = load i8, ptr %14, align 8, !tbaa !12
  %16 = zext i8 %15 to i32
  %17 = icmp slt i32 %12, %16
  br i1 %17, label %18, label %75

18:                                               ; preds = %10
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DBF, ptr %19, i32 0, i32 16
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = load i8, ptr %3, align 1, !tbaa !11
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds %struct.FIELD_RECORD, ptr %21, i64 %23
  store ptr %24, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.FIELD_RECORD, ptr %25, i32 0, i32 5
  %27 = getelementptr inbounds [14 x i8], ptr %26, i64 0, i64 0
  store i8 117, ptr %27, align 2, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.FIELD_RECORD, ptr %28, i32 0, i32 1
  %30 = load i8, ptr %29, align 1, !tbaa !17
  %31 = zext i8 %30 to i32
  switch i32 %31, label %71 [
    i32 67, label %32
  ]

32:                                               ; preds = %18
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.DBF, ptr %33, i32 0, i32 17
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.FIELD_RECORD, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !20
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %35, i64 %39
  store ptr %40, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.FIELD_RECORD, ptr %42, i32 0, i32 3
  %44 = load i8, ptr %43, align 4, !tbaa !21
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds i8, ptr %41, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  store i8 %47, ptr %6, align 1, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.FIELD_RECORD, ptr %49, i32 0, i32 3
  %51 = load i8, ptr %50, align 4, !tbaa !21
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds i8, ptr %48, i64 %52
  store i8 0, ptr %53, align 1, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds [75 x i8], ptr %8, i64 0, i64 0
  %56 = getelementptr inbounds [75 x i8], ptr %9, i64 0, i64 0
  %57 = call ptr @str_repl(ptr noundef %54, ptr noundef %55, ptr noundef %56)
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %63

59:                                               ; preds = %32
  store i32 1, ptr %7, align 4, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.FIELD_RECORD, ptr %60, i32 0, i32 5
  %62 = getelementptr inbounds [14 x i8], ptr %61, i64 0, i64 0
  store i8 109, ptr %62, align 2, !tbaa !11
  br label %63

63:                                               ; preds = %59, %32
  %64 = load i8, ptr %6, align 1, !tbaa !11
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.FIELD_RECORD, ptr %66, i32 0, i32 3
  %68 = load i8, ptr %67, align 4, !tbaa !21
  %69 = zext i8 %68 to i64
  %70 = getelementptr inbounds i8, ptr %65, i64 %69
  store i8 %64, ptr %70, align 1, !tbaa !11
  br label %71

71:                                               ; preds = %63, %18
  br label %72

72:                                               ; preds = %71
  %73 = load i8, ptr %3, align 1, !tbaa !11
  %74 = add i8 %73, 1
  store i8 %74, ptr %3, align 1, !tbaa !11
  br label %10, !llvm.loop !22

75:                                               ; preds = %10
  %76 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 75, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 75, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret i32 %76
}

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

; 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) #2

declare ptr @str_repl(ptr noundef, ptr noundef, 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind }

!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, !7, i64 2088}
!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, !6, i64 2096}
!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 = !{!13, !6, i64 2104}
!20 = !{!18, !10, i64 12}
!21 = !{!18, !7, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"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.FIELD_RECORD = type { [11 x i8], i8, i32, i8, i8, [14 x i8] }

@__const.dbf_afix.noiso8859 = external hidden unnamed_addr constant [75 x i8], align 16
@__const.dbf_afix.codepg850 = external hidden unnamed_addr constant [75 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @dbf_afix(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [75 x i8], align 16
  %3 = alloca [75 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 75, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(75) %2, ptr noundef nonnull align 16 dereferenceable(75) @__const.dbf_afix.noiso8859, i64 75, i1 false)
  call void @llvm.lifetime.start.p0(i64 75, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(75) %3, ptr noundef nonnull align 16 dereferenceable(75) @__const.dbf_afix.codepg850, i64 75, i1 false)
  %4 = getelementptr inbounds i8, ptr %0, i64 2088
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %.not21 = icmp eq i8 %5, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 2096
  %7 = getelementptr inbounds i8, ptr %0, i64 2104
  br label %8

8:                                                ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %.020 = phi i32 [ 0, %.lr.ph ], [ %.2, %31 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !13
  %10 = getelementptr inbounds %struct.FIELD_RECORD, ptr %9, i64 %indvars.iv
  %11 = getelementptr inbounds i8, ptr %10, i64 18
  store i8 117, ptr %11, align 2, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %10, i64 11
  %13 = load i8, ptr %12, align 1, !tbaa !15
  %cond = icmp eq i8 %13, 67
  br i1 %cond, label %14, label %31

14:                                               ; preds = %8
  %15 = load ptr, ptr %7, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %10, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %15, i64 %18
  %20 = getelementptr inbounds i8, ptr %10, i64 16
  %21 = load i8, ptr %20, align 4, !tbaa !19
  %22 = zext i8 %21 to i64
  %23 = getelementptr inbounds i8, ptr %19, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !14
  store i8 0, ptr %23, align 1, !tbaa !14
  %25 = call ptr @str_repl(ptr noundef %19, ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %27, label %26

26:                                               ; preds = %14
  store i8 109, ptr %11, align 2, !tbaa !14
  br label %27

27:                                               ; preds = %26, %14
  %.1 = phi i32 [ 1, %26 ], [ %.020, %14 ]
  %28 = load i8, ptr %20, align 4, !tbaa !19
  %29 = zext i8 %28 to i64
  %30 = getelementptr inbounds i8, ptr %19, i64 %29
  store i8 %24, ptr %30, align 1, !tbaa !14
  br label %31

31:                                               ; preds = %27, %8
  %.2 = phi i32 [ %.1, %27 ], [ %.020, %8 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i8, ptr %4, align 8, !tbaa !5
  %33 = zext i8 %32 to i64
  %34 = icmp ult i64 %indvars.iv.next, %33
  br i1 %34, label %8, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %31, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %.2, %31 ]
  call void @llvm.lifetime.end.p0(i64 75, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 75, ptr nonnull %2) #4
  ret i32 %.0.lcssa
}

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

; 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) #2

declare ptr @str_repl(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind }

!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 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 11}
!16 = !{!"FIELD_RECORD", !7, i64 0, !7, i64 11, !10, i64 12, !7, i64 16, !7, i64 17, !7, i64 18}
!17 = !{!6, !9, i64 2104}
!18 = !{!16, !10, i64 12}
!19 = !{!16, !7, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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