; LLVM IR from docsteer/sacnview :: libs/WinPcap-413-173-b4/Examples-pcap/readfile_ex (readfile_ex)

; 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.pcap_pkthdr = type { %struct.timeval, i32, i32 }
%struct.timeval = type { i64, i64 }

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [256 x i8], align 16
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 256, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 2
  br i1 %14, label %15, label %20

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %18)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %87

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %21, i64 1
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds [256 x i8], ptr %7, i64 0, i64 0
  %25 = call ptr @pcap_open_offline(ptr noundef %23, ptr noundef %24)
  store ptr %25, ptr %6, align 8, !tbaa !9
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %33

27:                                               ; preds = %20
  %28 = load ptr, ptr @stderr, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds ptr, ptr %29, i64 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.1, ptr noundef %31) #4
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %87

33:                                               ; preds = %20
  br label %34

34:                                               ; preds = %76, %33
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = call i32 @pcap_next_ex(ptr noundef %35, ptr noundef %8, ptr noundef %9)
  store i32 %36, ptr %11, align 4, !tbaa !5
  %37 = icmp sge i32 %36, 0
  br i1 %37, label %38, label %78

38:                                               ; preds = %34
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.pcap_pkthdr, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %struct.timeval, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.pcap_pkthdr, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.timeval, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.pcap_pkthdr, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %42, i64 noundef %46, i32 noundef %49)
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %73, %38
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.pcap_pkthdr, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = add i32 %55, 1
  %57 = icmp ult i32 %52, %56
  br i1 %57, label %58, label %76

58:                                               ; preds = %51
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = sub i32 %60, 1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %59, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !18
  %65 = zext i8 %64 to i32
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %65)
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = urem i32 %67, 16
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %58
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %72

72:                                               ; preds = %70, %58
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = add i32 %74, 1
  store i32 %75, ptr %10, align 4, !tbaa !5
  br label %51, !llvm.loop !19

76:                                               ; preds = %51
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %34, !llvm.loop !21

78:                                               ; preds = %34
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = icmp eq i32 %79, -1
  br i1 %80, label %81, label %85

81:                                               ; preds = %78
  %82 = load ptr, ptr %6, align 8, !tbaa !9
  %83 = call ptr @pcap_geterr(ptr noundef %82)
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %83)
  br label %85

85:                                               ; preds = %81, %78
  %86 = load ptr, ptr %6, align 8, !tbaa !9
  call void @pcap_close(ptr noundef %86)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %87

87:                                               ; preds = %85, %27, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

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

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

declare ptr @pcap_open_offline(ptr noundef, ptr noundef) #2

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

declare i32 @pcap_next_ex(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @pcap_geterr(ptr noundef) #2

declare void @pcap_close(ptr noundef) #2

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

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 = { "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 "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !14, i64 0}
!12 = !{!"pcap_pkthdr", !13, i64 0, !6, i64 16, !6, i64 20}
!13 = !{!"timeval", !14, i64 0, !14, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !14, i64 8}
!16 = !{!12, !6, i64 20}
!17 = !{!12, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [256 x i8], align 16
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %9, label %6

6:                                                ; preds = %2
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %7)
  br label %57

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = call ptr @pcap_open_offline(ptr noundef %11, ptr noundef nonnull %3) #4
  %13 = icmp eq ptr %12, null
  br i1 %13, label %16, label %.preheader

.preheader:                                       ; preds = %9
  %14 = call i32 @pcap_next_ex(ptr noundef nonnull %12, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %.lr.ph15, label %._crit_edge16

16:                                               ; preds = %9
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.1, ptr noundef %18) #5
  br label %57

.lr.ph15:                                         ; preds = %.preheader, %._crit_edge
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %20, i64 20
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %21, i64 noundef %23, i32 noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = add i32 %29, -1
  %31 = icmp ult i32 %30, -2
  br i1 %31, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph15, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 1, %.lr.ph15 ]
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr i8, ptr %32, i64 %indvars.iv
  %34 = getelementptr i8, ptr %33, i64 -1
  %35 = load i8, ptr %34, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %36)
  %38 = and i64 %indvars.iv, 15
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %.lr.ph
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %42

42:                                               ; preds = %.lr.ph, %40
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 16
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = add i32 %45, 1
  %47 = zext i32 %46 to i64
  %48 = icmp ult i64 %indvars.iv.next, %47
  br i1 %48, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %42, %.lr.ph15
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %50 = call i32 @pcap_next_ex(ptr noundef nonnull %12, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %51 = icmp sgt i32 %50, -1
  br i1 %51, label %.lr.ph15, label %._crit_edge16, !llvm.loop !20

._crit_edge16:                                    ; preds = %._crit_edge, %.preheader
  %.lcssa = phi i32 [ %14, %.preheader ], [ %50, %._crit_edge ]
  %52 = icmp eq i32 %.lcssa, -1
  br i1 %52, label %53, label %56

53:                                               ; preds = %._crit_edge16
  %54 = call ptr @pcap_geterr(ptr noundef nonnull %12) #4
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %54)
  br label %56

56:                                               ; preds = %53, %._crit_edge16
  call void @pcap_close(ptr noundef nonnull %12) #4
  br label %57

57:                                               ; preds = %56, %16, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %16 ], [ 0, %56 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #4
  ret i32 %.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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @pcap_open_offline(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @pcap_next_ex(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @pcap_geterr(ptr noundef) local_unnamed_addr #3

declare void @pcap_close(ptr noundef) local_unnamed_addr #3

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

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 = { 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 #3 = { "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 = { nounwind }
attributes #5 = { cold 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, !12, i64 0}
!10 = !{!"pcap_pkthdr", !11, i64 0, !13, i64 16, !13, i64 20}
!11 = !{!"timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !12, i64 8}
!15 = !{!10, !13, i64 20}
!16 = !{!10, !13, i64 16}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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