; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/elf (parseElf)

; 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.Elf32_Shdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @print_sec_header(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %116, %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %119

13:                                               ; preds = %9
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %14)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct.Elf32_Shdr, ptr %17, i64 %19
  %21 = getelementptr inbounds %struct.Elf32_Shdr, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %16, i64 %23
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, ptr noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.Elf32_Shdr, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.Elf32_Shdr, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  switch i32 %31, label %58 [
    i32 0, label %32
    i32 1, label %34
    i32 2, label %36
    i32 3, label %38
    i32 4, label %40
    i32 5, label %42
    i32 6, label %44
    i32 7, label %46
    i32 8, label %48
    i32 9, label %50
    i32 10, label %52
    i32 11, label %54
  ]

32:                                               ; preds = %13
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.16)
  br label %58

34:                                               ; preds = %13
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.17)
  br label %58

36:                                               ; preds = %13
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.18)
  br label %58

38:                                               ; preds = %13
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.19)
  br label %58

40:                                               ; preds = %13
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.20)
  br label %58

42:                                               ; preds = %13
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.21)
  br label %58

44:                                               ; preds = %13
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.22)
  br label %58

46:                                               ; preds = %13
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.23)
  br label %58

48:                                               ; preds = %13
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.24)
  br label %58

50:                                               ; preds = %13
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.25)
  br label %58

52:                                               ; preds = %13
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.26)
  br label %58

54:                                               ; preds = %13
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.27)
  br label %58

56:                                               ; No predecessors!
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, ptr noundef @.str.28)
  br label %58

58:                                               ; preds = %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36, %34, %32, %13
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.Elf32_Shdr, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.Elf32_Shdr, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 4, !tbaa !14
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.29, i32 noundef %64)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.Elf32_Shdr, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.Elf32_Shdr, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %70, align 4, !tbaa !15
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.30, i32 noundef %71)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds %struct.Elf32_Shdr, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.Elf32_Shdr, ptr %76, i32 0, i32 5
  %78 = load i32, ptr %77, align 4, !tbaa !16
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.31, i32 noundef %78)
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.32)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds %struct.Elf32_Shdr, ptr %81, i64 %83
  %85 = getelementptr inbounds %struct.Elf32_Shdr, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 4, !tbaa !17
  %87 = and i32 %86, 1
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %91

89:                                               ; preds = %58
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.33)
  br label %91

91:                                               ; preds = %89, %58
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = load i32, ptr %7, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds %struct.Elf32_Shdr, ptr %92, i64 %94
  %96 = getelementptr inbounds %struct.Elf32_Shdr, ptr %95, i32 0, i32 2
  %97 = load i32, ptr %96, align 4, !tbaa !17
  %98 = and i32 %97, 2
  %99 = icmp ne i32 %98, 0
  br i1 %99, label %100, label %102

100:                                              ; preds = %91
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.34)
  br label %102

102:                                              ; preds = %100, %91
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %7, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds %struct.Elf32_Shdr, ptr %103, i64 %105
  %107 = getelementptr inbounds %struct.Elf32_Shdr, ptr %106, i32 0, i32 2
  %108 = load i32, ptr %107, align 4, !tbaa !17
  %109 = and i32 %108, 4
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %113

111:                                              ; preds = %102
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.35)
  br label %113

113:                                              ; preds = %111, %102
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  %115 = call i32 (ptr, ...) @printf(ptr noundef @.str.37)
  br label %116

116:                                              ; preds = %113
  %117 = load i32, ptr %7, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !18

119:                                              ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

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

attributes #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 12}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !10, i64 20}
!17 = !{!12, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.Elf32_Shdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [2 x i8], align 1
@switch.table.print_sec_header = private unnamed_addr constant [12 x ptr] [ptr @.str.16, ptr @.str.17, ptr @.str.18, ptr @.str.19, ptr @.str.20, ptr @.str.21, ptr @.str.22, ptr @.str.23, ptr @.str.24, ptr @.str.25, ptr @.str.26, ptr @.str.27], align 8

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @print_sec_header(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %44
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %44 ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %6)
  %8 = getelementptr inbounds %struct.Elf32_Shdr, ptr %0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %2, i64 %10
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, ptr noundef %11)
  %13 = getelementptr inbounds i8, ptr %8, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = icmp ult i32 %14, 12
  br i1 %15, label %switch.lookup, label %18

switch.lookup:                                    ; preds = %.lr.ph
  %16 = zext nneg i32 %14 to i64
  %switch.gep = getelementptr inbounds [12 x ptr], ptr @switch.table.print_sec_header, i64 0, i64 %16
  %switch.load = load ptr, ptr %switch.gep, align 8
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15, ptr noundef nonnull %switch.load)
  br label %18

18:                                               ; preds = %.lr.ph, %switch.lookup
  %19 = getelementptr inbounds i8, ptr %8, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.29, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %8, i64 16
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30, i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %8, i64 20
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31, i32 noundef %26)
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32)
  %29 = getelementptr inbounds i8, ptr %8, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = and i32 %30, 1
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %34, label %32

32:                                               ; preds = %18
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33)
  %.pre = load i32, ptr %29, align 4, !tbaa !14
  br label %34

34:                                               ; preds = %32, %18
  %35 = phi i32 [ %.pre, %32 ], [ %30, %18 ]
  %36 = and i32 %35, 2
  %.not20 = icmp eq i32 %36, 0
  br i1 %.not20, label %39, label %37

37:                                               ; preds = %34
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34)
  %.pre24 = load i32, ptr %29, align 4, !tbaa !14
  br label %39

39:                                               ; preds = %37, %34
  %40 = phi i32 [ %.pre24, %37 ], [ %35, %34 ]
  %41 = and i32 %40, 4
  %.not21 = icmp eq i32 %41, 0
  br i1 %.not21, label %44, label %42

42:                                               ; preds = %39
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.35)
  br label %44

44:                                               ; preds = %42, %39
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36)
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.37)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %44, %3
  ret void
}

attributes #0 = { 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 #1 = { 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" }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 12}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 20}
!14 = !{!6, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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