; LLVM IR from giacomo-ascari/dichotomic-compression :: legacy/dc/dc.ll (dc_print_pixel_matrix)

; 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._dc_pixel_matrix = type { ptr, i32, i32 }
%struct._dc_corners = type { i32, i32, i32, i32 }
%struct._dc_pixel = type { i8, i8, i8 }

@.str.12 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 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
declare dso_local i32 @ix(i32 noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @_dc_print_pixel_matrix(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, 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
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !12
  store i32 %15, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._dc_corners, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = sext i32 %18 to i64
  store i64 %19, ptr %7, align 8, !tbaa !16
  br label %20

20:                                               ; preds = %84, %2
  %21 = load i64, ptr %7, align 8, !tbaa !16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._dc_corners, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !18
  %25 = sext i32 %24 to i64
  %26 = icmp ult i64 %21, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %87

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._dc_corners, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !19
  %32 = sext i32 %31 to i64
  store i64 %32, ptr %9, align 8, !tbaa !16
  br label %33

33:                                               ; preds = %79, %28
  %34 = load i64, ptr %9, align 8, !tbaa !16
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._dc_corners, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !20
  %38 = sext i32 %37 to i64
  %39 = icmp ult i64 %34, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %33
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %82

41:                                               ; preds = %33
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !16
  %44 = trunc i64 %43 to i32
  %45 = load i64, ptr %7, align 8, !tbaa !16
  %46 = trunc i64 %45 to i32
  %47 = load i32, ptr %6, align 4, !tbaa !13
  %48 = call i32 @ix(i32 noundef %44, i32 noundef %46, i32 noundef %47)
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct._dc_pixel, ptr %42, i64 %49
  %51 = getelementptr inbounds %struct._dc_pixel, ptr %50, i32 0, i32 0
  %52 = load i8, ptr %51, align 1, !tbaa !21
  %53 = zext i8 %52 to i32
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %9, align 8, !tbaa !16
  %56 = trunc i64 %55 to i32
  %57 = load i64, ptr %7, align 8, !tbaa !16
  %58 = trunc i64 %57 to i32
  %59 = load i32, ptr %6, align 4, !tbaa !13
  %60 = call i32 @ix(i32 noundef %56, i32 noundef %58, i32 noundef %59)
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct._dc_pixel, ptr %54, i64 %61
  %63 = getelementptr inbounds %struct._dc_pixel, ptr %62, i32 0, i32 1
  %64 = load i8, ptr %63, align 1, !tbaa !23
  %65 = zext i8 %64 to i32
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !16
  %68 = trunc i64 %67 to i32
  %69 = load i64, ptr %7, align 8, !tbaa !16
  %70 = trunc i64 %69 to i32
  %71 = load i32, ptr %6, align 4, !tbaa !13
  %72 = call i32 @ix(i32 noundef %68, i32 noundef %70, i32 noundef %71)
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct._dc_pixel, ptr %66, i64 %73
  %75 = getelementptr inbounds %struct._dc_pixel, ptr %74, i32 0, i32 2
  %76 = load i8, ptr %75, align 1, !tbaa !24
  %77 = zext i8 %76 to i32
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, i32 noundef %53, i32 noundef %65, i32 noundef %77)
  br label %79

79:                                               ; preds = %41
  %80 = load i64, ptr %9, align 8, !tbaa !16
  %81 = add i64 %80, 1
  store i64 %81, ptr %9, align 8, !tbaa !16
  br label %33, !llvm.loop !25

82:                                               ; preds = %40
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  br label %84

84:                                               ; preds = %82
  %85 = load i64, ptr %7, align 8, !tbaa !16
  %86 = add i64 %85, 1
  store i64 %86, ptr %7, align 8, !tbaa !16
  br label %20, !llvm.loop !27

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

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 = { "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 = !{!"_dc_pixel_matrix", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 4}
!15 = !{!"_dc_corners", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!15, !11, i64 12}
!19 = !{!15, !11, i64 0}
!20 = !{!15, !11, i64 8}
!21 = !{!22, !7, i64 0}
!22 = !{!"_dc_pixel", !7, i64 0, !7, i64 1, !7, i64 2}
!23 = !{!22, !7, i64 1}
!24 = !{!22, !7, i64 2}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


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

%struct._dc_pixel = type { i8, i8, i8 }

@.str.12 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @ix(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @_dc_print_pixel_matrix(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %1, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %.lr.ph25, label %._crit_edge26

.lr.ph25:                                         ; preds = %2
  %11 = sext i32 %7 to i64
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  br label %13

._crit_edge26:                                    ; preds = %._crit_edge, %2
  ret void

13:                                               ; preds = %.lr.ph25, %._crit_edge
  %.02123 = phi i64 [ %11, %.lr.ph25 ], [ %20, %._crit_edge ]
  %14 = load i32, ptr %1, align 4, !tbaa !15
  %15 = load i32, ptr %12, align 4, !tbaa !16
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13
  %17 = sext i32 %14 to i64
  %18 = trunc i64 %.02123 to i32
  br label %24

._crit_edge:                                      ; preds = %24, %13
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %20 = add i64 %.02123, 1
  %21 = load i32, ptr %8, align 4, !tbaa !14
  %22 = sext i32 %21 to i64
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %13, label %._crit_edge26, !llvm.loop !17

24:                                               ; preds = %.lr.ph, %24
  %.022 = phi i64 [ %17, %.lr.ph ], [ %42, %24 ]
  %25 = trunc i64 %.022 to i32
  %26 = tail call i32 @ix(i32 noundef %25, i32 noundef %18, i32 noundef %5)
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct._dc_pixel, ptr %3, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !19
  %30 = zext i8 %29 to i32
  %31 = tail call i32 @ix(i32 noundef %25, i32 noundef %18, i32 noundef %5)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct._dc_pixel, ptr %3, i64 %32, i32 1
  %34 = load i8, ptr %33, align 1, !tbaa !21
  %35 = zext i8 %34 to i32
  %36 = tail call i32 @ix(i32 noundef %25, i32 noundef %18, i32 noundef %5)
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct._dc_pixel, ptr %3, i64 %37, i32 2
  %39 = load i8, ptr %38, align 1, !tbaa !22
  %40 = zext i8 %39 to i32
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, i32 noundef %30, i32 noundef %35, i32 noundef %40)
  %42 = add nuw i64 %.022, 1
  %43 = load i32, ptr %12, align 4, !tbaa !16
  %44 = sext i32 %43 to i64
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %24, label %._crit_edge, !llvm.loop !23
}

attributes #0 = { 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" }

!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 = !{!"_dc_pixel_matrix", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !10, i64 4}
!13 = !{!"_dc_corners", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!14 = !{!13, !10, i64 12}
!15 = !{!13, !10, i64 0}
!16 = !{!13, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !8, i64 0}
!20 = !{!"_dc_pixel", !8, i64 0, !8, i64 1, !8, i64 2}
!21 = !{!20, !8, i64 1}
!22 = !{!20, !8, i64 2}
!23 = distinct !{!23, !18}


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