; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/openthread_a59ed77b (Z10DumpBufferPKcPKht)

; 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 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  br label %15

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %14, %12
  %16 = phi ptr [ %13, %12 ], [ @.str.1, %14 ]
  %17 = load i16, ptr %6, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %16, i32 noundef %18)
  store i16 0, ptr %8, align 2, !tbaa !9
  br label %20

20:                                               ; preds = %54, %15
  %21 = load i16, ptr %6, align 2, !tbaa !9
  %22 = add i16 %21, -1
  store i16 %22, ptr %6, align 2, !tbaa !9
  %23 = icmp ne i16 %21, 0
  br i1 %23, label %24, label %55

24:                                               ; preds = %20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %25, align 1, !tbaa !11
  store i8 %27, ptr %9, align 1, !tbaa !11
  %28 = load i8, ptr %9, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %29)
  %31 = load i8, ptr %9, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = call i32 @isprint(i32 noundef %32) #5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %24
  %36 = load i8, ptr %9, align 1, !tbaa !11
  br label %38

37:                                               ; preds = %24
  br label %38

38:                                               ; preds = %37, %35
  %39 = phi i8 [ %36, %35 ], [ 46, %37 ]
  %40 = load i16, ptr %8, align 2, !tbaa !9
  %41 = zext i16 %40 to i64
  %42 = getelementptr inbounds [17 x i8], ptr %7, i64 0, i64 %41
  store i8 %39, ptr %42, align 1, !tbaa !11
  %43 = load i16, ptr %8, align 2, !tbaa !9
  %44 = add i16 %43, 1
  store i16 %44, ptr %8, align 2, !tbaa !9
  %45 = load i16, ptr %8, align 2, !tbaa !9
  %46 = zext i16 %45 to i32
  %47 = icmp eq i32 %46, 16
  br i1 %47, label %48, label %54

48:                                               ; preds = %38
  %49 = load i16, ptr %8, align 2, !tbaa !9
  %50 = zext i16 %49 to i64
  %51 = getelementptr inbounds [17 x i8], ptr %7, i64 0, i64 %50
  store i8 0, ptr %51, align 1, !tbaa !11
  %52 = getelementptr inbounds [17 x i8], ptr %7, i64 0, i64 0
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %52)
  store i16 0, ptr %8, align 2, !tbaa !9
  br label %54

54:                                               ; preds = %48, %38
  br label %20, !llvm.loop !12

55:                                               ; preds = %20
  %56 = load i16, ptr %8, align 2, !tbaa !9
  %57 = zext i16 %56 to i64
  %58 = getelementptr inbounds [17 x i8], ptr %7, i64 0, i64 %57
  store i8 0, ptr %58, align 1, !tbaa !11
  br label %59

59:                                               ; preds = %64, %55
  %60 = load i16, ptr %8, align 2, !tbaa !9
  %61 = add i16 %60, 1
  store i16 %61, ptr %8, align 2, !tbaa !9
  %62 = zext i16 %60 to i32
  %63 = icmp slt i32 %62, 16
  br i1 %63, label %64, label %66

64:                                               ; preds = %59
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %59, !llvm.loop !14

66:                                               ; preds = %59
  %67 = getelementptr inbounds [17 x i8], ptr %7, i64 0, i64 0
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %67)
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 17, ptr %7) #4
  ret void
}

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isprint(i32 noundef) #3

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

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

!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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z10DumpBufferPKcPKht(ptr noundef %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [17 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 17, ptr nonnull %4) #4
  %.not = icmp eq ptr %0, null
  %5 = select i1 %.not, ptr @.str.1, ptr %0
  %6 = zext i16 %2 to i32
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %5, i32 noundef %6)
  %.not1517 = icmp eq i16 %2, 0
  br i1 %.not1517, label %._crit_edge.thread, label %.lr.ph.preheader

._crit_edge.thread:                               ; preds = %3
  store i8 0, ptr %4, align 16, !tbaa !5
  br label %.lr.ph22.preheader

.lr.ph.preheader:                                 ; preds = %3
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %22
  %.in = phi i16 [ %9, %22 ], [ %2, %.lr.ph.preheader ]
  %.019 = phi ptr [ %10, %22 ], [ %1, %.lr.ph.preheader ]
  %.01318 = phi i16 [ %.1, %22 ], [ 0, %.lr.ph.preheader ]
  %9 = add i16 %.in, -1
  %10 = getelementptr inbounds i8, ptr %.019, i64 1
  %11 = load i8, ptr %.019, align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %12)
  %14 = call i32 @isprint(i32 noundef %12) #5
  %.not16 = icmp eq i32 %14, 0
  %15 = select i1 %.not16, i8 46, i8 %11
  %16 = zext i16 %.01318 to i64
  %17 = getelementptr inbounds [17 x i8], ptr %4, i64 0, i64 %16
  store i8 %15, ptr %17, align 1, !tbaa !5
  %18 = add i16 %.01318, 1
  %19 = icmp eq i16 %18, 16
  br i1 %19, label %20, label %22

20:                                               ; preds = %.lr.ph
  store i8 0, ptr %8, align 16, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %4)
  br label %22

22:                                               ; preds = %20, %.lr.ph
  %.1 = phi i16 [ 0, %20 ], [ %18, %.lr.ph ]
  %.not15 = icmp eq i16 %9, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %22
  %23 = zext i16 %.1 to i64
  %24 = getelementptr inbounds [17 x i8], ptr %4, i64 0, i64 %23
  store i8 0, ptr %24, align 1, !tbaa !5
  %25 = icmp ult i16 %.1, 16
  br i1 %25, label %.lr.ph22.preheader, label %._crit_edge23

.lr.ph22.preheader:                               ; preds = %._crit_edge.thread, %._crit_edge
  %.220.ph = phi i16 [ %.1, %._crit_edge ], [ 0, %._crit_edge.thread ]
  br label %.lr.ph22

.lr.ph22:                                         ; preds = %.lr.ph22.preheader, %.lr.ph22
  %.220 = phi i16 [ %26, %.lr.ph22 ], [ %.220.ph, %.lr.ph22.preheader ]
  %26 = add i16 %.220, 1
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %exitcond.not = icmp eq i16 %26, 16
  br i1 %exitcond.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !10

._crit_edge23:                                    ; preds = %.lr.ph22, %._crit_edge
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 17, ptr nonnull %4) #4
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isprint(i32 noundef) local_unnamed_addr #3

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

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass