; LLVM IR from freakout42/macrocalc :: arx/src (rdb_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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @rdb_writ(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
  %7 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %38

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

17:                                               ; preds = %10
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DBF, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = call i32 @putc(i32 noundef 45, ptr noundef %20)
  br label %22

22:                                               ; preds = %17, %10
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DBF, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DBF, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 8, !tbaa !17
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, i32 noundef %28) #4
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.DBF, ptr %30, i32 0, i32 6
  %32 = load i8, ptr %31, align 8, !tbaa !18
  %33 = sext i8 %32 to i32
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.DBF, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = call i32 @putc(i32 noundef %33, ptr noundef %36)
  br label %38

38:                                               ; preds = %22, %2
  store i8 0, ptr %5, align 1, !tbaa !15
  br label %39

39:                                               ; preds = %87, %38
  %40 = load i8, ptr %5, align 1, !tbaa !15
  %41 = zext i8 %40 to i32
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.DBF, ptr %42, i32 0, i32 15
  %44 = load i8, ptr %43, align 8, !tbaa !19
  %45 = zext i8 %44 to i32
  %46 = icmp slt i32 %41, %45
  br i1 %46, label %47, label %90

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DBF, ptr %48, i32 0, i32 16
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load i8, ptr %5, align 1, !tbaa !15
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds %struct.FIELD_RECORD, ptr %50, i64 %52
  store ptr %53, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.DBF, ptr %54, i32 0, i32 17
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.FIELD_RECORD, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !21
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %56, i64 %60
  store ptr %61, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.DBF, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str.1, ptr noundef %65) #4
  %67 = load i8, ptr %5, align 1, !tbaa !15
  %68 = zext i8 %67 to i32
  %69 = add nsw i32 %68, 1
  %70 = trunc i32 %69 to i8
  %71 = zext i8 %70 to i32
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.DBF, ptr %72, i32 0, i32 15
  %74 = load i8, ptr %73, align 8, !tbaa !19
  %75 = zext i8 %74 to i32
  %76 = icmp slt i32 %71, %75
  br i1 %76, label %77, label %86

77:                                               ; preds = %47
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.DBF, ptr %78, i32 0, i32 6
  %80 = load i8, ptr %79, align 8, !tbaa !18
  %81 = sext i8 %80 to i32
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.DBF, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  %85 = call i32 @putc(i32 noundef %81, ptr noundef %84)
  br label %86

86:                                               ; preds = %77, %47
  br label %87

87:                                               ; preds = %86
  %88 = load i8, ptr %5, align 1, !tbaa !15
  %89 = add i8 %88, 1
  store i8 %89, ptr %5, align 1, !tbaa !15
  br label %39, !llvm.loop !23

90:                                               ; preds = %39
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.DBF, ptr %91, i32 0, i32 3
  %93 = load ptr, ptr %92, align 8, !tbaa !16
  %94 = call i32 @putc(i32 noundef 10, ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #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

declare i32 @putc(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(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 = { "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 "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 = !{!12, !6, i64 2104}
!12 = !{!"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, !13, i64 2112}
!13 = !{!"DBFPROLOG", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4, !14, i64 8, !14, i64 10, !14, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 28, !7, i64 29}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !6, i64 2056}
!17 = !{!12, !10, i64 2064}
!18 = !{!12, !7, i64 2072}
!19 = !{!12, !7, i64 2088}
!20 = !{!12, !6, i64 2096}
!21 = !{!22, !10, i64 12}
!22 = !{!"FIELD_RECORD", !7, i64 0, !7, i64 11, !10, i64 12, !7, i64 16, !7, i64 17, !7, i64 18}
!23 = distinct !{!23, !24}
!24 = !{!"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] }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 2104
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !13
  %8 = icmp eq i8 %7, 42
  br i1 %8, label %9, label %13

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 2056
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = tail call i32 @putc(i32 noundef 45, ptr noundef %11)
  br label %13

13:                                               ; preds = %9, %4
  %14 = getelementptr inbounds i8, ptr %0, i64 2056
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 2064
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, i32 noundef %17) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 2072
  %20 = load i8, ptr %19, align 8, !tbaa !16
  %21 = sext i8 %20 to i32
  %22 = load ptr, ptr %14, align 8, !tbaa !14
  %23 = tail call i32 @putc(i32 noundef %21, ptr noundef %22)
  br label %24

24:                                               ; preds = %13, %2
  %25 = getelementptr inbounds i8, ptr %0, i64 2088
  %26 = load i8, ptr %25, align 8, !tbaa !17
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 2096
  %28 = getelementptr inbounds i8, ptr %0, i64 2104
  %29 = getelementptr inbounds i8, ptr %0, i64 2056
  %30 = getelementptr inbounds i8, ptr %0, i64 2072
  br label %31

31:                                               ; preds = %.lr.ph, %48
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %48 ]
  %32 = load ptr, ptr %27, align 8, !tbaa !18
  %33 = load ptr, ptr %28, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.FIELD_RECORD, ptr %32, i64 %indvars.iv, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !19
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  %38 = load ptr, ptr %29, align 8, !tbaa !14
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.1, ptr noundef %37) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i8, ptr %25, align 8, !tbaa !17
  %41 = zext i8 %40 to i64
  %42 = icmp ult i64 %indvars.iv.next, %41
  br i1 %42, label %43, label %48

43:                                               ; preds = %31
  %44 = load i8, ptr %30, align 8, !tbaa !16
  %45 = sext i8 %44 to i32
  %46 = load ptr, ptr %29, align 8, !tbaa !14
  %47 = tail call i32 @putc(i32 noundef %45, ptr noundef %46)
  %.pre = load i8, ptr %25, align 8, !tbaa !17
  %.pre23 = zext i8 %.pre to i64
  br label %48

48:                                               ; preds = %31, %43
  %.pre-phi = phi i64 [ %41, %31 ], [ %.pre23, %43 ]
  %49 = icmp ult i64 %indvars.iv.next, %.pre-phi
  br i1 %49, label %31, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %48, %24
  %50 = getelementptr inbounds i8, ptr %0, i64 2056
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = tail call i32 @putc(i32 noundef 10, ptr noundef %51)
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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 2104}
!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 = !{!7, !7, i64 0}
!14 = !{!6, !9, i64 2056}
!15 = !{!6, !10, i64 2064}
!16 = !{!6, !7, i64 2072}
!17 = !{!6, !7, i64 2088}
!18 = !{!6, !9, i64 2096}
!19 = !{!20, !10, i64 12}
!20 = !{!"FIELD_RECORD", !7, i64 0, !7, i64 11, !10, i64 12, !7, i64 16, !7, i64 17, !7, i64 18}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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