; LLVM IR from mkazhdan/DMG :: Util/TIFF (tif_dir)

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

@TIFFReassignTagToIgnore.TIFFignoretags = external hidden global [127 x i32], align 16
@TIFFReassignTagToIgnore.tagcount = external hidden global i32, align 4

; 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: nounwind uwtable
define dso_local i32 @TIFFReassignTagToIgnore(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %9, label %56 [
    i32 0, label %10
    i32 1, label %37
    i32 2, label %55
  ]

10:                                               ; preds = %2
  %11 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 126
  br i1 %12, label %13, label %36

13:                                               ; preds = %10
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %27, %13
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %30

18:                                               ; preds = %14
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %58

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !9

30:                                               ; preds = %14
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %34
  store i32 %31, ptr %35, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %58

36:                                               ; preds = %10
  br label %57

37:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %51, %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %54

42:                                               ; preds = %38
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %58

50:                                               ; preds = %42
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !11

54:                                               ; preds = %38
  br label %57

55:                                               ; preds = %2
  store i32 0, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %58

56:                                               ; preds = %2
  br label %57

57:                                               ; preds = %56, %54, %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %58

58:                                               ; preds = %57, %55, %49, %30, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@TIFFReassignTagToIgnore.TIFFignoretags = external hidden local_unnamed_addr global [127 x i32], align 16
@TIFFReassignTagToIgnore.tagcount = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @TIFFReassignTagToIgnore(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  switch i32 %0, label %.loopexit [
    i32 0, label %5
    i32 1, label %.preheader14
    i32 2, label %20
  ]

.preheader14:                                     ; preds = %2
  %3 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader14
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

5:                                                ; preds = %2
  %6 = load i32, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 126
  br i1 %7, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %5
  %8 = icmp sgt i32 %6, 0
  br i1 %8, label %.lr.ph20.preheader, label %._crit_edge

.lr.ph20.preheader:                               ; preds = %.preheader
  %wide.trip.count26 = zext nneg i32 %6 to i64
  br label %.lr.ph20

9:                                                ; preds = %.lr.ph20
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count26
  br i1 %exitcond27.not, label %._crit_edge, label %.lr.ph20, !llvm.loop !9

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %9
  %indvars.iv23 = phi i64 [ 0, %.lr.ph20.preheader ], [ %indvars.iv.next24, %9 ]
  %10 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %indvars.iv23
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, %1
  br i1 %12, label %.loopexit, label %9

._crit_edge:                                      ; preds = %9, %.preheader
  %13 = add nsw i32 %6, 1
  store i32 %13, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  %14 = sext i32 %6 to i64
  %15 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %14
  store i32 %1, ptr %15, align 4, !tbaa !5
  br label %.loopexit

16:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %16 ]
  %17 = getelementptr inbounds [127 x i32], ptr @TIFFReassignTagToIgnore.TIFFignoretags, i64 0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, %1
  br i1 %19, label %.loopexit, label %16

20:                                               ; preds = %2
  store i32 0, ptr @TIFFReassignTagToIgnore.tagcount, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %16, %.lr.ph20, %.preheader14, %5, %2, %20, %._crit_edge
  %.012 = phi i32 [ 1, %20 ], [ 1, %._crit_edge ], [ 0, %2 ], [ 0, %5 ], [ 0, %.preheader14 ], [ 1, %.lr.ph20 ], [ 1, %.lr.ph ], [ 0, %16 ]
  ret i32 %.012
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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