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

; 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.client_info = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.TIFFSetClientInfo = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 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 willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

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

12:                                               ; preds = %24, %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %22

15:                                               ; preds = %12
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.client_info, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i32 @strcmp(ptr noundef %18, ptr noundef %19) #7
  %21 = icmp ne i32 %20, 0
  br label %22

22:                                               ; preds = %15, %12
  %23 = phi i1 [ false, %12 ], [ %21, %15 ]
  br i1 %23, label %24, label %28

24:                                               ; preds = %22
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.client_info, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  store ptr %27, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !22

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.client_info, ptr %33, i32 0, i32 1
  store ptr %32, ptr %34, align 8, !tbaa !24
  store i32 1, ptr %8, align 4
  br label %72

35:                                               ; preds = %28
  %36 = call ptr @_TIFFmalloc(i32 noundef 24)
  store ptr %36, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  br label %41

40:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 103, ptr noundef @__PRETTY_FUNCTION__.TIFFSetClientInfo) #8
  unreachable

41:                                               ; preds = %39
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tiff, ptr %42, i32 0, i32 62
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.client_info, ptr %45, i32 0, i32 0
  store ptr %44, ptr %46, align 8, !tbaa !21
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i64 @strlen(ptr noundef %47) #7
  %49 = add i64 %48, 1
  %50 = trunc i64 %49 to i32
  %51 = call ptr @_TIFFmalloc(i32 noundef %50)
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.client_info, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !19
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.client_info, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %41
  br label %60

59:                                               ; preds = %41
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 106, ptr noundef @__PRETTY_FUNCTION__.TIFFSetClientInfo) #8
  unreachable

60:                                               ; preds = %58
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.client_info, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = call ptr @strcpy(ptr noundef %63, ptr noundef %64) #6
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.client_info, ptr %67, i32 0, i32 1
  store ptr %66, ptr %68, align 8, !tbaa !24
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.tiff, ptr %70, i32 0, i32 62
  store ptr %69, ptr %71, align 8, !tbaa !9
  store i32 0, ptr %8, align 4
  br label %72

72:                                               ; preds = %60, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %73 = load i32, ptr %8, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

declare ptr @_TIFFmalloc(i32 noundef) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { noreturn 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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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 712}
!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 = !{!20, !6, i64 16}
!20 = !{!"client_info", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!20, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!20, !6, i64 8}


; 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 [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.TIFFSetClientInfo = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @TIFFSetClientInfo(ptr nocapture noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 712
  br label %5

5:                                                ; preds = %6, %3
  %.0.in = phi ptr [ %4, %3 ], [ %.0, %6 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.critedge25, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %8, ptr noundef nonnull dereferenceable(1) %2) #5
  %.not22 = icmp eq i32 %9, 0
  br i1 %.not22, label %.critedge, label %5, !llvm.loop !11

.critedge:                                        ; preds = %6
  %10 = getelementptr inbounds i8, ptr %.0, i64 8
  store ptr %1, ptr %10, align 8, !tbaa !13
  br label %24

.critedge25:                                      ; preds = %5
  %11 = tail call ptr @_TIFFmalloc(i32 noundef 24) #6
  %.not23 = icmp eq ptr %11, null
  br i1 %.not23, label %12, label %13

12:                                               ; preds = %.critedge25
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 103, ptr noundef nonnull @__PRETTY_FUNCTION__.TIFFSetClientInfo) #7
  unreachable

13:                                               ; preds = %.critedge25
  %14 = load ptr, ptr %4, align 8, !tbaa !14
  store ptr %14, ptr %11, align 8, !tbaa !24
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #5
  %16 = trunc i64 %15 to i32
  %17 = add i32 %16, 1
  %18 = tail call ptr @_TIFFmalloc(i32 noundef %17) #6
  %19 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %18, ptr %19, align 8, !tbaa !9
  %.not24 = icmp eq ptr %18, null
  br i1 %.not24, label %20, label %21

20:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 106, ptr noundef nonnull @__PRETTY_FUNCTION__.TIFFSetClientInfo) #7
  unreachable

21:                                               ; preds = %13
  %22 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %18, ptr noundef nonnull dereferenceable(1) %2) #6
  %23 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %1, ptr %23, align 8, !tbaa !13
  store ptr %11, ptr %4, align 8, !tbaa !14
  br label %24

24:                                               ; preds = %21, %.critedge
  ret void
}

declare ptr @_TIFFmalloc(i32 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

attributes #0 = { 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 #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 = { "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 = { noreturn 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 nofree nounwind willreturn memory(argmem: readwrite) "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 }
attributes #7 = { noreturn 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 16}
!10 = !{!"client_info", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !6, i64 712}
!15 = !{!"tiff", !6, i64 0, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !16, i64 24, !6, i64 32, !17, i64 40, !18, i64 48, !21, i64 320, !6, i64 328, !6, i64 336, !16, i64 344, !17, i64 348, !16, i64 352, !16, i64 356, !16, i64 360, !17, i64 364, !16, i64 368, !16, i64 372, !16, i64 376, !16, i64 380, !16, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !16, 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, !16, i64 536, !16, i64 540, !6, i64 544, !16, i64 552, !6, i64 560, !16, i64 568, !6, i64 576, !16, 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, !22, i64 672, !6, i64 680, !23, i64 688, !6, i64 712}
!16 = !{!"int", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0, !16, i64 32, !16, i64 36, !16, i64 40, !16, i64 44, !16, i64 48, !16, i64 52, !16, i64 56, !17, i64 60, !17, i64 62, !17, i64 64, !17, i64 66, !17, i64 68, !17, i64 70, !17, i64 72, !17, i64 74, !16, i64 76, !17, i64 80, !17, i64 82, !19, i64 88, !19, i64 96, !20, i64 104, !20, i64 108, !17, i64 112, !17, i64 114, !20, i64 116, !20, i64 120, !7, i64 124, !7, i64 128, !7, i64 152, !17, i64 156, !6, i64 160, !16, i64 168, !16, i64 172, !6, i64 176, !6, i64 184, !16, i64 192, !17, i64 196, !6, i64 200, !7, i64 208, !17, i64 212, !7, i64 216, !16, i64 240, !6, i64 248, !16, i64 256, !6, i64 264}
!19 = !{!"double", !7, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = !{!"", !17, i64 0, !17, i64 2, !16, i64 4}
!22 = !{!"long", !7, i64 0}
!23 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!10, !6, i64 0}


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