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

; 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.ourstream_s = type { [65536 x i8], i32, i32, i32, i32, [65536 x i8], i32, i32, i32, i32, i64, ptr }
%struct.ourbuffer_s = type { %struct.zlib_filefunc_def_s, %struct.zlib_filefunc64_def_s }
%struct.zlib_filefunc_def_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.zlib_filefunc64_def_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

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

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

21:                                               ; preds = %88, %2
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = icmp ugt i32 %22, 0
  br i1 %23, label %24, label %101

24:                                               ; preds = %21
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ourbuffer_s, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.zlib_filefunc64_def_s, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %54

30:                                               ; preds = %24
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ourbuffer_s, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.zlib_filefunc64_def_s, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ourbuffer_s, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.zlib_filefunc64_def_s, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ourstream_s, ptr %39, i32 0, i32 11
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ourstream_s, ptr %42, i32 0, i32 5
  %44 = getelementptr inbounds [65536 x i8], ptr %43, i64 0, i64 0
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sub i32 %45, %46
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %44, i64 %48
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = call i64 %34(ptr noundef %38, ptr noundef %41, ptr noundef %49, i64 noundef %51)
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %78

54:                                               ; preds = %24
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ourbuffer_s, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds %struct.zlib_filefunc_def_s, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !20
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ourbuffer_s, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.zlib_filefunc_def_s, ptr %60, i32 0, i32 8
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ourstream_s, ptr %63, i32 0, i32 11
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ourstream_s, ptr %66, i32 0, i32 5
  %68 = getelementptr inbounds [65536 x i8], ptr %67, i64 0, i64 0
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sub i32 %69, %70
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %68, i64 %72
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = call i64 %58(ptr noundef %62, ptr noundef %65, ptr noundef %73, i64 noundef %75)
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %11, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %54, %30
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ourstream_s, ptr %79, i32 0, i32 9
  %81 = load i32, ptr %80, align 4, !tbaa !22
  %82 = add i32 %81, 1
  store i32 %82, ptr %80, align 4, !tbaa !22
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = icmp slt i32 %83, 0
  br i1 %84, label %85, label %88

85:                                               ; preds = %78
  %86 = load i32, ptr %11, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  store i64 %87, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %108

88:                                               ; preds = %78
  %89 = load i32, ptr %11, align 4, !tbaa !9
  %90 = load i32, ptr %8, align 4, !tbaa !9
  %91 = add i32 %90, %89
  store i32 %91, ptr %8, align 4, !tbaa !9
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = sub i32 %93, %92
  store i32 %94, ptr %10, align 4, !tbaa !9
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.ourstream_s, ptr %97, i32 0, i32 10
  %99 = load i64, ptr %98, align 8, !tbaa !23
  %100 = add i64 %99, %96
  store i64 %100, ptr %98, align 8, !tbaa !23
  br label %21, !llvm.loop !24

101:                                              ; preds = %21
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.ourstream_s, ptr %102, i32 0, i32 6
  store i32 0, ptr %103, align 8, !tbaa !11
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.ourstream_s, ptr %104, i32 0, i32 7
  store i32 0, ptr %105, align 4, !tbaa !26
  %106 = load i32, ptr %8, align 4, !tbaa !9
  %107 = zext i32 %106 to i64
  store i64 %107, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %108

108:                                              ; preds = %101, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %109 = load i64, ptr %3, align 8
  ret i64 %109
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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, !10, i64 131088}
!12 = !{!"ourstream_s", !7, i64 0, !10, i64 65536, !10, i64 65540, !10, i64 65544, !10, i64 65548, !7, i64 65552, !10, i64 131088, !10, i64 131092, !10, i64 131096, !10, i64 131100, !13, i64 131104, !6, i64 131112}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !6, i64 96}
!15 = !{!"ourbuffer_s", !16, i64 0, !17, i64 72}
!16 = !{!"zlib_filefunc_def_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!17 = !{!"zlib_filefunc64_def_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!18 = !{!15, !6, i64 136}
!19 = !{!12, !6, i64 131112}
!20 = !{!15, !6, i64 24}
!21 = !{!15, !6, i64 64}
!22 = !{!12, !10, i64 131100}
!23 = !{!12, !13, i64 131104}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!12, !10, i64 131092}


; 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: nounwind uwtable
define dso_local i64 @fflush_buf(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 131088
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not38 = icmp eq i32 %4, 0
  br i1 %.not38, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = getelementptr inbounds i8, ptr %0, i64 136
  %7 = getelementptr inbounds i8, ptr %1, i64 131112
  %8 = getelementptr inbounds i8, ptr %1, i64 65552
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = getelementptr inbounds i8, ptr %1, i64 131100
  %12 = getelementptr inbounds i8, ptr %1, i64 131104
  br label %13

13:                                               ; preds = %.lr.ph, %30
  %.03240 = phi i32 [ %4, %.lr.ph ], [ %32, %30 ]
  %.03439 = phi i32 [ 0, %.lr.ph ], [ %31, %30 ]
  %14 = load ptr, ptr %5, align 8, !tbaa !12
  %.not36 = icmp eq ptr %14, null
  br i1 %.not36, label %15, label %17

15:                                               ; preds = %13
  %16 = load ptr, ptr %9, align 8, !tbaa !16
  br label %17

17:                                               ; preds = %13, %15
  %.sink49 = phi ptr [ %10, %15 ], [ %6, %13 ]
  %.sink46 = phi ptr [ %16, %15 ], [ %14, %13 ]
  %18 = load ptr, ptr %.sink49, align 8, !tbaa !17
  %19 = load ptr, ptr %7, align 8, !tbaa !18
  %20 = sub i32 %4, %.03240
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %8, i64 %21
  %23 = zext i32 %.03240 to i64
  %24 = tail call i64 %.sink46(ptr noundef %18, ptr noundef %19, ptr noundef nonnull %22, i64 noundef %23) #1
  %.0 = trunc i64 %24 to i32
  %25 = load i32, ptr %11, align 4, !tbaa !19
  %26 = add i32 %25, 1
  store i32 %26, ptr %11, align 4, !tbaa !19
  %27 = icmp slt i32 %.0, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %17
  %sext = shl i64 %24, 32
  %29 = ashr exact i64 %sext, 32
  br label %38

30:                                               ; preds = %17
  %31 = add i32 %.03439, %.0
  %32 = sub i32 %.03240, %.0
  %33 = and i64 %24, 2147483647
  %34 = load i64, ptr %12, align 8, !tbaa !20
  %35 = add i64 %34, %33
  store i64 %35, ptr %12, align 8, !tbaa !20
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %._crit_edge.loopexit, label %13, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %30
  %36 = zext i32 %31 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.034.lcssa = phi i64 [ 0, %2 ], [ %36, %._crit_edge.loopexit ]
  store i32 0, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %1, i64 131092
  store i32 0, ptr %37, align 4, !tbaa !23
  br label %38

38:                                               ; preds = %._crit_edge, %28
  %.033 = phi i64 [ %29, %28 ], [ %.034.lcssa, %._crit_edge ]
  ret i64 %.033
}

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 }

!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 131088}
!6 = !{!"ourstream_s", !7, i64 0, !9, i64 65536, !9, i64 65540, !9, i64 65544, !9, i64 65548, !7, i64 65552, !9, i64 131088, !9, i64 131092, !9, i64 131096, !9, i64 131100, !10, i64 131104, !11, i64 131112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 96}
!13 = !{!"ourbuffer_s", !14, i64 0, !15, i64 72}
!14 = !{!"zlib_filefunc_def_s", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64}
!15 = !{!"zlib_filefunc64_def_s", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64}
!16 = !{!13, !11, i64 24}
!17 = !{!11, !11, i64 0}
!18 = !{!6, !11, i64 131112}
!19 = !{!6, !9, i64 131100}
!20 = !{!6, !10, i64 131104}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!6, !9, i64 131092}


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