; LLVM IR from freakout42/macrocalc :: mc/nro (nrotxt)

; 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"

; Function Attrs: nounwind uwtable
define dso_local ptr @getfield(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = trunc i32 %2 to i8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %7, ptr %6, align 1, !tbaa !9
  br label %8

8:                                                ; preds = %32, %3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = load i8, ptr %6, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp ne i32 %11, %13
  br i1 %14, label %15, label %30

15:                                               ; preds = %8
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 13
  br i1 %19, label %20, label %30

20:                                               ; preds = %15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = icmp ne i32 %23, 10
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 0
  br label %30

30:                                               ; preds = %25, %20, %15, %8
  %31 = phi i1 [ false, %20 ], [ false, %15 ], [ false, %8 ], [ %29, %25 ]
  br i1 %31, label %32, label %38

32:                                               ; preds = %30
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %4, align 8, !tbaa !5
  %35 = load i8, ptr %33, align 1, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i32 1
  store ptr %37, ptr %5, align 8, !tbaa !5
  store i8 %35, ptr %36, align 1, !tbaa !9
  br label %8, !llvm.loop !10

38:                                               ; preds = %30
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %39, align 1, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = load i8, ptr %6, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %42, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %4, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %46, %38
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  ret ptr %50
}

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" }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @getfield(ptr noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %sext = shl i32 %2, 24
  %4 = ashr exact i32 %sext, 24
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %6 = sext i8 %5 to i32
  %.not18 = icmp eq i32 %4, %6
  %7 = freeze i1 %.not18
  br i1 %7, label %.critedge, label %switch.early.test

switch.early.test:                                ; preds = %3, %9
  %8 = phi i8 [ %12, %9 ], [ %5, %3 ]
  %.020 = phi ptr [ %10, %9 ], [ %0, %3 ]
  %.01119 = phi ptr [ %11, %9 ], [ %1, %3 ]
  switch i8 %8, label %9 [
    i8 13, label %.critedge
    i8 10, label %.critedge
    i8 0, label %.critedge
  ]

9:                                                ; preds = %switch.early.test
  %10 = getelementptr inbounds i8, ptr %.020, i64 1
  %11 = getelementptr inbounds i8, ptr %.01119, i64 1
  store i8 %8, ptr %.01119, align 1, !tbaa !5
  %12 = load i8, ptr %10, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %.not = icmp eq i32 %4, %13
  %14 = freeze i1 %.not
  br i1 %14, label %.critedge, label %switch.early.test, !llvm.loop !8

.critedge:                                        ; preds = %9, %switch.early.test, %switch.early.test, %switch.early.test, %3
  %.011.lcssa = phi ptr [ %1, %3 ], [ %.01119, %switch.early.test ], [ %.01119, %switch.early.test ], [ %.01119, %switch.early.test ], [ %11, %9 ]
  %.0.lcssa = phi ptr [ %0, %3 ], [ %.020, %switch.early.test ], [ %.020, %switch.early.test ], [ %.020, %switch.early.test ], [ %10, %9 ]
  store i8 0, ptr %.011.lcssa, align 1, !tbaa !5
  %15 = load i8, ptr %.0.lcssa, align 1, !tbaa !5
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %4, %16
  %spec.select.idx = zext i1 %17 to i64
  %spec.select = getelementptr inbounds i8, ptr %.0.lcssa, i64 %spec.select.idx
  ret ptr %spec.select
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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