; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources (dhdebug)

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

@__const.dhdebug_dump.address = external hidden unnamed_addr constant [9 x i8], align 1
@dhdebug_dump.str = external hidden constant [24 x i8], align 4
@dhdebug_dump.str.1 = external hidden constant [12 x i8], align 4

; Function Attrs: nounwind uwtable
declare dso_local void @dhdebug_ram(ptr noundef, ...) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @dhdebug_dump(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca [9 x i8], align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %129

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  store i8 16, ptr %5, align 1, !tbaa !11
  %15 = call ptr @llvm.stacksave.p0()
  store ptr %15, ptr %6, align 8
  %16 = alloca i8, i64 17, align 16
  %17 = alloca i8, i64 49, align 16
  call void @llvm.lifetime.start.p0(i64 9, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 @__const.dhdebug_dump.address, i64 9, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i32
  %21 = load i32, ptr %4, align 4, !tbaa !9
  call void (ptr, ...) @dhdebug_ram(ptr noundef @dhdebug_dump.str, i32 noundef %20, i32 noundef %21)
  br label %22

22:                                               ; preds = %18
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %123, %23
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sdiv i32 %25, 16777216
  %27 = and i32 %26, 255
  %28 = trunc i32 %27 to i8
  %29 = getelementptr inbounds [9 x i8], ptr %7, i64 0, i64 0
  %30 = call i32 @byteToHex(i8 noundef zeroext %28, ptr noundef %29)
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sdiv i32 %31, 65536
  %33 = and i32 %32, 255
  %34 = trunc i32 %33 to i8
  %35 = getelementptr inbounds [9 x i8], ptr %7, i64 0, i64 2
  %36 = call i32 @byteToHex(i8 noundef zeroext %34, ptr noundef %35)
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sdiv i32 %37, 256
  %39 = and i32 %38, 255
  %40 = trunc i32 %39 to i8
  %41 = getelementptr inbounds [9 x i8], ptr %7, i64 0, i64 4
  %42 = call i32 @byteToHex(i8 noundef zeroext %40, ptr noundef %41)
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = and i32 %43, 255
  %45 = trunc i32 %44 to i8
  %46 = getelementptr inbounds [9 x i8], ptr %7, i64 0, i64 6
  %47 = call i32 @byteToHex(i8 noundef zeroext %45, ptr noundef %46)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %115, %24
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = icmp ult i32 %49, 16
  br i1 %50, label %51, label %118

51:                                               ; preds = %48
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = icmp ult i32 %52, %53
  br i1 %54, label %55, label %94

55:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !9
  %59 = sext i32 %57 to i64
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  store i8 %61, ptr %10, align 1, !tbaa !11
  %62 = load i8, ptr %10, align 1, !tbaa !11
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = mul i32 %63, 3
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %17, i64 %65
  %67 = call i32 @byteToHex(i8 noundef zeroext %62, ptr noundef %66)
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = mul i32 %68, 3
  %70 = add i32 %69, 2
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %17, i64 %71
  store i8 32, ptr %72, align 1, !tbaa !11
  %73 = load i8, ptr %10, align 1, !tbaa !11
  %74 = sext i8 %73 to i32
  %75 = icmp slt i32 %74, 32
  br i1 %75, label %80, label %76

76:                                               ; preds = %55
  %77 = load i8, ptr %10, align 1, !tbaa !11
  %78 = sext i8 %77 to i32
  %79 = icmp sge i32 %78, 127
  br i1 %79, label %80, label %84

80:                                               ; preds = %76, %55
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %16, i64 %82
  store i8 46, ptr %83, align 1, !tbaa !11
  br label %89

84:                                               ; preds = %76
  %85 = load i8, ptr %10, align 1, !tbaa !11
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %16, i64 %87
  store i8 %85, ptr %88, align 1, !tbaa !11
  br label %89

89:                                               ; preds = %84, %80
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = add i32 %90, 1
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %16, i64 %92
  store i8 0, ptr %93, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %109

94:                                               ; preds = %51
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = mul i32 %95, 3
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %17, i64 %97
  store i8 32, ptr %98, align 1, !tbaa !11
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = mul i32 %99, 3
  %101 = add i32 %100, 1
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds i8, ptr %17, i64 %102
  store i8 32, ptr %103, align 1, !tbaa !11
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = mul i32 %104, 3
  %106 = add i32 %105, 2
  %107 = zext i32 %106 to i64
  %108 = getelementptr inbounds i8, ptr %17, i64 %107
  store i8 32, ptr %108, align 1, !tbaa !11
  br label %109

109:                                              ; preds = %94, %89
  %110 = load i32, ptr %9, align 4, !tbaa !9
  %111 = mul i32 %110, 3
  %112 = add i32 %111, 3
  %113 = zext i32 %112 to i64
  %114 = getelementptr inbounds i8, ptr %17, i64 %113
  store i8 0, ptr %114, align 1, !tbaa !11
  br label %115

115:                                              ; preds = %109
  %116 = load i32, ptr %9, align 4, !tbaa !9
  %117 = add i32 %116, 1
  store i32 %117, ptr %9, align 4, !tbaa !9
  br label %48, !llvm.loop !12

118:                                              ; preds = %48
  br label %119

119:                                              ; preds = %118
  %120 = getelementptr inbounds [9 x i8], ptr %7, i64 0, i64 0
  call void (ptr, ...) @dhdebug_ram(ptr noundef @dhdebug_dump.str.1, ptr noundef %120, ptr noundef %17, ptr noundef %16)
  br label %121

121:                                              ; preds = %119
  br label %122

122:                                              ; preds = %121
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %8, align 4, !tbaa !9
  %125 = load i32, ptr %4, align 4, !tbaa !9
  %126 = icmp ult i32 %124, %125
  br i1 %126, label %24, label %127, !llvm.loop !14

127:                                              ; preds = %123
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 9, ptr %7) #5
  %128 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %128)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  br label %129

129:                                              ; preds = %127, %13
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i32 @byteToHex(i8 noundef zeroext, ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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

!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 = !{!"int", !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"

@__const.dhdebug_dump.address = external hidden unnamed_addr constant [9 x i8], align 1
@dhdebug_dump.str = external hidden constant [24 x i8], align 4
@dhdebug_dump.str.1 = external hidden constant [12 x i8], align 4

; Function Attrs: nounwind uwtable
declare dso_local void @dhdebug_ram(ptr noundef, ...) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @dhdebug_dump(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [9 x i8], align 1
  %4 = icmp eq i32 %1, 0
  br i1 %4, label %48, label %5

5:                                                ; preds = %2
  %6 = tail call ptr @llvm.stacksave.p0()
  %7 = alloca [17 x i8], align 16
  %8 = alloca [49 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %3, ptr noundef nonnull align 1 dereferenceable(9) @__const.dhdebug_dump.address, i64 9, i1 false)
  %9 = ptrtoint ptr %0 to i64
  %10 = trunc i64 %9 to i32
  tail call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @dhdebug_dump.str, i32 noundef %10, i32 noundef %1)
  %11 = getelementptr inbounds i8, ptr %3, i64 2
  %12 = getelementptr inbounds i8, ptr %3, i64 4
  %13 = getelementptr inbounds i8, ptr %3, i64 6
  %invariant.gep = getelementptr inbounds i8, ptr %7, i64 1
  %invariant.gep32 = getelementptr inbounds i8, ptr %8, i64 3
  br label %14

14:                                               ; preds = %45, %5
  %.0 = phi i32 [ 0, %5 ], [ %.2, %45 ]
  %15 = sdiv i32 %.0, 16777216
  %16 = trunc nsw i32 %15 to i8
  %17 = call i32 @byteToHex(i8 noundef zeroext %16, ptr noundef nonnull %3) #5
  %18 = sdiv i32 %.0, 65536
  %19 = trunc i32 %18 to i8
  %20 = call i32 @byteToHex(i8 noundef zeroext %19, ptr noundef nonnull %11) #5
  %21 = sdiv i32 %.0, 256
  %22 = trunc i32 %21 to i8
  %23 = call i32 @byteToHex(i8 noundef zeroext %22, ptr noundef nonnull %12) #5
  %24 = trunc i32 %.0 to i8
  %25 = call i32 @byteToHex(i8 noundef zeroext %24, ptr noundef nonnull %13) #5
  br label %26

26:                                               ; preds = %14, %44
  %indvars.iv = phi i64 [ 0, %14 ], [ %indvars.iv.next, %44 ]
  %.135 = phi i32 [ %.0, %14 ], [ %.2, %44 ]
  %27 = icmp ult i32 %.135, %1
  br i1 %27, label %28, label %39

28:                                               ; preds = %26
  %29 = add nuw nsw i32 %.135, 1
  %30 = sext i32 %.135 to i64
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = mul nuw nsw i64 %indvars.iv, 3
  %34 = getelementptr inbounds i8, ptr %8, i64 %33
  %35 = call i32 @byteToHex(i8 noundef zeroext %32, ptr noundef nonnull %34) #5
  %36 = getelementptr inbounds i8, ptr %34, i64 2
  store i8 32, ptr %36, align 1, !tbaa !5
  %37 = add i8 %32, -127
  %or.cond = icmp ult i8 %37, -95
  %spec.select = select i1 %or.cond, i8 46, i8 %32
  %38 = getelementptr inbounds i8, ptr %7, i64 %indvars.iv
  store i8 %spec.select, ptr %38, align 1
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv
  store i8 0, ptr %gep, align 1, !tbaa !5
  br label %44

39:                                               ; preds = %26
  %40 = mul nuw nsw i64 %indvars.iv, 3
  %41 = getelementptr inbounds i8, ptr %8, i64 %40
  store i8 32, ptr %41, align 1, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  store i8 32, ptr %42, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %41, i64 2
  store i8 32, ptr %43, align 1, !tbaa !5
  br label %44

44:                                               ; preds = %39, %28
  %.pre-phi = phi i64 [ %40, %39 ], [ %33, %28 ]
  %.2 = phi i32 [ %.135, %39 ], [ %29, %28 ]
  %gep33 = getelementptr inbounds i8, ptr %invariant.gep32, i64 %.pre-phi
  store i8 0, ptr %gep33, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16
  br i1 %exitcond.not, label %45, label %26, !llvm.loop !8

45:                                               ; preds = %44
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @dhdebug_dump.str.1, ptr noundef nonnull %3, ptr noundef nonnull %8, ptr noundef nonnull %7)
  %46 = icmp ult i32 %.2, %1
  br i1 %46, label %14, label %47, !llvm.loop !10

47:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %3) #5
  call void @llvm.stackrestore.p0(ptr %6)
  br label %48

48:                                               ; preds = %2, %47
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i32 @byteToHex(i8 noundef zeroext, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass