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

; 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 [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @yml_writ(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  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
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.DBF, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.DBF, ptr %9, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str, i32 noundef %11) #4
  store i8 0, ptr %3, align 1, !tbaa !15
  br label %13

13:                                               ; preds = %114, %1
  %14 = load i8, ptr %3, align 1, !tbaa !15
  %15 = zext i8 %14 to i32
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DBF, ptr %16, i32 0, i32 15
  %18 = load i8, ptr %17, align 8, !tbaa !16
  %19 = zext i8 %18 to i32
  %20 = icmp slt i32 %15, %19
  br i1 %20, label %21, label %117

21:                                               ; preds = %13
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.DBF, ptr %22, i32 0, i32 16
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = load i8, ptr %3, align 1, !tbaa !15
  %26 = zext i8 %25 to i64
  %27 = getelementptr inbounds %struct.FIELD_RECORD, ptr %24, i64 %26
  store ptr %27, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.DBF, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.FIELD_RECORD, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [11 x i8], ptr %32, i64 0, i64 0
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.1, i32 noundef 11, ptr noundef %33) #4
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.DBF, ptr %35, i32 0, i32 17
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.FIELD_RECORD, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !19
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %37, i64 %41
  store ptr %42, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.FIELD_RECORD, ptr %43, i32 0, i32 1
  %45 = load i8, ptr %44, align 1, !tbaa !21
  %46 = zext i8 %45 to i32
  switch i32 %46, label %113 [
    i32 68, label %47
    i32 78, label %57
    i32 70, label %57
    i32 76, label %57
    i32 67, label %71
  ]

47:                                               ; preds = %21
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DBF, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 4
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 6
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.2, ptr noundef %51, ptr noundef %53, ptr noundef %55) #4
  br label %113

57:                                               ; preds = %21, %21, %21
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DBF, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !15
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %57
  br label %68

66:                                               ; preds = %57
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %66, %65
  %69 = phi ptr [ @.str.4, %65 ], [ %67, %66 ]
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.3, ptr noundef %69) #4
  br label %113

71:                                               ; preds = %21
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.DBF, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = call i32 @fputc(i32 noundef 39, ptr noundef %74)
  br label %76

76:                                               ; preds = %95, %71
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load i8, ptr %77, align 1, !tbaa !15
  %79 = icmp ne i8 %78, 0
  br i1 %79, label %80, label %104

80:                                               ; preds = %76
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i8, ptr %81, align 1, !tbaa !15
  %83 = sext i8 %82 to i32
  %84 = icmp eq i32 %83, 39
  br i1 %84, label %90, label %85

85:                                               ; preds = %80
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = load i8, ptr %86, align 1, !tbaa !15
  %88 = sext i8 %87 to i32
  %89 = icmp eq i32 %88, 92
  br i1 %89, label %90, label %95

90:                                               ; preds = %85, %80
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.DBF, ptr %91, i32 0, i32 3
  %93 = load ptr, ptr %92, align 8, !tbaa !9
  %94 = call i32 @fputc(i32 noundef 92, ptr noundef %93)
  br label %95

95:                                               ; preds = %90, %85
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i32 1
  store ptr %97, ptr %5, align 8, !tbaa !5
  %98 = load i8, ptr %96, align 1, !tbaa !15
  %99 = sext i8 %98 to i32
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.DBF, ptr %100, i32 0, i32 3
  %102 = load ptr, ptr %101, align 8, !tbaa !9
  %103 = call i32 @fputc(i32 noundef %99, ptr noundef %102)
  br label %76, !llvm.loop !22

104:                                              ; preds = %76
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.DBF, ptr %105, i32 0, i32 3
  %107 = load ptr, ptr %106, align 8, !tbaa !9
  %108 = call i32 @fputc(i32 noundef 39, ptr noundef %107)
  %109 = load ptr, ptr %2, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.DBF, ptr %109, i32 0, i32 3
  %111 = load ptr, ptr %110, align 8, !tbaa !9
  %112 = call i32 @fputc(i32 noundef 10, ptr noundef %111)
  br label %113

113:                                              ; preds = %104, %68, %47, %21
  br label %114

114:                                              ; preds = %113
  %115 = load i8, ptr %3, align 1, !tbaa !15
  %116 = add i8 %115, 1
  store i8 %116, ptr %3, align 1, !tbaa !15
  br label %13, !llvm.loop !24

117:                                              ; preds = %13
  %118 = load ptr, ptr %2, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.DBF, ptr %118, i32 0, i32 3
  %120 = load ptr, ptr %119, align 8, !tbaa !9
  %121 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %120, ptr noundef @.str.5) #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 0
}

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

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

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


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

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @yml_writ(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 2056
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 2064
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str, i32 noundef %5) #2
  %7 = getelementptr inbounds i8, ptr %0, i64 2088
  %8 = load i8, ptr %7, align 8, !tbaa !14
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 2096
  %10 = getelementptr inbounds i8, ptr %0, i64 2104
  br label %11

11:                                               ; preds = %.lr.ph, %49
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %49 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !15
  %13 = getelementptr inbounds %struct.FIELD_RECORD, ptr %12, i64 %indvars.iv
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.1, i32 noundef 11, ptr noundef %13) #2
  %16 = load ptr, ptr %10, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %13, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %16, i64 %19
  %21 = getelementptr inbounds i8, ptr %13, i64 11
  %22 = load i8, ptr %21, align 1, !tbaa !19
  switch i8 %22, label %49 [
    i8 68, label %23
    i8 78, label %28
    i8 70, label %28
    i8 76, label %28
    i8 67, label %.preheader
  ]

23:                                               ; preds = %11
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %20, i64 4
  %26 = getelementptr inbounds i8, ptr %20, i64 6
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.2, ptr noundef %20, ptr noundef nonnull %25, ptr noundef nonnull %26) #2
  br label %49

28:                                               ; preds = %11, %11, %11
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = load i8, ptr %20, align 1, !tbaa !20
  %31 = icmp eq i8 %30, 0
  %32 = select i1 %31, ptr @.str.4, ptr %20
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.3, ptr noundef nonnull %32) #2
  br label %49

.preheader:                                       ; preds = %11, %40
  %.sink = phi i32 [ %43, %40 ], [ 39, %11 ]
  %.0 = phi ptr [ %42, %40 ], [ %20, %11 ]
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = tail call i32 @fputc(i32 noundef %.sink, ptr noundef %34)
  %36 = load i8, ptr %.0, align 1, !tbaa !20
  switch i8 %36, label %40 [
    i8 0, label %44
    i8 39, label %37
    i8 92, label %37
  ]

37:                                               ; preds = %.preheader, %.preheader
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = tail call i32 @fputc(i32 noundef 92, ptr noundef %38)
  %.pre = load i8, ptr %.0, align 1, !tbaa !20
  br label %40

40:                                               ; preds = %.preheader, %37
  %41 = phi i8 [ %36, %.preheader ], [ %.pre, %37 ]
  %42 = getelementptr inbounds i8, ptr %.0, i64 1
  %43 = sext i8 %41 to i32
  br label %.preheader, !llvm.loop !21

44:                                               ; preds = %.preheader
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = tail call i32 @fputc(i32 noundef 39, ptr noundef %45)
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = tail call i32 @fputc(i32 noundef 10, ptr noundef %47)
  br label %49

49:                                               ; preds = %11, %23, %28, %44
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %50 = load i8, ptr %7, align 8, !tbaa !14
  %51 = zext i8 %50 to i64
  %52 = icmp ult i64 %indvars.iv.next, %51
  br i1 %52, label %11, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %49, %1
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef nonnull @.str.5) #2
  ret i32 0
}

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

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

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 = { 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, !9, i64 2056}
!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, !10, i64 2064}
!14 = !{!6, !7, i64 2088}
!15 = !{!6, !9, i64 2096}
!16 = !{!6, !9, i64 2104}
!17 = !{!18, !10, i64 12}
!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 11}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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