; LLVM IR from Stephane-D/SGDK :: src (tools)

; 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.Bitmap = type { i16, i16, i16, ptr, ptr }

; 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 ptr @allocateBitmap(ptr noundef) #1

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

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %5, align 8, !tbaa !5
  br label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call ptr @allocateBitmap(ptr noundef %12)
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %11, %9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %80

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Bitmap, ptr %18, i32 0, i32 1
  %20 = load i16, ptr %19, align 2, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Bitmap, ptr %21, i32 0, i32 1
  store i16 %20, ptr %22, align 2, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Bitmap, ptr %23, i32 0, i32 2
  %25 = load i16, ptr %24, align 4, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Bitmap, ptr %26, i32 0, i32 2
  store i16 %25, ptr %27, align 4, !tbaa !12
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Bitmap, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Bitmap, ptr %31, i32 0, i32 3
  store ptr %30, ptr %32, align 8, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Bitmap, ptr %33, i32 0, i32 0
  store i16 0, ptr %34, align 8, !tbaa !14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Bitmap, ptr %35, i32 0, i32 0
  %37 = load i16, ptr %36, align 8, !tbaa !14
  %38 = zext i16 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %51

40:                                               ; preds = %17
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Bitmap, ptr %41, i32 0, i32 0
  %43 = load i16, ptr %42, align 8, !tbaa !14
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Bitmap, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Bitmap, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = call i64 @unpack(i16 noundef zeroext %43, ptr noundef %46, ptr noundef %49)
  br label %79

51:                                               ; preds = %17
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Bitmap, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Bitmap, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = icmp ne ptr %54, %57
  br i1 %58, label %59, label %78

59:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Bitmap, ptr %60, i32 0, i32 1
  %62 = load i16, ptr %61, align 2, !tbaa !9
  %63 = zext i16 %62 to i32
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Bitmap, ptr %64, i32 0, i32 2
  %66 = load i16, ptr %65, align 4, !tbaa !12
  %67 = zext i16 %66 to i32
  %68 = mul nsw i32 %63, %67
  %69 = sdiv i32 %68, 2
  %70 = trunc i32 %69 to i16
  store i16 %70, ptr %6, align 2, !tbaa !16
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Bitmap, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Bitmap, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load i16, ptr %6, align 2, !tbaa !16
  call void @memcpy(ptr noundef %73, ptr noundef %76, i16 noundef zeroext %77)
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  br label %78

78:                                               ; preds = %59, %51
  br label %79

79:                                               ; preds = %78, %40
  br label %80

80:                                               ; preds = %79, %14
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %81
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @unpack(i16 noundef zeroext, ptr noundef, ptr noundef) #1

declare void @memcpy(ptr noundef, ptr noundef, i16 noundef zeroext) #2

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, !11, i64 2}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!11, !11, i64 0}


; 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
declare dso_local ptr @allocateBitmap(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @unpackBitmap(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %.thread

3:                                                ; preds = %2
  %4 = tail call ptr @allocateBitmap(ptr noundef %0)
  %.not25 = icmp eq ptr %4, null
  br i1 %.not25, label %28, label %.thread

.thread:                                          ; preds = %2, %3
  %.030 = phi ptr [ %4, %3 ], [ %1, %2 ]
  %5 = getelementptr inbounds i8, ptr %0, i64 2
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %.030, i64 2
  store i16 %6, ptr %7, align 2, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i16, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %.030, i64 4
  store i16 %9, ptr %10, align 4, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %.030, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !12
  store i16 0, ptr %.030, align 8, !tbaa !13
  %14 = load i16, ptr %0, align 8, !tbaa !13
  %.not26 = icmp eq i16 %14, 0
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %.030, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  br i1 %.not26, label %21, label %19

19:                                               ; preds = %.thread
  %20 = tail call i64 @unpack(i16 noundef zeroext %14, ptr noundef %16, ptr noundef %18)
  br label %28

21:                                               ; preds = %.thread
  %.not27 = icmp eq ptr %16, %18
  br i1 %.not27, label %28, label %22

22:                                               ; preds = %21
  %23 = zext i16 %6 to i32
  %24 = zext i16 %9 to i32
  %25 = mul nuw nsw i32 %24, %23
  %26 = lshr i32 %25, 1
  %27 = trunc i32 %26 to i16
  tail call void @memcpy(ptr noundef %18, ptr noundef %16, i16 noundef zeroext %27) #2
  br label %28

28:                                               ; preds = %19, %22, %21, %3
  %.031 = phi ptr [ %.030, %19 ], [ %.030, %22 ], [ %.030, %21 ], [ null, %3 ]
  ret ptr %.031
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @unpack(i16 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @memcpy(ptr noundef, ptr noundef, i16 noundef zeroext) 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, !7, i64 2}
!6 = !{!"", !7, i64 0, !7, i64 2, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 16}


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