; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Image.ll (ZN7R2Image7CaptureEv)

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

%class.R2Image = type { i32, i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [22 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

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7R2Image7CaptureEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca [4 x i32], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %5 = getelementptr inbounds [4 x i32], ptr %3, i64 0, i64 0
  call void @glGetIntegerv(i32 noundef 2978, ptr noundef %5)
  %6 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds [4 x i32], ptr %3, i64 0, i64 2
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = icmp sge i32 %7, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.8, i32 noundef 296, ptr noundef @.str.2)
  br label %12

12:                                               ; preds = %11, %1
  %13 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = getelementptr inbounds [4 x i32], ptr %3, i64 0, i64 3
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp sge i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.9, i32 noundef 297, ptr noundef @.str.2)
  br label %19

19:                                               ; preds = %18, %12
  %20 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 298, ptr noundef @.str.2)
  br label %24

24:                                               ; preds = %23, %19
  %25 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !15
  switch i32 %26, label %55 [
    i32 1, label %27
    i32 2, label %34
    i32 3, label %41
    i32 4, label %48
  ]

27:                                               ; preds = %24
  %28 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  call void @glReadPixels(i32 noundef 0, i32 noundef 0, i32 noundef %29, i32 noundef %31, i32 noundef 6409, i32 noundef 5121, ptr noundef %33)
  br label %55

34:                                               ; preds = %24
  %35 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  call void @glReadPixels(i32 noundef 0, i32 noundef 0, i32 noundef %36, i32 noundef %38, i32 noundef 6410, i32 noundef 5121, ptr noundef %40)
  br label %55

41:                                               ; preds = %24
  %42 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  call void @glReadPixels(i32 noundef 0, i32 noundef 0, i32 noundef %43, i32 noundef %45, i32 noundef 6407, i32 noundef 5121, ptr noundef %47)
  br label %55

48:                                               ; preds = %24
  %49 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !13
  %53 = getelementptr inbounds %class.R2Image, ptr %4, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  call void @glReadPixels(i32 noundef 0, i32 noundef 0, i32 noundef %50, i32 noundef %52, i32 noundef 6408, i32 noundef 5121, ptr noundef %54)
  br label %55

55:                                               ; preds = %48, %41, %34, %27, %24
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  ret void
}

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

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

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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS7R2Image", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !11, 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 [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [22 x i8], align 1
@switch.table._ZN7R2Image7CaptureEv = private unnamed_addr constant [4 x i32] [i32 6409, i32 6410, i32 6407, i32 6408], align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7R2Image7CaptureEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @glGetIntegerv(i32 noundef 2978, ptr noundef nonnull %2)
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %.not = icmp slt i32 %3, %5
  br i1 %.not, label %6, label %7

6:                                                ; preds = %1
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.8, i32 noundef 296, ptr noundef nonnull @.str.2)
  br label %7

7:                                                ; preds = %6, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %2, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %.not1 = icmp slt i32 %9, %11
  br i1 %.not1, label %12, label %13

12:                                               ; preds = %7
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.9, i32 noundef 297, ptr noundef nonnull @.str.2)
  br label %13

13:                                               ; preds = %12, %7
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %.not2 = icmp eq ptr %15, null
  br i1 %.not2, label %16, label %17

16:                                               ; preds = %13
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 298, ptr noundef nonnull @.str.2)
  br label %17

17:                                               ; preds = %16, %13
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %switch.tableidx = add i32 %19, -1
  %20 = icmp ult i32 %switch.tableidx, 4
  br i1 %20, label %switch.lookup, label %25

switch.lookup:                                    ; preds = %17
  %21 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [4 x i32], ptr @switch.table._ZN7R2Image7CaptureEv, i64 0, i64 %21
  %switch.load = load i32, ptr %switch.gep, align 4
  %22 = load i32, ptr %0, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !12
  %24 = load ptr, ptr %14, align 8, !tbaa !13
  call void @glReadPixels(i32 noundef 0, i32 noundef 0, i32 noundef %22, i32 noundef %23, i32 noundef %switch.load, i32 noundef 5121, ptr noundef %24)
  br label %25

25:                                               ; preds = %17, %switch.lookup
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret void
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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, !7, i64 0}
!6 = !{!"_ZTS7R2Image", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass