; LLVM IR from cornell-zhang/rosetta :: BNN/cpp/minizip (ioapi_mem)

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

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

; 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.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @fwrite_mem_func(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %12, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ourmemory_s, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ourmemory_s, ptr %17, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = sub i64 %16, %19
  %21 = icmp ugt i64 %13, %20
  br i1 %21, label %22, label %68

22:                                               ; preds = %4
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ourmemory_s, ptr %23, i32 0, i32 4
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %59

27:                                               ; preds = %22
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ourmemory_s, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !11
  store i64 %30, ptr %11, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp ult i64 %31, 65536
  br i1 %32, label %33, label %36

33:                                               ; preds = %27
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = add i64 %34, 65536
  store i64 %35, ptr %11, align 8, !tbaa !9
  br label %40

36:                                               ; preds = %27
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = add i64 %38, %37
  store i64 %39, ptr %11, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %36, %33
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = call noalias ptr @malloc(i64 noundef %41) #6
  store ptr %42, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ourmemory_s, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ourmemory_s, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %43, ptr align 1 %46, i64 %49, i1 false)
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ourmemory_s, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  call void @free(ptr noundef %52) #5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ourmemory_s, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !16
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ourmemory_s, ptr %57, i32 0, i32 1
  store i64 %56, ptr %58, align 8, !tbaa !11
  br label %67

59:                                               ; preds = %22
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ourmemory_s, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ourmemory_s, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !14
  %66 = sub i64 %62, %65
  store i64 %66, ptr %8, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %59, %40
  br label %68

68:                                               ; preds = %67, %4
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ourmemory_s, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ourmemory_s, ptr %72, i32 0, i32 3
  %74 = load i64, ptr %73, align 8, !tbaa !14
  %75 = getelementptr inbounds i8, ptr %71, i64 %74
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %75, ptr align 1 %76, i64 %77, i1 false)
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ourmemory_s, ptr %79, i32 0, i32 3
  %81 = load i64, ptr %80, align 8, !tbaa !14
  %82 = add i64 %81, %78
  store i64 %82, ptr %80, align 8, !tbaa !14
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ourmemory_s, ptr %83, i32 0, i32 3
  %85 = load i64, ptr %84, align 8, !tbaa !14
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.ourmemory_s, ptr %86, i32 0, i32 2
  %88 = load i64, ptr %87, align 8, !tbaa !17
  %89 = icmp ugt i64 %85, %88
  br i1 %89, label %90, label %96

90:                                               ; preds = %68
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.ourmemory_s, ptr %91, i32 0, i32 3
  %93 = load i64, ptr %92, align 8, !tbaa !14
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ourmemory_s, ptr %94, i32 0, i32 2
  store i64 %93, ptr %95, align 8, !tbaa !17
  br label %96

96:                                               ; preds = %90, %68
  %97 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret i64 %97
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"ourmemory_s", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !13, i64 32}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !10, i64 16}


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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local i64 @fwrite_mem_func(ptr nocapture noundef readnone %0, ptr nocapture noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = sub i64 %6, %8
  %10 = icmp ult i64 %9, %3
  br i1 %10, label %11, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.pre = load ptr, ptr %1, align 8, !tbaa !13
  br label %16

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %1, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %.not = icmp eq i32 %13, 0
  %.pre35 = load ptr, ptr %1, align 8, !tbaa !13
  br i1 %.not, label %16, label %14

14:                                               ; preds = %11
  %.0.v = tail call i64 @llvm.umax.i64(i64 %3, i64 65536)
  %.0 = add i64 %6, %.0.v
  %15 = tail call noalias ptr @malloc(i64 noundef %.0) #5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 1 %.pre35, i64 %6, i1 false)
  tail call void @free(ptr noundef %.pre35) #6
  store ptr %15, ptr %1, align 8, !tbaa !13
  store i64 %.0, ptr %5, align 8, !tbaa !5
  %.pre36 = load i64, ptr %7, align 8, !tbaa !12
  br label %16

16:                                               ; preds = %._crit_edge, %11, %14
  %17 = phi i64 [ %.pre36, %14 ], [ %8, %._crit_edge ], [ %8, %11 ]
  %18 = phi ptr [ %15, %14 ], [ %.pre, %._crit_edge ], [ %.pre35, %11 ]
  %.031 = phi i64 [ %3, %14 ], [ %3, %._crit_edge ], [ %9, %11 ]
  %19 = getelementptr inbounds i8, ptr %18, i64 %17
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr align 1 %2, i64 %.031, i1 false)
  %20 = load i64, ptr %7, align 8, !tbaa !12
  %21 = add i64 %20, %.031
  store i64 %21, ptr %7, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = icmp ugt i64 %21, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  store i64 %21, ptr %22, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %25, %16
  ret i64 %.031
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nounwind willreturn 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 8}
!6 = !{!"ourmemory_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !11, i64 32}
!15 = !{!6, !10, i64 16}


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