; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzdeasm_main)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [62 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 i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %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
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 4
  br i1 %14, label %15, label %21

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

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %22, i64 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call i32 (ptr, i32, ...) @open(ptr noundef %24, i32 noundef 0)
  store i32 %25, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %32

28:                                               ; preds = %21
  %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
  call void @perror(ptr noundef %31)
  br label %32

32:                                               ; preds = %28, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = call i64 @lseek(i32 noundef %33, i64 noundef 0, i32 noundef 2) #5
  store i64 %34, ptr %7, align 8, !tbaa !11
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = call i64 @lseek(i32 noundef %35, i64 noundef 0, i32 noundef 0) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %37 = load i64, ptr %7, align 8, !tbaa !11
  %38 = call noalias ptr @malloc(i64 noundef %37) #6
  store ptr %38, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %58, %32
  %40 = load i64, ptr %10, align 8, !tbaa !11
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %43, label %62

43:                                               ; preds = %39
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i64, ptr %7, align 8, !tbaa !11
  %49 = load i64, ptr %10, align 8, !tbaa !11
  %50 = sub i64 %48, %49
  %51 = call i64 @read(i32 noundef %44, ptr noundef %47, i64 noundef %50)
  store i64 %51, ptr %9, align 8, !tbaa !11
  %52 = load i64, ptr %9, align 8, !tbaa !11
  %53 = icmp slt i64 %52, 0
  br i1 %53, label %54, label %58

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds ptr, ptr %55, i64 1
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  call void @perror(ptr noundef %57)
  br label %58

58:                                               ; preds = %54, %43
  %59 = load i64, ptr %9, align 8, !tbaa !11
  %60 = load i64, ptr %10, align 8, !tbaa !11
  %61 = add i64 %60, %59
  store i64 %61, ptr %10, align 8, !tbaa !11
  br label %39, !llvm.loop !13

62:                                               ; preds = %39
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = call i32 @close(i32 noundef %63)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %65 = call ptr (...) @buzzdebug_new()
  store ptr %65, ptr %11, align 8, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = getelementptr inbounds ptr, ptr %67, i64 2
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = call i32 @buzzdebug_fromfile(ptr noundef %66, ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %76, label %72

72:                                               ; preds = %62
  %73 = load ptr, ptr %5, align 8, !tbaa !9
  %74 = getelementptr inbounds ptr, ptr %73, i64 2
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  call void @perror(ptr noundef %75)
  br label %76

76:                                               ; preds = %72, %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load i64, ptr %7, align 8, !tbaa !11
  %79 = trunc i64 %78 to i32
  %80 = load ptr, ptr %11, align 8, !tbaa !9
  %81 = load ptr, ptr %5, align 8, !tbaa !9
  %82 = getelementptr inbounds ptr, ptr %81, i64 3
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = call i32 @buzz_deasm(ptr noundef %77, i32 noundef %79, ptr noundef %80, ptr noundef %83)
  store i32 %84, ptr %12, align 4, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %85) #5
  call void @buzzdebug_destroy(ptr noundef %11)
  %86 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %86, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %87

87:                                               ; preds = %76, %15
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr 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 @perror(ptr noundef) #3

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) #1

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

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

declare i32 @close(i32 noundef) #3

declare ptr @buzzdebug_new(...) #3

declare i32 @buzzdebug_fromfile(ptr noundef, ptr noundef) #3

declare i32 @buzz_deasm(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

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

declare void @buzzdebug_destroy(ptr 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 "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) "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 = !{!"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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %.not = icmp eq i32 %0, 4
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #8
  br label %40

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i32 (ptr, i32, ...) @open(ptr noundef %10, i32 noundef 0) #9
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @perror(ptr noundef %14) #10
  br label %15

15:                                               ; preds = %13, %8
  %16 = tail call i64 @lseek(i32 noundef %11, i64 noundef 0, i32 noundef 2) #9
  %17 = tail call i64 @lseek(i32 noundef %11, i64 noundef 0, i32 noundef 0) #9
  %18 = tail call noalias ptr @malloc(i64 noundef %16) #11
  %.not31 = icmp eq i64 %16, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %25
  %.02730 = phi i64 [ %26, %25 ], [ 0, %15 ]
  %19 = getelementptr inbounds i8, ptr %18, i64 %.02730
  %20 = sub i64 %16, %.02730
  %21 = tail call i64 @read(i32 noundef %11, ptr noundef %19, i64 noundef %20) #9
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %.lr.ph
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @perror(ptr noundef %24) #10
  br label %25

25:                                               ; preds = %23, %.lr.ph
  %26 = add i64 %21, %.02730
  %27 = icmp ult i64 %26, %16
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %25, %15
  %28 = tail call i32 @close(i32 noundef %11) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #9
  %29 = tail call ptr (...) @buzzdebug_new() #9
  store ptr %29, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %1, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = tail call i32 @buzzdebug_fromfile(ptr noundef %29, ptr noundef %31) #9
  %.not29 = icmp eq i32 %32, 0
  br i1 %.not29, label %33, label %35

33:                                               ; preds = %._crit_edge
  %34 = load ptr, ptr %30, align 8, !tbaa !5
  tail call void @perror(ptr noundef %34) #10
  br label %35

35:                                               ; preds = %33, %._crit_edge
  %36 = trunc i64 %16 to i32
  %37 = getelementptr inbounds i8, ptr %1, i64 24
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = tail call i32 @buzz_deasm(ptr noundef %18, i32 noundef %36, ptr noundef %29, ptr noundef %38) #9
  tail call void @free(ptr noundef %18) #9
  call void @buzzdebug_destroy(ptr noundef nonnull %3) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #9
  br label %40

40:                                               ; preds = %35, %4
  %.0 = phi i32 [ 0, %4 ], [ %39, %35 ]
  ret i32 %.0
}

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

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

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

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

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

declare i32 @close(i32 noundef) local_unnamed_addr #6

declare ptr @buzzdebug_new(...) local_unnamed_addr #6

declare i32 @buzzdebug_fromfile(ptr noundef, ptr noundef) local_unnamed_addr #6

declare i32 @buzz_deasm(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

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

declare void @buzzdebug_destroy(ptr noundef) local_unnamed_addr #6

; Function Attrs: mustprogress 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = { 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 #6 = { "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 #7 = { 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 #8 = { cold nounwind }
attributes #9 = { nounwind }
attributes #10 = { cold }
attributes #11 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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