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

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

%"class.rmg::Bitmap" = type { i16, i16, i8, ptr }

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

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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
define dso_local void @_ZN3rmg6Bitmap12loadFromFileEPKc(ptr dead_on_unwind noalias writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store ptr @.str, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i64 @strlen(ptr noundef %8) #7
  %10 = sub i64 %9, 1
  store i64 %10, ptr %6, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %28, %2
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = add i64 %12, -1
  store i64 %13, ptr %6, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %29

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 46
  br i1 %22, label %23, label %28

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = add i64 %25, 1
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  store ptr %27, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %23, %16
  br label %11, !llvm.loop !12

29:                                               ; preds = %15
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i32 @strcmp(ptr noundef %30, ptr noundef @.str.1) #7
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3rmg6Bitmap7loadPNGEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %34)
  store i32 1, ptr %7, align 4
  br label %48

35:                                               ; preds = %29
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @strcmp(ptr noundef %36, ptr noundef @.str.2) #7
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %43, label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @strcmp(ptr noundef %40, ptr noundef @.str.3) #7
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %39, %35
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3rmg6Bitmap8loadTIFFEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %44)
  store i32 1, ptr %7, align 4
  br label %48

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %46)
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 16, i1 false)
  call void @_ZN3rmg6BitmapC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #6
  store i32 1, ptr %7, align 4
  br label %48

48:                                               ; preds = %45, %43, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret void
}

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

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

declare void @_ZN3rmg6Bitmap7loadPNGEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8, ptr noundef) #4

declare void @_ZN3rmg6Bitmap8loadTIFFEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8, ptr noundef) #4

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg6BitmapC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%"class.rmg::Bitmap" = type { i16, i16, i8, ptr }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg6Bitmap12loadFromFileEPKc(ptr dead_on_unwind noalias writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %4 = add i64 %3, -2
  %.not13 = icmp eq i64 %4, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = add i64 %3, -1
  %6 = add i64 %3, -3
  %xtraiter = and i64 %4, 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
  %7 = phi i64 [ %12, %.lr.ph.prol ], [ %4, %.lr.ph.preheader ]
  %.015.prol = phi i64 [ %7, %.lr.ph.prol ], [ %5, %.lr.ph.preheader ]
  %.01114.prol = phi ptr [ %spec.select.prol, %.lr.ph.prol ], [ @.str, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %8 = getelementptr inbounds i8, ptr %1, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = icmp eq i8 %9, 46
  %11 = getelementptr inbounds i8, ptr %1, i64 %.015.prol
  %spec.select.prol = select i1 %10, ptr %11, ptr %.01114.prol
  %12 = add i64 %7, -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 [ %4, %.lr.ph.preheader ], [ %12, %.lr.ph.prol ]
  %.015.unr = phi i64 [ %5, %.lr.ph.preheader ], [ %7, %.lr.ph.prol ]
  %.01114.unr = phi ptr [ @.str, %.lr.ph.preheader ], [ %spec.select.prol, %.lr.ph.prol ]
  %13 = icmp ult i64 %6, 3
  br i1 %13, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %2
  %.011.lcssa = phi ptr [ @.str, %2 ], [ %spec.select.lcssa.unr, %.lr.ph.prol.loopexit ], [ %spec.select.3, %.lr.ph ]
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %.011.lcssa, ptr noundef nonnull dereferenceable(1) @.str.1) #6
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %37, label %38

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

37:                                               ; preds = %._crit_edge
  tail call void @_ZN3rmg6Bitmap7loadPNGEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %1)
  br label %47

38:                                               ; preds = %._crit_edge
  %39 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %.011.lcssa, ptr noundef nonnull dereferenceable(1) @.str.2) #6
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %.011.lcssa, ptr noundef nonnull dereferenceable(1) @.str.3) #6
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %41, %38
  tail call void @_ZN3rmg6Bitmap8loadTIFFEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8 %0, ptr noundef %1)
  br label %47

45:                                               ; preds = %41
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %1)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  tail call void @_ZN3rmg6BitmapC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #7
  br label %47

47:                                               ; preds = %45, %44, %37
  ret void
}

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

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

declare void @_ZN3rmg6Bitmap7loadPNGEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8, ptr noundef) local_unnamed_addr #3

declare void @_ZN3rmg6Bitmap8loadTIFFEPKc(ptr dead_on_unwind writable sret(%"class.rmg::Bitmap") align 8, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg6BitmapC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #5 align 2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #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 = { 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 #5 = { 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 #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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