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

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

@heap = external hidden global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [12 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 void @KDebug_Alert(ptr noundef) #1

; Function Attrs: noinline nounwind uwtable
define dso_local void @MEM_dump() #2 {
  %1 = alloca [40 x i8], align 16
  %2 = alloca [16 x i8], align 16
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  call void @KDebug_Alert(ptr noundef @.str.10)
  call void @KDebug_Alert(ptr noundef @.str.11)
  call void @llvm.lifetime.start.p0(i64 40, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = load ptr, ptr @heap, align 8, !tbaa !5
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #4
  store i16 0, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  br label %8

8:                                                ; preds = %46, %0
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %10, ptr %5, align 2, !tbaa !9
  %11 = icmp ne i16 %10, 0
  br i1 %11, label %12, label %53

12:                                               ; preds = %8
  %13 = load i16, ptr %5, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = and i32 %14, 1
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %46

17:                                               ; preds = %12
  %18 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %19 = call ptr @strcpy(ptr noundef %18, ptr noundef @.str.12) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %23 = call zeroext i16 @intToHex(i64 noundef %21, ptr noundef %22, i16 noundef zeroext 8)
  %24 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %25 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %26 = call ptr @strcat(ptr noundef %24, ptr noundef %25) #4
  %27 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %28 = call ptr @strcat(ptr noundef %27, ptr noundef @.str.13) #4
  %29 = load i16, ptr %5, align 2, !tbaa !9
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 65534
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %34 = call zeroext i16 @intToStr(i64 noundef %32, ptr noundef %33, i16 noundef zeroext 0)
  %35 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %36 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %37 = call ptr @strcat(ptr noundef %35, ptr noundef %36) #4
  %38 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  call void @KDebug_Alert(ptr noundef %38)
  %39 = load i16, ptr %5, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = and i32 %40, 65534
  %42 = load i16, ptr %4, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = add nsw i32 %43, %41
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %4, align 2, !tbaa !9
  br label %46

46:                                               ; preds = %17, %12
  %47 = load i16, ptr %5, align 2, !tbaa !9
  %48 = zext i16 %47 to i32
  %49 = ashr i32 %48, 1
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds i16, ptr %50, i64 %51
  store ptr %52, ptr %3, align 8, !tbaa !5
  call void @KDebug_Alert(ptr noundef @.str.14)
  br label %8, !llvm.loop !11

53:                                               ; preds = %8
  call void @KDebug_Alert(ptr noundef @.str.15)
  %54 = load ptr, ptr @heap, align 8, !tbaa !5
  store ptr %54, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  store i16 0, ptr %6, align 2, !tbaa !9
  br label %55

55:                                               ; preds = %93, %53
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i16, ptr %56, align 2, !tbaa !9
  store i16 %57, ptr %5, align 2, !tbaa !9
  %58 = icmp ne i16 %57, 0
  br i1 %58, label %59, label %100

59:                                               ; preds = %55
  %60 = load i16, ptr %5, align 2, !tbaa !9
  %61 = zext i16 %60 to i32
  %62 = and i32 %61, 1
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %93, label %64

64:                                               ; preds = %59
  %65 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %66 = call ptr @strcpy(ptr noundef %65, ptr noundef @.str.12) #4
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = ptrtoint ptr %67 to i64
  %69 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %70 = call zeroext i16 @intToHex(i64 noundef %68, ptr noundef %69, i16 noundef zeroext 8)
  %71 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %72 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %73 = call ptr @strcat(ptr noundef %71, ptr noundef %72) #4
  %74 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %75 = call ptr @strcat(ptr noundef %74, ptr noundef @.str.13) #4
  %76 = load i16, ptr %5, align 2, !tbaa !9
  %77 = zext i16 %76 to i32
  %78 = and i32 %77, 65534
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %81 = call zeroext i16 @intToStr(i64 noundef %79, ptr noundef %80, i16 noundef zeroext 0)
  %82 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  %83 = getelementptr inbounds [16 x i8], ptr %2, i64 0, i64 0
  %84 = call ptr @strcat(ptr noundef %82, ptr noundef %83) #4
  %85 = getelementptr inbounds [40 x i8], ptr %1, i64 0, i64 0
  call void @KDebug_Alert(ptr noundef %85)
  %86 = load i16, ptr %5, align 2, !tbaa !9
  %87 = zext i16 %86 to i32
  %88 = and i32 %87, 65534
  %89 = load i16, ptr %6, align 2, !tbaa !9
  %90 = zext i16 %89 to i32
  %91 = add nsw i32 %90, %88
  %92 = trunc i32 %91 to i16
  store i16 %92, ptr %6, align 2, !tbaa !9
  br label %93

93:                                               ; preds = %64, %59
  %94 = load i16, ptr %5, align 2, !tbaa !9
  %95 = zext i16 %94 to i32
  %96 = ashr i32 %95, 1
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = sext i32 %96 to i64
  %99 = getelementptr inbounds i16, ptr %97, i64 %98
  store ptr %99, ptr %3, align 8, !tbaa !5
  call void @KDebug_Alert(ptr noundef @.str.14)
  br label %55, !llvm.loop !13

100:                                              ; preds = %55
  call void @KDebug_Alert(ptr noundef @.str.16)
  %101 = load i16, ptr %4, align 2, !tbaa !9
  %102 = zext i16 %101 to i64
  call void @KDebug_AlertNumber(i64 noundef %102)
  call void @KDebug_Alert(ptr noundef @.str.17)
  %103 = load i16, ptr %6, align 2, !tbaa !9
  %104 = zext i16 %103 to i64
  call void @KDebug_AlertNumber(i64 noundef %104)
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %1) #4
  ret void
}

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

declare zeroext i16 @intToHex(i64 noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #3

declare zeroext i16 @intToStr(i64 noundef, ptr noundef, i16 noundef zeroext) #1

declare void @KDebug_AlertNumber(i64 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 = { noinline 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 "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 = { 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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@heap = external hidden local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [12 x i8], align 1

; 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

declare void @KDebug_Alert(ptr noundef) local_unnamed_addr #1

; Function Attrs: noinline nounwind uwtable
define dso_local void @MEM_dump() local_unnamed_addr #2 {
  %1 = alloca [40 x i8], align 16
  %2 = alloca [16 x i8], align 16
  tail call void @KDebug_Alert(ptr noundef nonnull @.str.10) #4
  tail call void @KDebug_Alert(ptr noundef nonnull @.str.11) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %3 = load ptr, ptr @heap, align 8, !tbaa !5
  %4 = load i16, ptr %3, align 2, !tbaa !9
  %.not26 = icmp eq i16 %4, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %20
  %5 = phi i16 [ %24, %20 ], [ %4, %0 ]
  %.01728 = phi i16 [ %.118, %20 ], [ 0, %0 ]
  %.01927 = phi ptr [ %23, %20 ], [ %3, %0 ]
  %6 = zext i16 %5 to i32
  %7 = and i32 %6, 1
  %.not25 = icmp eq i32 %7, 0
  br i1 %.not25, label %20, label %8

8:                                                ; preds = %.lr.ph
  %9 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.12) #4
  %10 = ptrtoint ptr %.01927 to i64
  %11 = call zeroext i16 @intToHex(i64 noundef %10, ptr noundef nonnull %2, i16 noundef zeroext 8) #4
  %12 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %2) #4
  %13 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.13) #4
  %14 = and i32 %6, 65534
  %15 = zext nneg i32 %14 to i64
  %16 = call zeroext i16 @intToStr(i64 noundef %15, ptr noundef nonnull %2, i16 noundef zeroext 0) #4
  %17 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %2) #4
  call void @KDebug_Alert(ptr noundef nonnull %1) #4
  %18 = trunc nuw i32 %14 to i16
  %19 = add i16 %.01728, %18
  br label %20

20:                                               ; preds = %8, %.lr.ph
  %.118 = phi i16 [ %19, %8 ], [ %.01728, %.lr.ph ]
  %21 = lshr i32 %6, 1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds i16, ptr %.01927, i64 %22
  call void @KDebug_Alert(ptr noundef nonnull @.str.14) #4
  %24 = load i16, ptr %23, align 2, !tbaa !9
  %.not = icmp eq i16 %24, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %20
  %25 = zext i16 %.118 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.017.lcssa = phi i64 [ 0, %0 ], [ %25, %._crit_edge.loopexit ]
  call void @KDebug_Alert(ptr noundef nonnull @.str.15) #4
  %26 = load ptr, ptr @heap, align 8, !tbaa !5
  %27 = load i16, ptr %26, align 2, !tbaa !9
  %.not2329 = icmp eq i16 %27, 0
  br i1 %.not2329, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %._crit_edge, %41
  %28 = phi i16 [ %45, %41 ], [ %27, %._crit_edge ]
  %.031 = phi i16 [ %.1, %41 ], [ 0, %._crit_edge ]
  %.12030 = phi ptr [ %44, %41 ], [ %26, %._crit_edge ]
  %29 = zext i16 %28 to i32
  %30 = and i32 %29, 1
  %.not24 = icmp eq i32 %30, 0
  br i1 %.not24, label %31, label %41

31:                                               ; preds = %.lr.ph33
  %32 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.12) #4
  %33 = ptrtoint ptr %.12030 to i64
  %34 = call zeroext i16 @intToHex(i64 noundef %33, ptr noundef nonnull %2, i16 noundef zeroext 8) #4
  %35 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %2) #4
  %36 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.13) #4
  %37 = zext i16 %28 to i64
  %38 = call zeroext i16 @intToStr(i64 noundef %37, ptr noundef nonnull %2, i16 noundef zeroext 0) #4
  %39 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %2) #4
  call void @KDebug_Alert(ptr noundef nonnull %1) #4
  %40 = add i16 %28, %.031
  br label %41

41:                                               ; preds = %31, %.lr.ph33
  %.1 = phi i16 [ %.031, %.lr.ph33 ], [ %40, %31 ]
  %42 = lshr i32 %29, 1
  %43 = zext nneg i32 %42 to i64
  %44 = getelementptr inbounds i16, ptr %.12030, i64 %43
  call void @KDebug_Alert(ptr noundef nonnull @.str.14) #4
  %45 = load i16, ptr %44, align 2, !tbaa !9
  %.not23 = icmp eq i16 %45, 0
  br i1 %.not23, label %._crit_edge34.loopexit, label %.lr.ph33, !llvm.loop !13

._crit_edge34.loopexit:                           ; preds = %41
  %46 = zext i16 %.1 to i64
  br label %._crit_edge34

._crit_edge34:                                    ; preds = %._crit_edge34.loopexit, %._crit_edge
  %.0.lcssa = phi i64 [ 0, %._crit_edge ], [ %46, %._crit_edge34.loopexit ]
  call void @KDebug_Alert(ptr noundef nonnull @.str.16) #4
  call void @KDebug_AlertNumber(i64 noundef %.017.lcssa) #4
  call void @KDebug_Alert(ptr noundef nonnull @.str.17) #4
  call void @KDebug_AlertNumber(i64 noundef %.0.lcssa) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #4
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

declare zeroext i16 @intToHex(i64 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

declare zeroext i16 @intToStr(i64 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare void @KDebug_AlertNumber(i64 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 = { noinline 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass