; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (elf)

; 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_Ehdr = type { [16 x i8], i16, i16, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16 }

@.str.8 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [22 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

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

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

declare void @rewind(ptr noundef) #1

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @printfElf32_Message(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.Elf32_Ehdr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  call void @rewind(ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 52, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i64 @fread(ptr noundef %3, i64 noundef 52, i64 noundef 1, ptr noundef %5)
  %7 = icmp eq i64 1, %6
  br i1 %7, label %8, label %41

8:                                                ; preds = %1
  call void @printfElf32_EhdrMessage(ptr noundef byval(%struct.Elf32_Ehdr) align 8 %3)
  %9 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 10
  %10 = load i16, ptr %9, align 4, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = icmp eq i32 0, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %23

15:                                               ; preds = %8
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 5
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 10
  %21 = load i16, ptr %20, align 4, !tbaa !9
  %22 = zext i16 %21 to i32
  call void @printfElf32_PhdrMessage(ptr noundef %17, i32 noundef %19, i32 noundef %22)
  br label %23

23:                                               ; preds = %15, %13
  %24 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 12
  %25 = load i16, ptr %24, align 4, !tbaa !14
  %26 = zext i16 %25 to i32
  %27 = icmp eq i32 0, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  br label %40

30:                                               ; preds = %23
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 12
  %36 = load i16, ptr %35, align 4, !tbaa !14
  %37 = zext i16 %36 to i32
  %38 = getelementptr inbounds %struct.Elf32_Ehdr, ptr %3, i32 0, i32 13
  %39 = load i16, ptr %38, align 2, !tbaa !16
  call void @printfElf32_ShdrMessage(ptr noundef %32, i32 noundef %34, i32 noundef %37, i16 noundef zeroext %39)
  br label %40

40:                                               ; preds = %30, %28
  br label %43

41:                                               ; preds = %1
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  br label %43

43:                                               ; preds = %41, %40
  call void @llvm.lifetime.end.p0(i64 52, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_EhdrMessage(ptr noundef byval(%struct.Elf32_Ehdr) align 8) #2

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_PhdrMessage(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_ShdrMessage(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !11, i64 44}
!10 = !{!"", !7, i64 0, !11, i64 16, !11, i64 18, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !11, i64 42, !11, i64 44, !11, i64 46, !11, i64 48, !11, i64 50}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 28}
!14 = !{!10, !11, i64 48}
!15 = !{!10, !12, i64 32}
!16 = !{!10, !11, i64 50}


; 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_Ehdr = type { [16 x i8], i16, i16, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16 }

@.str.8 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [22 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @printfElf32_Message(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.Elf32_Ehdr, align 8
  tail call void @rewind(ptr noundef %0)
  call void @llvm.lifetime.start.p0(i64 52, ptr nonnull %2) #3
  %3 = call i64 @fread(ptr noundef nonnull %2, i64 noundef 52, i64 noundef 1, ptr noundef %0)
  %4 = icmp eq i64 %3, 1
  br i1 %4, label %5, label %29

5:                                                ; preds = %1
  tail call void @printfElf32_EhdrMessage(ptr noundef nonnull byval(%struct.Elf32_Ehdr) align 8 %2)
  %6 = getelementptr inbounds i8, ptr %2, i64 44
  %7 = load i16, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i16 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %16

11:                                               ; preds = %5
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %13 = getelementptr inbounds i8, ptr %2, i64 28
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = zext i16 %7 to i32
  tail call void @printfElf32_PhdrMessage(ptr noundef %0, i32 noundef %14, i32 noundef %15)
  br label %16

16:                                               ; preds = %11, %9
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  %18 = load i16, ptr %17, align 8, !tbaa !12
  %19 = icmp eq i16 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %31

22:                                               ; preds = %16
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %24 = getelementptr inbounds i8, ptr %2, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = zext i16 %18 to i32
  %27 = getelementptr inbounds i8, ptr %2, i64 50
  %28 = load i16, ptr %27, align 2, !tbaa !14
  tail call void @printfElf32_ShdrMessage(ptr noundef %0, i32 noundef %25, i32 noundef %26, i16 noundef zeroext %28)
  br label %31

29:                                               ; preds = %1
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  br label %31

31:                                               ; preds = %20, %22, %29
  call void @llvm.lifetime.end.p0(i64 52, ptr nonnull %2) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_EhdrMessage(ptr noundef byval(%struct.Elf32_Ehdr) align 8) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_PhdrMessage(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @printfElf32_ShdrMessage(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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, !9, i64 44}
!6 = !{!"", !7, i64 0, !9, i64 16, !9, i64 18, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !9, i64 40, !9, i64 42, !9, i64 44, !9, i64 46, !9, i64 48, !9, i64 50}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!6, !9, i64 48}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !9, i64 50}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass