; LLVM IR from VTIvanov20/eight-ball-pool :: src/main.ll (Z12GuiLoadIconsPKcb)

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

@.str.27 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZL8guiIcons = external hidden global <{ [1599 x i32], [449 x i32] }>, align 16

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z12GuiLoadIconsPKcb(ptr noundef %0, i1 noundef zeroext %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [5 x i8], align 1
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %13 = zext i1 %1 to i8
  store i8 %13, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call noalias ptr @fopen(ptr noundef %14, ptr noundef @.str.27)
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %103

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 5, ptr %7) #5
  call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 5, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #5
  store i16 0, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #5
  store i16 0, ptr %9, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #5
  store i16 0, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #5
  store i16 0, ptr %11, align 2, !tbaa !11
  %19 = getelementptr inbounds [5 x i8], ptr %7, i64 0, i64 0
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i64 @fread(ptr noundef %19, i64 noundef 1, i64 noundef 4, ptr noundef %20)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @fread(ptr noundef %8, i64 noundef 1, i64 noundef 2, ptr noundef %22)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i64 @fread(ptr noundef %9, i64 noundef 1, i64 noundef 2, ptr noundef %24)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i64 @fread(ptr noundef %10, i64 noundef 1, i64 noundef 2, ptr noundef %26)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i64 @fread(ptr noundef %11, i64 noundef 1, i64 noundef 2, ptr noundef %28)
  %30 = getelementptr inbounds [5 x i8], ptr %7, i64 0, i64 0
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 114
  br i1 %33, label %34, label %100

34:                                               ; preds = %18
  %35 = getelementptr inbounds [5 x i8], ptr %7, i64 0, i64 1
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 71
  br i1 %38, label %39, label %100

39:                                               ; preds = %34
  %40 = getelementptr inbounds [5 x i8], ptr %7, i64 0, i64 2
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %42, 73
  br i1 %43, label %44, label %100

44:                                               ; preds = %39
  %45 = getelementptr inbounds [5 x i8], ptr %7, i64 0, i64 3
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 32
  br i1 %48, label %49, label %100

49:                                               ; preds = %44
  %50 = load i8, ptr %4, align 1, !tbaa !9, !range !14, !noundef !15
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %80

52:                                               ; preds = %49
  %53 = load i16, ptr %10, align 2, !tbaa !11
  %54 = sext i16 %53 to i64
  %55 = mul i64 %54, 8
  %56 = call noalias ptr @malloc(i64 noundef %55) #6
  store ptr %56, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !16
  br label %57

57:                                               ; preds = %76, %52
  %58 = load i32, ptr %12, align 4, !tbaa !16
  %59 = load i16, ptr %10, align 2, !tbaa !11
  %60 = sext i16 %59 to i32
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %79

63:                                               ; preds = %57
  %64 = call noalias ptr @malloc(i64 noundef 32) #6
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !16
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %65, i64 %67
  store ptr %64, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i32, ptr %12, align 4, !tbaa !16
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = call i64 @fread(ptr noundef %73, i64 noundef 32, i64 noundef 1, ptr noundef %74)
  br label %76

76:                                               ; preds = %63
  %77 = load i32, ptr %12, align 4, !tbaa !16
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %12, align 4, !tbaa !16
  br label %57, !llvm.loop !18

79:                                               ; preds = %62
  br label %87

80:                                               ; preds = %49
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i16, ptr %10, align 2, !tbaa !11
  %83 = sext i16 %82 to i32
  %84 = mul nsw i32 %83, 32
  %85 = sext i32 %84 to i64
  %86 = call i32 @fseek(ptr noundef %81, i64 noundef %85, i32 noundef 1)
  br label %87

87:                                               ; preds = %80, %79
  %88 = load i16, ptr %10, align 2, !tbaa !11
  %89 = sext i16 %88 to i32
  %90 = load i16, ptr %11, align 2, !tbaa !11
  %91 = sext i16 %90 to i32
  %92 = load i16, ptr %11, align 2, !tbaa !11
  %93 = sext i16 %92 to i32
  %94 = mul nsw i32 %91, %93
  %95 = sdiv i32 %94, 32
  %96 = mul nsw i32 %89, %95
  %97 = sext i32 %96 to i64
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = call i64 @fread(ptr noundef @_ZL8guiIcons, i64 noundef %97, i64 noundef 4, ptr noundef %98)
  br label %100

100:                                              ; preds = %87, %44, %39, %34, %18
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = call i32 @fclose(ptr noundef %101)
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 5, ptr %7) #5
  br label %103

103:                                              ; preds = %100, %2
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %104
}

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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.27 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZL8guiIcons = external hidden global <{ [1599 x i32], [449 x i32] }>, align 16

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

; 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noalias noundef ptr @_Z12GuiLoadIconsPKcb(ptr nocapture noundef readonly %0, i1 noundef zeroext %1) local_unnamed_addr #4 {
  %3 = alloca [5 x i8], align 4
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.27)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %42, label %9

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(5) %3, i8 0, i64 5, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #5
  store i16 0, ptr %4, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #5
  store i16 0, ptr %5, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #5
  store i16 0, ptr %6, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %7) #5
  store i16 0, ptr %7, align 2, !tbaa !5
  %10 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 1, i64 noundef 4, ptr noundef nonnull %8)
  %11 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 1, i64 noundef 2, ptr noundef nonnull %8)
  %12 = call i64 @fread(ptr noundef nonnull %5, i64 noundef 1, i64 noundef 2, ptr noundef nonnull %8)
  %13 = call i64 @fread(ptr noundef nonnull %6, i64 noundef 1, i64 noundef 2, ptr noundef nonnull %8)
  %14 = call i64 @fread(ptr noundef nonnull %7, i64 noundef 1, i64 noundef 2, ptr noundef nonnull %8)
  %15 = load <4 x i8>, ptr %3, align 4
  %.fr = freeze <4 x i8> %15
  %.fr.scalar = bitcast <4 x i8> %.fr to i32
  %16 = icmp eq i32 %.fr.scalar, 541673330
  br i1 %16, label %17, label %40

17:                                               ; preds = %9
  %18 = load i16, ptr %6, align 2, !tbaa !5
  br i1 %1, label %19, label %28

19:                                               ; preds = %17
  %20 = sext i16 %18 to i64
  %21 = shl nsw i64 %20, 3
  %22 = tail call noalias ptr @malloc(i64 noundef %21) #6
  %23 = sext i16 %18 to i32
  %24 = icmp sgt i16 %18, 0
  br i1 %24, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %19
  %wide.trip.count = zext nneg i32 %23 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %25 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #6
  %26 = getelementptr inbounds ptr, ptr %22, i64 %indvars.iv
  store ptr %25, ptr %26, align 8, !tbaa !9
  %27 = tail call i64 @fread(ptr noundef %25, i64 noundef 32, i64 noundef 1, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

28:                                               ; preds = %17
  %29 = sext i16 %18 to i32
  %30 = shl nsw i32 %29, 5
  %31 = sext i32 %30 to i64
  %32 = tail call i32 @fseek(ptr noundef nonnull %8, i64 noundef %31, i32 noundef 1)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %19, %28
  %.pre-phi = phi i32 [ %23, %19 ], [ %29, %28 ], [ %23, %.lr.ph ]
  %.029 = phi ptr [ %22, %19 ], [ null, %28 ], [ %22, %.lr.ph ]
  %33 = load i16, ptr %7, align 2, !tbaa !5
  %34 = sext i16 %33 to i32
  %35 = mul nsw i32 %34, %34
  %36 = lshr i32 %35, 5
  %37 = mul nsw i32 %36, %.pre-phi
  %38 = sext i32 %37 to i64
  %39 = tail call i64 @fread(ptr noundef nonnull @_ZL8guiIcons, i64 noundef %38, i64 noundef 4, ptr noundef nonnull %8)
  br label %40

40:                                               ; preds = %.loopexit, %9
  %.1 = phi ptr [ %.029, %.loopexit ], [ null, %9 ]
  %41 = tail call i32 @fclose(ptr noundef nonnull %8)
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #5
  br label %42

42:                                               ; preds = %40, %2
  %.2 = phi ptr [ %.1, %40 ], [ null, %2 ]
  ret ptr %.2
}

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #4 = { mustprogress nofree 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass