; LLVM IR from wichue/nethello :: src/base/BackTrace.ll (ZN3chw16addr2line_formatEPvPcS1_i)

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

@_ZN3chw11_chw_binaryE = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3chw16addr2line_formatEPvPcS1_i(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca [512 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 512, ptr %10) #6
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 512, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %15 = getelementptr inbounds [512 x i8], ptr %10, i64 0, i64 0
  %16 = load ptr, ptr @_ZN3chw11_chw_binaryE, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 -1
  %19 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %15, i64 noundef 512, ptr noundef @.str.2, ptr noundef %16, ptr noundef %18) #6
  store i32 %19, ptr %11, align 4, !tbaa !9
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %4
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 512
  br i1 %24, label %25, label %27

25:                                               ; preds = %22, %4
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %26, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %99

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %28 = getelementptr inbounds [512 x i8], ptr %10, i64 0, i64 0
  %29 = call noalias ptr @popen(ptr noundef %28, ptr noundef @.str.3)
  store ptr %29, ptr %13, align 8, !tbaa !5
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %34, label %32

32:                                               ; preds = %27
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %33, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %98

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = call ptr @fgets(ptr noundef %35, i32 noundef %36, ptr noundef %37)
  store ptr %38, ptr %14, align 8, !tbaa !5
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = call i32 @pclose(ptr noundef %39)
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %34
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %44, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %97

45:                                               ; preds = %34
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = call i64 @strlen(ptr noundef %46) #7
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %11, align 4, !tbaa !9
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %45
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %51, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %97

52:                                               ; preds = %45
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !11
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 10
  br i1 %60, label %61, label %67

61:                                               ; preds = %52
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %62, i64 %65
  store i8 0, ptr %66, align 1, !tbaa !11
  br label %67

67:                                               ; preds = %61, %52
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %68, ptr %14, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %92, %67
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = getelementptr inbounds i8, ptr %74, i64 -1
  %76 = icmp ult ptr %70, %75
  br i1 %76, label %77, label %95

77:                                               ; preds = %69
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 0
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 63
  br i1 %82, label %83, label %91

83:                                               ; preds = %77
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 1
  %86 = load i8, ptr %85, align 1, !tbaa !11
  %87 = sext i8 %86 to i32
  %88 = icmp eq i32 %87, 63
  br i1 %88, label %89, label %91

89:                                               ; preds = %83
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %90, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %97

91:                                               ; preds = %83, %77
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %14, align 8, !tbaa !5
  %94 = getelementptr inbounds i8, ptr %93, i32 1
  store ptr %94, ptr %14, align 8, !tbaa !5
  br label %69, !llvm.loop !12

95:                                               ; preds = %69
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %96, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %97

97:                                               ; preds = %95, %89, %50, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %98

98:                                               ; preds = %97, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %99

99:                                               ; preds = %98, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 512, ptr %10) #6
  %100 = load ptr, ptr %5, align 8
  ret ptr %100
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

declare noalias ptr @popen(ptr noundef, ptr noundef) #4

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @pclose(ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@_ZN3chw11_chw_binaryE = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef ptr @_ZN3chw16addr2line_formatEPvPcS1_i(ptr noundef %0, ptr noundef readnone %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [512 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) %5, i8 0, i64 512, i1 false)
  %6 = load ptr, ptr @_ZN3chw11_chw_binaryE, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 -1
  %8 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %5, i64 noundef 512, ptr noundef nonnull @.str.2, ptr noundef %6, ptr noundef nonnull %7) #5
  %or.cond = icmp ugt i32 %8, 511
  br i1 %or.cond, label %.loopexit, label %9

9:                                                ; preds = %4
  %10 = call noalias ptr @popen(ptr noundef nonnull %5, ptr noundef nonnull @.str.3)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %.loopexit, label %11

11:                                               ; preds = %9
  %12 = tail call ptr @fgets(ptr noundef %2, i32 noundef %3, ptr noundef nonnull %10)
  %13 = tail call i32 @pclose(ptr noundef nonnull %10)
  %14 = icmp eq ptr %12, null
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %11
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %12) #6
  %17 = and i64 %16, 4294967295
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %15
  %20 = shl i64 %16, 32
  %sext = add i64 %20, -4294967296
  %21 = ashr exact i64 %sext, 32
  %22 = getelementptr inbounds i8, ptr %12, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = icmp eq i8 %23, 10
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  store i8 0, ptr %22, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %25, %19
  %27 = ashr exact i64 %20, 32
  %28 = getelementptr inbounds i8, ptr %2, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 -1
  %30 = icmp ugt ptr %29, %2
  br i1 %30, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %26, %37
  %.033 = phi ptr [ %38, %37 ], [ %2, %26 ]
  %31 = load i8, ptr %.033, align 1, !tbaa !9
  %32 = icmp eq i8 %31, 63
  br i1 %32, label %33, label %37

33:                                               ; preds = %.lr.ph
  %34 = getelementptr inbounds i8, ptr %.033, i64 1
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = icmp eq i8 %35, 63
  br i1 %36, label %.loopexit, label %37

37:                                               ; preds = %.lr.ph, %33
  %38 = getelementptr inbounds i8, ptr %.033, i64 1
  %exitcond.not = icmp eq ptr %38, %29
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %33, %37, %26, %9, %15, %11, %4
  %.2 = phi ptr [ %1, %4 ], [ %1, %9 ], [ %1, %11 ], [ %1, %15 ], [ %2, %26 ], [ %1, %33 ], [ %2, %37 ]
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %5) #5
  ret ptr %.2
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 willreturn memory(argmem: 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 #5 = { nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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