; LLVM IR from mkazhdan/DMG :: Util/TIFF/tif_dirinfo.ll (TIFFPrintFieldInfo)

; 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.tiff = type { ptr, i32, i32, i32, i32, i32, ptr, i16, %struct.TIFFDirectory, %struct.TIFFHeader, ptr, ptr, i32, i16, i32, i32, i32, i16, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, ptr, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, %struct.TIFFTagMethods, ptr }
%struct.TIFFDirectory = type { [4 x i64], i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i16, i16, i32, i16, i16, double, double, float, float, i16, i16, float, float, [2 x i16], [3 x ptr], [2 x i16], i16, ptr, i32, i32, ptr, ptr, i32, i16, ptr, [2 x i16], i16, [3 x ptr], i32, ptr, i32, ptr }
%struct.TIFFHeader = type { i16, i16, i32 }
%struct.TIFFTagMethods = type { ptr, ptr, ptr }
%struct.TIFFFieldInfo = type { i32, i16, i16, i32, i16, i8, i8, ptr }

@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @_TIFFPrintFieldInfo(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.tiff, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef @.str.3, ptr noundef %10) #3
  store i64 0, ptr %5, align 8, !tbaa !19
  br label %12

12:                                               ; preds = %65, %2
  %13 = load i64, ptr %5, align 8, !tbaa !19
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.tiff, ptr %14, i32 0, i32 59
  %16 = load i64, ptr %15, align 8, !tbaa !20
  %17 = icmp ult i64 %13, %16
  br i1 %17, label %18, label %68

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tiff, ptr %19, i32 0, i32 58
  %21 = load ptr, ptr %20, align 8, !tbaa !21
  %22 = load i64, ptr %5, align 8, !tbaa !19
  %23 = getelementptr inbounds ptr, ptr %21, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %5, align 8, !tbaa !19
  %27 = trunc i64 %26 to i32
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !22
  %31 = zext i32 %30 to i64
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %32, i32 0, i32 1
  %34 = load i16, ptr %33, align 4, !tbaa !24
  %35 = sext i16 %34 to i32
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %36, i32 0, i32 2
  %38 = load i16, ptr %37, align 2, !tbaa !25
  %39 = sext i16 %38 to i32
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %40, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !26
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %43, i32 0, i32 4
  %45 = load i16, ptr %44, align 4, !tbaa !27
  %46 = zext i16 %45 to i32
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %47, i32 0, i32 5
  %49 = load i8, ptr %48, align 2, !tbaa !28
  %50 = zext i8 %49 to i32
  %51 = icmp ne i32 %50, 0
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, ptr @.str.5, ptr @.str.6
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %54, i32 0, i32 6
  %56 = load i8, ptr %55, align 1, !tbaa !29
  %57 = zext i8 %56 to i32
  %58 = icmp ne i32 %57, 0
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, ptr @.str.5, ptr @.str.6
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TIFFFieldInfo, ptr %61, i32 0, i32 7
  %63 = load ptr, ptr %62, align 8, !tbaa !30
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.4, i32 noundef %27, i64 noundef %31, i32 noundef %35, i32 noundef %39, i32 noundef %42, i32 noundef %46, ptr noundef %53, ptr noundef %60, ptr noundef %63) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %65

65:                                               ; preds = %18
  %66 = load i64, ptr %5, align 8, !tbaa !19
  %67 = add i64 %66, 1
  store i64 %67, ptr %5, align 8, !tbaa !19
  br label %12, !llvm.loop !31

68:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

!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, !6, i64 0}
!10 = !{!"tiff", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !12, i64 40, !13, i64 48, !16, i64 320, !6, i64 328, !6, i64 336, !11, i64 344, !12, i64 348, !11, i64 352, !11, i64 356, !11, i64 360, !12, i64 364, !11, i64 368, !11, i64 372, !11, i64 376, !11, i64 380, !11, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !11, i64 416, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !11, i64 536, !11, i64 540, !6, i64 544, !11, i64 552, !6, i64 560, !11, i64 568, !6, i64 576, !11, i64 584, !6, i64 592, !6, i64 600, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !6, i64 640, !6, i64 648, !6, i64 656, !6, i64 664, !17, i64 672, !6, i64 680, !18, i64 688, !6, i64 712}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !7, i64 0, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !12, i64 60, !12, i64 62, !12, i64 64, !12, i64 66, !12, i64 68, !12, i64 70, !12, i64 72, !12, i64 74, !11, i64 76, !12, i64 80, !12, i64 82, !14, i64 88, !14, i64 96, !15, i64 104, !15, i64 108, !12, i64 112, !12, i64 114, !15, i64 116, !15, i64 120, !7, i64 124, !7, i64 128, !7, i64 152, !12, i64 156, !6, i64 160, !11, i64 168, !11, i64 172, !6, i64 176, !6, i64 184, !11, i64 192, !12, i64 196, !6, i64 200, !7, i64 208, !12, i64 212, !7, i64 216, !11, i64 240, !6, i64 248, !11, i64 256, !6, i64 264}
!14 = !{!"double", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 2, !11, i64 4}
!17 = !{!"long", !7, i64 0}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!17, !17, i64 0}
!20 = !{!10, !17, i64 672}
!21 = !{!10, !6, i64 664}
!22 = !{!23, !11, i64 0}
!23 = !{!"", !11, i64 0, !12, i64 4, !12, i64 6, !11, i64 8, !12, i64 12, !7, i64 14, !7, i64 15, !6, i64 16}
!24 = !{!23, !12, i64 4}
!25 = !{!23, !12, i64 6}
!26 = !{!23, !11, i64 8}
!27 = !{!23, !12, i64 12}
!28 = !{!23, !7, i64 14}
!29 = !{!23, !7, i64 15}
!30 = !{!23, !6, i64 16}
!31 = distinct !{!31, !32}
!32 = !{!"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"

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @_TIFFPrintFieldInfo(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %3) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 672
  %6 = load i64, ptr %5, align 8, !tbaa !18
  %.not18 = icmp eq i64 %6, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 664
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %.017 = phi i64 [ 0, %.lr.ph ], [ %35, %8 ]
  %9 = load ptr, ptr %7, align 8, !tbaa !19
  %10 = getelementptr inbounds ptr, ptr %9, i64 %.017
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %12 = trunc i64 %.017 to i32
  %13 = load i32, ptr %11, align 8, !tbaa !21
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %11, i64 4
  %16 = load i16, ptr %15, align 4, !tbaa !23
  %17 = sext i16 %16 to i32
  %18 = getelementptr inbounds i8, ptr %11, i64 6
  %19 = load i16, ptr %18, align 2, !tbaa !24
  %20 = sext i16 %19 to i32
  %21 = getelementptr inbounds i8, ptr %11, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !25
  %23 = getelementptr inbounds i8, ptr %11, i64 12
  %24 = load i16, ptr %23, align 4, !tbaa !26
  %25 = zext i16 %24 to i32
  %26 = getelementptr inbounds i8, ptr %11, i64 14
  %27 = load i8, ptr %26, align 2, !tbaa !27
  %.not = icmp eq i8 %27, 0
  %28 = select i1 %.not, ptr @.str.6, ptr @.str.5
  %29 = getelementptr inbounds i8, ptr %11, i64 15
  %30 = load i8, ptr %29, align 1, !tbaa !28
  %.not16 = icmp eq i8 %30, 0
  %31 = select i1 %.not16, ptr @.str.6, ptr @.str.5
  %32 = getelementptr inbounds i8, ptr %11, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !29
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.4, i32 noundef %12, i64 noundef %14, i32 noundef %17, i32 noundef %20, i32 noundef %22, i32 noundef %25, ptr noundef nonnull %28, ptr noundef nonnull %31, ptr noundef %33) #2
  %35 = add nuw i64 %.017, 1
  %36 = load i64, ptr %5, align 8, !tbaa !18
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %8, label %._crit_edge, !llvm.loop !30

._crit_edge:                                      ; preds = %8, %2
  ret void
}

; 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, !7, i64 0}
!6 = !{!"tiff", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !11, i64 40, !12, i64 48, !15, i64 320, !7, i64 328, !7, i64 336, !10, i64 344, !11, i64 348, !10, i64 352, !10, i64 356, !10, i64 360, !11, i64 364, !10, i64 368, !10, i64 372, !10, i64 376, !10, i64 380, !10, i64 384, !7, i64 392, !7, i64 400, !7, i64 408, !10, i64 416, !7, i64 424, !7, i64 432, !7, i64 440, !7, i64 448, !7, i64 456, !7, i64 464, !7, i64 472, !7, i64 480, !7, i64 488, !7, i64 496, !7, i64 504, !7, i64 512, !7, i64 520, !7, i64 528, !10, i64 536, !10, i64 540, !7, i64 544, !10, i64 552, !7, i64 560, !10, i64 568, !7, i64 576, !10, i64 584, !7, i64 592, !7, i64 600, !7, i64 608, !7, i64 616, !7, i64 624, !7, i64 632, !7, i64 640, !7, i64 648, !7, i64 656, !7, i64 664, !16, i64 672, !7, i64 680, !17, i64 688, !7, i64 712}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"", !8, i64 0, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !11, i64 60, !11, i64 62, !11, i64 64, !11, i64 66, !11, i64 68, !11, i64 70, !11, i64 72, !11, i64 74, !10, i64 76, !11, i64 80, !11, i64 82, !13, i64 88, !13, i64 96, !14, i64 104, !14, i64 108, !11, i64 112, !11, i64 114, !14, i64 116, !14, i64 120, !8, i64 124, !8, i64 128, !8, i64 152, !11, i64 156, !7, i64 160, !10, i64 168, !10, i64 172, !7, i64 176, !7, i64 184, !10, i64 192, !11, i64 196, !7, i64 200, !8, i64 208, !11, i64 212, !8, i64 216, !10, i64 240, !7, i64 248, !10, i64 256, !7, i64 264}
!13 = !{!"double", !8, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 2, !10, i64 4}
!16 = !{!"long", !8, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!18 = !{!6, !16, i64 672}
!19 = !{!6, !7, i64 664}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !10, i64 0}
!22 = !{!"", !10, i64 0, !11, i64 4, !11, i64 6, !10, i64 8, !11, i64 12, !8, i64 14, !8, i64 15, !7, i64 16}
!23 = !{!22, !11, i64 4}
!24 = !{!22, !11, i64 6}
!25 = !{!22, !10, i64 8}
!26 = !{!22, !11, i64 12}
!27 = !{!22, !8, i64 14}
!28 = !{!22, !8, i64 15}
!29 = !{!22, !7, i64 16}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}


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