; LLVM IR from achilles288/robot-monitor-graphics :: src/base/object3d.ll (ZN3rmg8Object3DC2EPNS_7ContextEPKcb)

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

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [78 x i8], align 1

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3rmg8Object3DC2EPNS_7ContextE(ptr noundef nonnull align 8 dereferenceable(216), ptr noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg8Object3DC2EPNS_7ContextEPKcb(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %1, ptr noundef %2, i1 noundef zeroext %3) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = zext i1 %3 to i8
  store i8 %13, ptr %8, align 1, !tbaa !9
  %14 = load ptr, ptr %5, align 8
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN3rmg8Object3DC2EPNS_7ContextE(ptr noundef nonnull align 8 dereferenceable(216) %14, ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr @.str, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #6
  %18 = sub i64 %17, 1
  store i64 %18, ptr %10, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %36, %4
  %20 = load i64, ptr %10, align 8, !tbaa !11
  %21 = add i64 %20, -1
  store i64 %21, ptr %10, align 8, !tbaa !11
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %37

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr %10, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %29, 46
  br i1 %30, label %31, label %36

31:                                               ; preds = %24
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %34 = add i64 %33, 1
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  store ptr %35, ptr %9, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %31, %24
  br label %19, !llvm.loop !14

37:                                               ; preds = %23
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = call i32 @strcmp(ptr noundef %38, ptr noundef @.str.1) #6
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %50

41:                                               ; preds = %37
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i8, ptr %8, align 1, !tbaa !9, !range !16, !noundef !17
  %44 = trunc i8 %43 to i1
  invoke void @_ZN3rmg8Object3D7loadOBJEPKcb(ptr noundef nonnull align 8 dereferenceable(216) %14, ptr noundef %42, i1 noundef zeroext %44)
          to label %45 unwind label %46

45:                                               ; preds = %41
  br label %54

46:                                               ; preds = %50, %41
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %11, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @_ZN3rmg8Object3DD2Ev(ptr noundef nonnull align 8 dereferenceable(216) %14) #5
  br label %55

50:                                               ; preds = %37
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %51)
          to label %53 unwind label %46

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void

55:                                               ; preds = %46
  %56 = load ptr, ptr %11, align 8
  %57 = load i32, ptr %12, align 4
  %58 = insertvalue { ptr, i32 } poison, ptr %56, 0
  %59 = insertvalue { ptr, i32 } %58, i32 %57, 1
  resume { ptr, i32 } %59
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

declare void @_ZN3rmg8Object3D7loadOBJEPKcb(ptr noundef nonnull align 8 dereferenceable(216), ptr noundef, i1 noundef zeroext) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg8Object3DD2Ev(ptr noundef nonnull align 8 dereferenceable(216)) unnamed_addr #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #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 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3rmg8Object3DC2EPNS_7ContextE(ptr noundef nonnull align 8 dereferenceable(216), ptr noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg8Object3DC2EPNS_7ContextEPKcb(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %1, ptr noundef %2, i1 noundef zeroext %3) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN3rmg8Object3DC2EPNS_7ContextE(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %1)
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #5
  %6 = add i64 %5, -2
  %.not15 = icmp eq i64 %6, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %7 = add i64 %5, -1
  %8 = add i64 %5, -3
  %xtraiter = and i64 %6, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %9 = phi i64 [ %14, %.lr.ph.prol ], [ %6, %.lr.ph.preheader ]
  %.017.prol = phi ptr [ %spec.select.prol, %.lr.ph.prol ], [ @.str, %.lr.ph.preheader ]
  %.01316.prol = phi i64 [ %9, %.lr.ph.prol ], [ %7, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %10 = getelementptr inbounds i8, ptr %2, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 46
  %13 = getelementptr inbounds i8, ptr %2, i64 %.01316.prol
  %spec.select.prol = select i1 %12, ptr %13, ptr %.017.prol
  %14 = add i64 %9, -1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !8

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %spec.select.lcssa.unr = phi ptr [ poison, %.lr.ph.preheader ], [ %spec.select.prol, %.lr.ph.prol ]
  %.unr = phi i64 [ %6, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.017.unr = phi ptr [ @.str, %.lr.ph.preheader ], [ %spec.select.prol, %.lr.ph.prol ]
  %.01316.unr = phi i64 [ %7, %.lr.ph.preheader ], [ %9, %.lr.ph.prol ]
  %15 = icmp ult i64 %8, 3
  br i1 %15, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %4
  %.0.lcssa = phi ptr [ @.str, %4 ], [ %spec.select.lcssa.unr, %.lr.ph.prol.loopexit ], [ %spec.select.3, %.lr.ph ]
  %16 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %.0.lcssa, ptr noundef nonnull dereferenceable(1) @.str.1) #5
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %39, label %42

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %18 = phi i64 [ %38, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %.017 = phi ptr [ %spec.select.3, %.lr.ph ], [ %.017.unr, %.lr.ph.prol.loopexit ]
  %.01316 = phi i64 [ %33, %.lr.ph ], [ %.01316.unr, %.lr.ph.prol.loopexit ]
  %19 = getelementptr inbounds i8, ptr %2, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = icmp eq i8 %20, 46
  %22 = getelementptr inbounds i8, ptr %2, i64 %.01316
  %spec.select = select i1 %21, ptr %22, ptr %.017
  %23 = add i64 %18, -1
  %24 = getelementptr inbounds i8, ptr %2, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = icmp eq i8 %25, 46
  %27 = getelementptr inbounds i8, ptr %2, i64 %18
  %spec.select.1 = select i1 %26, ptr %27, ptr %spec.select
  %28 = add i64 %18, -2
  %29 = getelementptr inbounds i8, ptr %2, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = icmp eq i8 %30, 46
  %32 = getelementptr inbounds i8, ptr %2, i64 %23
  %spec.select.2 = select i1 %31, ptr %32, ptr %spec.select.1
  %33 = add i64 %18, -3
  %34 = getelementptr inbounds i8, ptr %2, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = icmp eq i8 %35, 46
  %37 = getelementptr inbounds i8, ptr %2, i64 %28
  %spec.select.3 = select i1 %36, ptr %37, ptr %spec.select.2
  %38 = add i64 %18, -4
  %.not.3 = icmp eq i64 %38, 0
  br i1 %.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !10

39:                                               ; preds = %._crit_edge
  invoke void @_ZN3rmg8Object3D7loadOBJEPKcb(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %2, i1 noundef zeroext %3)
          to label %44 unwind label %40

40:                                               ; preds = %39
  %41 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN3rmg8Object3DD2Ev(ptr noundef nonnull align 8 dereferenceable(216) %0) #6
  resume { ptr, i32 } %41

42:                                               ; preds = %._crit_edge
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %2)
  br label %44

44:                                               ; preds = %39, %42
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @_ZN3rmg8Object3D7loadOBJEPKcb(ptr noundef nonnull align 8 dereferenceable(216), ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg8Object3DD2Ev(ptr noundef nonnull align 8 dereferenceable(216)) unnamed_addr #4 align 2

attributes #0 = { mustprogress 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 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 #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 = { 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 #4 = { mustprogress 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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.unroll.disable"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass