; LLVM IR from holzschu/ios_system :: shell_cmds/hexdump (display)

; 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._pr = type { ptr, i32, i32, ptr, ptr, ptr, i32, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }

@bpad.spec = external hidden global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @bpad(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._pr, ptr %5, i32 0, i32 1
  store i32 2, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._pr, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 0
  store i8 115, ptr %10, align 1, !tbaa !14
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._pr, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  store i8 0, ptr %14, align 1, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._pr, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  store ptr %17, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %24, %1
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !14
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, 37
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %3, align 8, !tbaa !5
  br label %18, !llvm.loop !16

27:                                               ; preds = %18
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i32 1
  store ptr %29, ptr %3, align 8, !tbaa !5
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %45, %27
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !14
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %30
  %36 = load ptr, ptr @bpad.spec, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !14
  %39 = sext i8 %38 to i32
  %40 = call ptr @index(ptr noundef %36, i32 noundef %39) #4
  %41 = icmp ne ptr %40, null
  br label %42

42:                                               ; preds = %35, %30
  %43 = phi i1 [ false, %30 ], [ %41, %35 ]
  br i1 %43, label %44, label %48

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %3, align 8, !tbaa !5
  br label %30, !llvm.loop !18

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %56, %48
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %3, align 8, !tbaa !5
  %52 = load i8, ptr %50, align 1, !tbaa !14
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %4, align 8, !tbaa !5
  store i8 %52, ptr %53, align 1, !tbaa !14
  %55 = icmp ne i8 %52, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  br label %49, !llvm.loop !19

57:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @index(ptr noundef, i32 noundef) #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 = { 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 #3 = { nounwind }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_pr", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !12, i64 44}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !11, i64 0, !7, i64 4}
!13 = !{!10, !6, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


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

@bpad.spec = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: read) uwtable
define dso_local void @bpad(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 2, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !12
  store i8 115, ptr %4, align 1, !tbaa !13
  %5 = load ptr, ptr %3, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 0, ptr %6, align 1, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  br label %9

9:                                                ; preds = %9, %1
  %.012 = phi ptr [ %8, %1 ], [ %11, %9 ]
  %10 = load i8, ptr %.012, align 1, !tbaa !13
  %.not = icmp eq i8 %10, 37
  %11 = getelementptr inbounds i8, ptr %.012, i64 1
  br i1 %.not, label %12, label %9, !llvm.loop !15

12:                                               ; preds = %9
  %13 = load i8, ptr %11, align 1, !tbaa !13
  %.not1417 = icmp eq i8 %13, 0
  br i1 %.not1417, label %.critedge.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %14 = load ptr, ptr @bpad.spec, align 8, !tbaa !17
  br label %15

15:                                               ; preds = %.lr.ph, %19
  %16 = phi i8 [ %13, %.lr.ph ], [ %21, %19 ]
  %.118 = phi ptr [ %11, %.lr.ph ], [ %20, %19 ]
  %17 = sext i8 %16 to i32
  %18 = tail call ptr @index(ptr noundef %14, i32 noundef %17) #2
  %.not15 = icmp eq ptr %18, null
  br i1 %.not15, label %.critedge.preheader, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %.118, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %.not14 = icmp eq i8 %21, 0
  br i1 %.not14, label %.critedge.preheader, label %15, !llvm.loop !18

.critedge.preheader:                              ; preds = %15, %19, %12
  %.2.ph = phi ptr [ %11, %12 ], [ %.118, %15 ], [ %20, %19 ]
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %.critedge
  %.2 = phi ptr [ %22, %.critedge ], [ %.2.ph, %.critedge.preheader ]
  %.0 = phi ptr [ %24, %.critedge ], [ %11, %.critedge.preheader ]
  %22 = getelementptr inbounds i8, ptr %.2, i64 1
  %23 = load i8, ptr %.2, align 1, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %.0, i64 1
  store i8 %23, ptr %.0, align 1, !tbaa !13
  %.not16 = icmp eq i8 %23, 0
  br i1 %.not16, label %25, label %.critedge, !llvm.loop !19

25:                                               ; preds = %.critedge
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare ptr @index(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: read) 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 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 #2 = { 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, !10, i64 8}
!6 = !{!"_pr", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !11, i64 44}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !10, i64 0, !8, i64 4}
!12 = !{!6, !7, i64 16}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !7, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


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