; LLVM IR from niessner/Matterport :: code/gaps/pkgs/jpeg (jcinit)

; 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.jpeg_compress_struct = type { ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i32, i32, i32, double, i32, i32, i32, ptr, [4 x ptr], [4 x ptr], [4 x ptr], [16 x i8], [16 x i8], [16 x i8], i32, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i16, i16, i32, i32, i32, i32, i32, i32, i32, [4 x ptr], i32, i32, i32, [10 x i32], i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.jpeg_error_mgr = type { ptr, ptr, ptr, ptr, ptr, i32, %union.anon, i32, i64, ptr, i32, ptr, i32, i32 }
%union.anon = type { [8 x i32], [48 x i8] }
%struct.jpeg_memory_mgr = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64 }
%struct.jpeg_marker_writer = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @jinit_compress_master(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_c_master_control(ptr noundef %3, i32 noundef 0)
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %4, i32 0, i32 24
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %12, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_color_converter(ptr noundef %9)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_downsampler(ptr noundef %10)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_c_prep_controller(ptr noundef %11, i32 noundef 0)
  br label %12

12:                                               ; preds = %8, %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_forward_dct(ptr noundef %13)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %14, i32 0, i32 25
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %29

18:                                               ; preds = %12
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %21, i32 0, i32 5
  store i32 1, ptr %22, align 8, !tbaa !16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = getelementptr inbounds %struct.jpeg_error_mgr, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  call void %27(ptr noundef %28)
  br label %39

29:                                               ; preds = %12
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %30, i32 0, i32 40
  %32 = load i32, ptr %31, align 4, !tbaa !20
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_phuff_encoder(ptr noundef %35)
  br label %38

36:                                               ; preds = %29
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_huff_encoder(ptr noundef %37)
  br label %38

38:                                               ; preds = %36, %34
  br label %39

39:                                               ; preds = %38, %18
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %41, i32 0, i32 22
  %43 = load i32, ptr %42, align 8, !tbaa !21
  %44 = icmp sgt i32 %43, 1
  br i1 %44, label %50, label %45

45:                                               ; preds = %39
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %46, i32 0, i32 26
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = icmp ne i32 %48, 0
  br label %50

50:                                               ; preds = %45, %39
  %51 = phi i1 [ true, %39 ], [ %49, %45 ]
  %52 = zext i1 %51 to i32
  call void @jinit_c_coef_controller(ptr noundef %40, i32 noundef %52)
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_c_main_controller(ptr noundef %53, i32 noundef 0)
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jinit_marker_writer(ptr noundef %54)
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !23
  %58 = getelementptr inbounds %struct.jpeg_memory_mgr, ptr %57, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !24
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  call void %59(ptr noundef %60)
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.jpeg_compress_struct, ptr %61, i32 0, i32 58
  %63 = load ptr, ptr %62, align 8, !tbaa !26
  %64 = getelementptr inbounds %struct.jpeg_marker_writer, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !27
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  call void %65(ptr noundef %66)
  ret void
}

declare void @jinit_c_master_control(ptr noundef, i32 noundef) #1

declare void @jinit_color_converter(ptr noundef) #1

declare void @jinit_downsampler(ptr noundef) #1

declare void @jinit_c_prep_controller(ptr noundef, i32 noundef) #1

declare void @jinit_forward_dct(ptr noundef) #1

declare void @jinit_phuff_encoder(ptr noundef) #1

declare void @jinit_huff_encoder(ptr noundef) #1

declare void @jinit_c_coef_controller(ptr noundef, i32 noundef) #1

declare void @jinit_c_main_controller(ptr noundef, i32 noundef) #1

declare void @jinit_marker_writer(ptr noundef) #1

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 = { "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, !11, i64 256}
!10 = !{!"jpeg_compress_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !12, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !6, i64 88, !7, i64 96, !7, i64 128, !7, i64 160, !7, i64 192, !7, i64 208, !7, i64 224, !11, i64 240, !6, i64 248, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !11, i64 288, !7, i64 292, !7, i64 293, !7, i64 294, !13, i64 296, !13, i64 298, !11, i64 300, !11, i64 304, !11, i64 308, !11, i64 312, !11, i64 316, !11, i64 320, !11, i64 324, !7, i64 328, !11, i64 360, !11, i64 364, !11, i64 368, !7, i64 372, !11, i64 412, !11, i64 416, !11, i64 420, !11, 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, !11, i64 512}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !11, i64 260}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !11, i64 40}
!17 = !{!"jpeg_error_mgr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !7, i64 44, !11, i64 124, !18, i64 128, !6, i64 136, !11, i64 144, !6, i64 152, !11, i64 160, !11, i64 164}
!18 = !{!"long", !7, i64 0}
!19 = !{!17, !6, i64 0}
!20 = !{!10, !11, i64 308}
!21 = !{!10, !11, i64 240}
!22 = !{!10, !11, i64 264}
!23 = !{!10, !6, i64 8}
!24 = !{!25, !6, i64 48}
!25 = !{!"jpeg_memory_mgr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !18, i64 88, !18, i64 96}
!26 = !{!10, !6, i64 464}
!27 = !{!28, !6, i64 0}
!28 = !{!"jpeg_marker_writer", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}


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

; Function Attrs: nounwind uwtable
define dso_local void @jinit_compress_master(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @jinit_c_master_control(ptr noundef %0, i32 noundef 0) #2
  %2 = getelementptr inbounds i8, ptr %0, i64 256
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %1
  tail call void @jinit_color_converter(ptr noundef nonnull %0) #2
  tail call void @jinit_downsampler(ptr noundef nonnull %0) #2
  tail call void @jinit_c_prep_controller(ptr noundef nonnull %0, i32 noundef 0) #2
  br label %5

5:                                                ; preds = %4, %1
  tail call void @jinit_forward_dct(ptr noundef nonnull %0) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 260
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %.not22 = icmp eq i32 %7, 0
  br i1 %.not22, label %12, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr %0, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %9, i64 40
  store i32 1, ptr %10, align 8, !tbaa !15
  %11 = load ptr, ptr %9, align 8, !tbaa !18
  tail call void %11(ptr noundef nonnull %0) #2
  br label %17

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 308
  %14 = load i32, ptr %13, align 4, !tbaa !19
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %16, label %15

15:                                               ; preds = %12
  tail call void @jinit_phuff_encoder(ptr noundef nonnull %0) #2
  br label %17

16:                                               ; preds = %12
  tail call void @jinit_huff_encoder(ptr noundef nonnull %0) #2
  br label %17

17:                                               ; preds = %15, %16, %8
  %18 = getelementptr inbounds i8, ptr %0, i64 240
  %19 = load i32, ptr %18, align 8, !tbaa !20
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %26, label %21

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 264
  %23 = load i32, ptr %22, align 8, !tbaa !21
  %24 = icmp ne i32 %23, 0
  %25 = zext i1 %24 to i32
  br label %26

26:                                               ; preds = %21, %17
  %27 = phi i32 [ 1, %17 ], [ %25, %21 ]
  tail call void @jinit_c_coef_controller(ptr noundef nonnull %0, i32 noundef %27) #2
  tail call void @jinit_c_main_controller(ptr noundef nonnull %0, i32 noundef 0) #2
  tail call void @jinit_marker_writer(ptr noundef nonnull %0) #2
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %29, i64 48
  %31 = load ptr, ptr %30, align 8, !tbaa !23
  tail call void %31(ptr noundef nonnull %0) #2
  %32 = getelementptr inbounds i8, ptr %0, i64 464
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  %34 = load ptr, ptr %33, align 8, !tbaa !26
  tail call void %34(ptr noundef nonnull %0) #2
  ret void
}

declare void @jinit_c_master_control(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @jinit_color_converter(ptr noundef) local_unnamed_addr #1

declare void @jinit_downsampler(ptr noundef) local_unnamed_addr #1

declare void @jinit_c_prep_controller(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @jinit_forward_dct(ptr noundef) local_unnamed_addr #1

declare void @jinit_phuff_encoder(ptr noundef) local_unnamed_addr #1

declare void @jinit_huff_encoder(ptr noundef) local_unnamed_addr #1

declare void @jinit_c_coef_controller(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @jinit_c_main_controller(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @jinit_marker_writer(ptr noundef) local_unnamed_addr #1

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 = { "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, !10, i64 256}
!6 = !{!"jpeg_compress_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !11, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !7, i64 88, !8, i64 96, !8, i64 128, !8, i64 160, !8, i64 192, !8, i64 208, !8, i64 224, !10, i64 240, !7, i64 248, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !10, i64 288, !8, i64 292, !8, i64 293, !8, i64 294, !12, i64 296, !12, i64 298, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !8, i64 328, !10, i64 360, !10, i64 364, !10, i64 368, !8, i64 372, !10, i64 412, !10, i64 416, !10, i64 420, !10, 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, !10, i64 512}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !10, i64 260}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !10, i64 40}
!16 = !{!"jpeg_error_mgr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !8, i64 44, !10, i64 124, !17, i64 128, !7, i64 136, !10, i64 144, !7, i64 152, !10, i64 160, !10, i64 164}
!17 = !{!"long", !8, i64 0}
!18 = !{!16, !7, i64 0}
!19 = !{!6, !10, i64 308}
!20 = !{!6, !10, i64 240}
!21 = !{!6, !10, i64 264}
!22 = !{!6, !7, i64 8}
!23 = !{!24, !7, i64 48}
!24 = !{!"jpeg_memory_mgr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !17, i64 88, !17, i64 96}
!25 = !{!6, !7, i64 464}
!26 = !{!27, !7, i64 0}
!27 = !{!"jpeg_marker_writer", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass