; LLVM IR from gognl/VMBR :: victim/src/boot (mmap)

; 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.mmap_table_t = type <{ i32, [0 x %struct.mmap_entry_t] }>
%struct.mmap_entry_t = type { i64, i64, i32, i32 }

@.str = external hidden unnamed_addr constant [53 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @print_mmap() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr inttoptr (i64 20480 to ptr), ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.mmap_table_t, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 1, !tbaa !9
  store i32 %6, ptr %2, align 4, !tbaa !9
  %7 = load i32, ptr %2, align 4, !tbaa !9
  call void (ptr, ...) @LOG_DEBUG(ptr noundef @.str, i32 noundef %7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %57, %0
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %60

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mmap_table_t, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %16, i64 0, i64 %18
  call void (ptr, ...) @LOG_DEBUG(ptr noundef @.str.1, i32 noundef %14, ptr noundef %19)
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mmap_table_t, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %22, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.mmap_entry_t, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 1, !tbaa !11
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mmap_table_t, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %29, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.mmap_entry_t, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 1, !tbaa !14
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mmap_table_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %36, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.mmap_entry_t, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 1, !tbaa !15
  %42 = load ptr, ptr %1, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mmap_table_t, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %43, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.mmap_entry_t, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 1, !tbaa !11
  %49 = load ptr, ptr %1, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mmap_table_t, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %50, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.mmap_entry_t, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 1, !tbaa !14
  %56 = add i64 %48, %55
  call void (ptr, ...) @LOG_DEBUG(ptr noundef @.str.2, i32 noundef %20, i64 noundef %27, i64 noundef %34, i32 noundef %41, i64 noundef %56)
  br label %57

57:                                               ; preds = %13
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !16

60:                                               ; preds = %12
  call void (ptr, ...) @LOG_DEBUG(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

declare void @LOG_DEBUG(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 }

!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, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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.mmap_entry_t = type { i64, i64, i32, i32 }

@.str = external hidden unnamed_addr constant [53 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @print_mmap() local_unnamed_addr #0 {
  %1 = load i32, ptr inttoptr (i64 20480 to ptr), align 4096, !tbaa !5
  tail call void (ptr, ...) @LOG_DEBUG(ptr noundef nonnull @.str, i32 noundef %1) #2
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void (ptr, ...) @LOG_DEBUG(ptr noundef nonnull @.str.3) #2
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %2 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void (ptr, ...) @LOG_DEBUG(ptr noundef nonnull @.str.1, i32 noundef %3, ptr noundef nonnull %2) #2
  %4 = load i64, ptr %2, align 4, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  %6 = load i64, ptr %5, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = add i64 %6, %4
  tail call void (ptr, ...) @LOG_DEBUG(ptr noundef nonnull @.str.2, i32 noundef %3, i64 noundef %4, i64 noundef %6, i32 noundef %8, i64 noundef %9) #2
  %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 !14
}

declare void @LOG_DEBUG(ptr noundef, ...) local_unnamed_addr #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 = { "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 }

!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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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