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

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

@stdout = external global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [23 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

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

declare i32 @fflush(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @_dc_decompression_init(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_decompression_destroy(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_deserialize(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_render(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_pack(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @dc_decompress(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.33, ptr noundef %12)
  br label %14

14:                                               ; preds = %11, %3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.34, ptr noundef %18)
  br label %20

20:                                               ; preds = %17, %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call ptr @_dc_decompression_init(ptr noundef %21, ptr noundef %22, i32 noundef %23)
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %20
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.35)
  br label %29

29:                                               ; preds = %27, %20
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr @stdout, align 8, !tbaa !5
  %34 = call i32 @fflush(ptr noundef %33)
  br label %35

35:                                               ; preds = %32, %29
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_dc_deserialize(ptr noundef %36)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %56

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._dc_decompression, ptr %40, i32 0, i32 1
  %42 = load i8, ptr %41, align 4, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %54

46:                                               ; preds = %39
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._dc_decompression, ptr %47, i32 0, i32 1
  %49 = load i8, ptr %48, align 4, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 2
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, i32 2, i32 0
  br label %54

54:                                               ; preds = %46, %45
  %55 = phi i32 [ 4, %45 ], [ %53, %46 ]
  store i32 %55, ptr %8, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %54, %35
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %77

59:                                               ; preds = %56
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._dc_decompression, ptr %60, i32 0, i32 5
  %62 = load i64, ptr %61, align 8, !tbaa !14
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = mul i64 %62, %64
  %66 = add i64 %65, 10
  %67 = udiv i64 %66, 1000
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._dc_decompression, ptr %68, i32 0, i32 1
  %70 = load i8, ptr %69, align 4, !tbaa !11
  %71 = zext i8 %70 to i32
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._dc_decompression, ptr %72, i32 0, i32 4
  %74 = load i8, ptr %73, align 8, !tbaa !15
  %75 = zext i8 %74 to i32
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.36, i64 noundef %67, i32 noundef %71, i32 noundef %75)
  br label %77

77:                                               ; preds = %59, %56
  %78 = load i32, ptr %6, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %82

80:                                               ; preds = %77
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.37)
  br label %82

82:                                               ; preds = %80, %77
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %88

85:                                               ; preds = %82
  %86 = load ptr, ptr @stdout, align 8, !tbaa !5
  %87 = call i32 @fflush(ptr noundef %86)
  br label %88

88:                                               ; preds = %85, %82
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_dc_render(ptr noundef %89)
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %97

92:                                               ; preds = %88
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._dc_decompression, ptr %93, i32 0, i32 5
  %95 = load i64, ptr %94, align 8, !tbaa !14
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, i64 noundef %95)
  br label %97

97:                                               ; preds = %92, %88
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %102

100:                                              ; preds = %97
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.38)
  br label %102

102:                                              ; preds = %100, %97
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %108

105:                                              ; preds = %102
  %106 = load ptr, ptr @stdout, align 8, !tbaa !5
  %107 = call i32 @fflush(ptr noundef %106)
  br label %108

108:                                              ; preds = %105, %102
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_dc_pack(ptr noundef %109)
  %110 = load i32, ptr %6, align 4, !tbaa !9
  %111 = icmp ne i32 %110, 0
  br i1 %111, label %112, label %124

112:                                              ; preds = %108
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct._dc_decompression, ptr %113, i32 0, i32 6
  %115 = load ptr, ptr %114, align 8, !tbaa !16
  %116 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %115, i32 0, i32 1
  %117 = load i32, ptr %116, align 8, !tbaa !17
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct._dc_decompression, ptr %118, i32 0, i32 6
  %120 = load ptr, ptr %119, align 8, !tbaa !16
  %121 = getelementptr inbounds %struct._dc_pixel_matrix, ptr %120, i32 0, i32 2
  %122 = load i32, ptr %121, align 4, !tbaa !19
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.39, i32 noundef %117, i32 noundef %122)
  br label %124

124:                                              ; preds = %112, %108
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_dc_decompression_destroy(ptr noundef %125)
  %126 = load i32, ptr %6, align 4, !tbaa !9
  %127 = icmp ne i32 %126, 0
  br i1 %127, label %128, label %130

128:                                              ; preds = %124
  %129 = call i32 (ptr, ...) @printf(ptr noundef @.str.40)
  br label %130

130:                                              ; preds = %128, %124
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 4}
!12 = !{!"_dc_decompression", !10, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !7, i64 24, !13, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 32}
!15 = !{!12, !7, i64 24}
!16 = !{!12, !6, i64 40}
!17 = !{!18, !10, i64 8}
!18 = !{!"_dc_pixel_matrix", !6, i64 0, !10, i64 8, !10, i64 12}
!19 = !{!18, !10, i64 12}


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

@stdout = external local_unnamed_addr global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @_dc_decompression_init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_decompression_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_deserialize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_render(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @_dc_pack(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dc_decompress(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.thread46, label %5

.thread46:                                        ; preds = %3
  %4 = tail call ptr @_dc_decompression_init(ptr noundef %0, ptr noundef %1, i32 noundef 0)
  tail call void @_dc_deserialize(ptr noundef %4)
  tail call void @_dc_render(ptr noundef %4)
  tail call void @_dc_pack(ptr noundef %4)
  tail call void @_dc_decompression_destroy(ptr noundef %4)
  br label %44

5:                                                ; preds = %3
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33, ptr noundef %0)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34, ptr noundef %1)
  %8 = tail call ptr @_dc_decompression_init(ptr noundef %0, ptr noundef %1, i32 noundef %2)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.35)
  %10 = load ptr, ptr @stdout, align 8, !tbaa !5
  %11 = tail call i32 @fflush(ptr noundef %10)
  tail call void @_dc_deserialize(ptr noundef %8)
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i8, ptr %12, align 4, !tbaa !9
  %14 = icmp eq i8 %13, 1
  %15 = icmp eq i8 %13, 2
  %16 = select i1 %15, i64 2, i64 0
  %17 = select i1 %14, i64 4, i64 %16
  %18 = getelementptr inbounds i8, ptr %8, i64 32
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = mul i64 %17, %19
  %21 = add i64 %20, 10
  %22 = udiv i64 %21, 1000
  %23 = zext i8 %13 to i32
  %24 = getelementptr inbounds i8, ptr %8, i64 24
  %25 = load i8, ptr %24, align 8, !tbaa !14
  %26 = zext i8 %25 to i32
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36, i64 noundef %22, i32 noundef %23, i32 noundef %26)
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.37)
  %29 = load ptr, ptr @stdout, align 8, !tbaa !5
  %30 = tail call i32 @fflush(ptr noundef %29)
  tail call void @_dc_render(ptr noundef %8)
  %31 = load i64, ptr %18, align 8, !tbaa !13
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i64 noundef %31)
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.38)
  %34 = load ptr, ptr @stdout, align 8, !tbaa !5
  %35 = tail call i32 @fflush(ptr noundef %34)
  tail call void @_dc_pack(ptr noundef %8)
  %36 = getelementptr inbounds i8, ptr %8, i64 40
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = load i32, ptr %38, align 8, !tbaa !16
  %40 = getelementptr inbounds i8, ptr %37, i64 12
  %41 = load i32, ptr %40, align 4, !tbaa !18
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.39, i32 noundef %39, i32 noundef %41)
  tail call void @_dc_decompression_destroy(ptr noundef %8)
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.40)
  br label %44

44:                                               ; preds = %.thread46, %5
  ret void
}

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

!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, !7, i64 4}
!10 = !{!"_dc_decompression", !11, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !7, i64 24, !12, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 32}
!14 = !{!10, !7, i64 24}
!15 = !{!10, !6, i64 40}
!16 = !{!17, !11, i64 8}
!17 = !{!"_dc_pixel_matrix", !6, i64 0, !11, i64 8, !11, i64 12}
!18 = !{!17, !11, i64 12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass