; LLVM IR from tomoyasuzuki/kvmm :: blk (create_blk)

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

@blk = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @create_blk() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %7, ptr @blk, align 8, !tbaa !5
  %8 = call noalias ptr @malloc(i64 noundef 512000000) #4
  %9 = load ptr, ptr @blk, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.blk, ptr %9, i32 0, i32 0
  store ptr %8, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr @blk, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.blk, ptr %11, i32 0, i32 1
  store i8 0, ptr %12, align 8, !tbaa !12
  %13 = load ptr, ptr @blk, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.blk, ptr %13, i32 0, i32 6
  store i8 0, ptr %14, align 1, !tbaa !13
  %15 = load ptr, ptr @blk, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.blk, ptr %15, i32 0, i32 5
  store i8 0, ptr %16, align 4, !tbaa !14
  %17 = load ptr, ptr @blk, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.blk, ptr %17, i32 0, i32 4
  store i8 0, ptr %18, align 1, !tbaa !15
  %19 = load ptr, ptr @blk, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.blk, ptr %19, i32 0, i32 3
  store i8 0, ptr %20, align 2, !tbaa !16
  %21 = load ptr, ptr @blk, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.blk, ptr %21, i32 0, i32 2
  store i8 0, ptr %22, align 1, !tbaa !17
  %23 = load ptr, ptr @blk, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.blk, ptr %23, i32 0, i32 7
  store i8 64, ptr %24, align 2, !tbaa !18
  %25 = load ptr, ptr @blk, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.blk, ptr %25, i32 0, i32 9
  store i8 0, ptr %26, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  %27 = call i32 (ptr, i32, ...) @open(ptr noundef @.str, i32 noundef 0)
  store i32 %27, ptr %1, align 4, !tbaa !20
  %28 = load i32, ptr %1, align 4, !tbaa !20
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %0
  call void @error(ptr noundef @.str.1)
  br label %31

31:                                               ; preds = %30, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %32 = load ptr, ptr @blk, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.blk, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  store ptr %34, ptr %2, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %50, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %36 = load i32, ptr %1, align 4, !tbaa !20
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = call i64 @read(i32 noundef %36, ptr noundef %37, i64 noundef 5120000)
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %3, align 4, !tbaa !20
  %40 = load i32, ptr %3, align 4, !tbaa !20
  %41 = icmp sle i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i32 2, ptr %4, align 4
  br label %48

43:                                               ; preds = %35
  %44 = load i32, ptr %3, align 4, !tbaa !20
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  store ptr %47, ptr %2, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %48

48:                                               ; preds = %43, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  %49 = load i32, ptr %4, align 4
  switch i32 %49, label %78 [
    i32 0, label %50
    i32 2, label %51
  ]

50:                                               ; preds = %48
  br label %35

51:                                               ; preds = %48
  %52 = load ptr, ptr @blk, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.blk, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %54, i64 5120000
  store ptr %55, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %56 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.2, i32 noundef 0)
  store i32 %56, ptr %5, align 4, !tbaa !20
  %57 = load i32, ptr %5, align 4, !tbaa !20
  %58 = icmp slt i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %51
  call void @error(ptr noundef @.str.3)
  br label %60

60:                                               ; preds = %59, %51
  br label %61

61:                                               ; preds = %76, %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %62 = load i32, ptr %5, align 4, !tbaa !20
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = call i64 @read(i32 noundef %62, ptr noundef %63, i64 noundef 512000)
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %6, align 4, !tbaa !20
  %66 = load i32, ptr %6, align 4, !tbaa !20
  %67 = icmp sle i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %61
  store i32 4, ptr %4, align 4
  br label %74

69:                                               ; preds = %61
  %70 = load i32, ptr %6, align 4, !tbaa !20
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = sext i32 %70 to i64
  %73 = getelementptr inbounds i8, ptr %71, i64 %72
  store ptr %73, ptr %2, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %74

74:                                               ; preds = %69, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %75 = load i32, ptr %4, align 4
  switch i32 %75, label %78 [
    i32 0, label %76
    i32 4, label %77
  ]

76:                                               ; preds = %74
  br label %61

77:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void

78:                                               ; preds = %74, %48
  unreachable
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

declare i32 @open(ptr noundef, i32 noundef, ...) #3

declare void @error(ptr noundef) #3

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #3

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

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 = { nounwind allocsize(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 = { "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 allocsize(0) }
attributes #5 = { 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, !6, i64 0}
!10 = !{!"blk", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !11, i64 16, !7, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 8}
!13 = !{!10, !7, i64 13}
!14 = !{!10, !7, i64 12}
!15 = !{!10, !7, i64 11}
!16 = !{!10, !7, i64 10}
!17 = !{!10, !7, i64 9}
!18 = !{!10, !7, i64 14}
!19 = !{!10, !7, i64 20}
!20 = !{!11, !11, i64 0}


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

@blk = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @create_blk() local_unnamed_addr #0 {
  %1 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  store ptr %1, ptr @blk, align 8, !tbaa !5
  %2 = tail call noalias dereferenceable_or_null(512000000) ptr @malloc(i64 noundef 512000000) #5
  store ptr %2, ptr %1, align 8, !tbaa !9
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = getelementptr inbounds i8, ptr %1, i64 14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(6) %3, i8 0, i64 6, i1 false)
  store i8 64, ptr %4, align 2, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %1, i64 20
  store i8 0, ptr %5, align 4, !tbaa !13
  %6 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str, i32 noundef 0) #6
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  tail call void @error(ptr noundef nonnull @.str.1) #6
  br label %9

9:                                                ; preds = %8, %0
  %10 = load ptr, ptr @blk, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %12, %9
  %.0 = phi ptr [ %11, %9 ], [ %17, %12 ]
  %13 = tail call i64 @read(i32 noundef %6, ptr noundef %.0, i64 noundef 5120000) #6
  %14 = trunc i64 %13 to i32
  %15 = icmp slt i32 %14, 1
  %16 = and i64 %13, 2147483647
  %17 = getelementptr inbounds i8, ptr %.0, i64 %16
  br i1 %15, label %18, label %12

18:                                               ; preds = %12
  %19 = load ptr, ptr @blk, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %20, i64 5120000
  %22 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str.2, i32 noundef 0) #6
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %.preheader

24:                                               ; preds = %18
  tail call void @error(ptr noundef nonnull @.str.3) #6
  br label %.preheader

.preheader:                                       ; preds = %24, %18
  br label %25

25:                                               ; preds = %.preheader, %25
  %.2 = phi ptr [ %30, %25 ], [ %21, %.preheader ]
  %26 = tail call i64 @read(i32 noundef %22, ptr noundef %.2, i64 noundef 512000) #6
  %27 = trunc i64 %26 to i32
  %28 = icmp slt i32 %27, 1
  %29 = and i64 %26, 2147483647
  %30 = getelementptr inbounds i8, ptr %.2, i64 %29
  br i1 %28, label %31, label %25

31:                                               ; preds = %25
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

declare void @error(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"blk", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !11, i64 16, !7, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 14}
!13 = !{!10, !7, i64 20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass