; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/ply.ll (Z17write_binary_itemP8_IO_FILEiijdi)

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

@ply_type_size = external dso_local global [9 x i32], align 16
@_ZL18native_binary_type = external hidden global i32, align 4
@stderr = external global ptr, align 8
@.str.55 = external hidden unnamed_addr constant [34 x i8], align 1

; 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17write_binary_itemP8_IO_FILEiijdi(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4, i32 noundef %5) #3 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i16, align 2
  %16 = alloca i16, align 2
  %17 = alloca float, align 4
  %18 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !11
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 2, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %19 = load i32, ptr %12, align 4, !tbaa !9
  switch i32 %19, label %38 [
    i32 1, label %20
    i32 2, label %23
    i32 3, label %26
    i32 4, label %27
    i32 5, label %30
    i32 6, label %33
    i32 7, label %34
    i32 8, label %37
  ]

20:                                               ; preds = %6
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %14, align 1, !tbaa !13
  store ptr %14, ptr %18, align 8, !tbaa !5
  br label %42

23:                                               ; preds = %6
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = trunc i32 %24 to i16
  store i16 %25, ptr %16, align 2, !tbaa !14
  store ptr %16, ptr %18, align 8, !tbaa !5
  br label %42

26:                                               ; preds = %6
  store ptr %9, ptr %18, align 8, !tbaa !5
  br label %42

27:                                               ; preds = %6
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %13, align 1, !tbaa !13
  store ptr %13, ptr %18, align 8, !tbaa !5
  br label %42

30:                                               ; preds = %6
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %15, align 2, !tbaa !14
  store ptr %15, ptr %18, align 8, !tbaa !5
  br label %42

33:                                               ; preds = %6
  store ptr %10, ptr %18, align 8, !tbaa !5
  br label %42

34:                                               ; preds = %6
  %35 = load double, ptr %11, align 8, !tbaa !11
  %36 = fptrunc double %35 to float
  store float %36, ptr %17, align 4, !tbaa !16
  store ptr %17, ptr %18, align 8, !tbaa !5
  br label %42

37:                                               ; preds = %6
  store ptr %11, ptr %18, align 8, !tbaa !5
  br label %42

38:                                               ; preds = %6
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.55, i32 noundef %40) #6
  call void @exit(i32 noundef -1) #7
  unreachable

42:                                               ; preds = %37, %34, %33, %30, %27, %26, %23, %20
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr @_ZL18native_binary_type, align 4, !tbaa !9
  %45 = icmp ne i32 %43, %44
  br i1 %45, label %46, label %58

46:                                               ; preds = %42
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [9 x i32], ptr @ply_type_size, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp sgt i32 %50, 1
  br i1 %51, label %52, label %58

52:                                               ; preds = %46
  %53 = load ptr, ptr %18, align 8, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [9 x i32], ptr @ply_type_size, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  call void @_Z10swap_bytesPci(ptr noundef %53, i32 noundef %57)
  br label %58

58:                                               ; preds = %52, %46, %42
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [9 x i32], ptr @ply_type_size, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i64 @fwrite(ptr noundef %59, i64 noundef %64, i64 noundef 1, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #6
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10swap_bytesPci(ptr noundef, i32 noundef) #4

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 #3 = { mustprogress 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 = { mustprogress 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 #5 = { "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 = { nounwind }
attributes #7 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, 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"

@ply_type_size = external dso_local local_unnamed_addr global [9 x i32], align 16
@_ZL18native_binary_type = external hidden local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.55 = external hidden unnamed_addr constant [34 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z17write_binary_itemP8_IO_FILEiijdi(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, double noundef %4, i32 noundef %5) local_unnamed_addr #3 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  %14 = alloca float, align 4
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  store double %4, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %11) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %12) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #4
  switch i32 %5, label %27 [
    i32 1, label %15
    i32 2, label %17
    i32 3, label %30
    i32 4, label %19
    i32 5, label %21
    i32 6, label %23
    i32 7, label %24
    i32 8, label %26
  ]

15:                                               ; preds = %6
  %16 = trunc i32 %2 to i8
  store i8 %16, ptr %11, align 1, !tbaa !11
  br label %30

17:                                               ; preds = %6
  %18 = trunc i32 %2 to i16
  store i16 %18, ptr %13, align 2, !tbaa !12
  br label %30

19:                                               ; preds = %6
  %20 = trunc i32 %3 to i8
  store i8 %20, ptr %10, align 1, !tbaa !11
  br label %30

21:                                               ; preds = %6
  %22 = trunc i32 %3 to i16
  store i16 %22, ptr %12, align 2, !tbaa !12
  br label %30

23:                                               ; preds = %6
  br label %30

24:                                               ; preds = %6
  %25 = fptrunc double %4 to float
  store float %25, ptr %14, align 4, !tbaa !14
  br label %30

26:                                               ; preds = %6
  br label %30

27:                                               ; preds = %6
  %28 = load ptr, ptr @stderr, align 8, !tbaa !16
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.55, i32 noundef %5) #5
  tail call void @exit(i32 noundef -1) #6
  unreachable

30:                                               ; preds = %6, %26, %24, %23, %21, %19, %17, %15
  %.0 = phi ptr [ %9, %26 ], [ %14, %24 ], [ %8, %23 ], [ %12, %21 ], [ %10, %19 ], [ %13, %17 ], [ %11, %15 ], [ %7, %6 ]
  %31 = load i32, ptr @_ZL18native_binary_type, align 4, !tbaa !5
  %.not = icmp eq i32 %31, %1
  %.pre = zext nneg i32 %5 to i64
  br i1 %.not, label %._crit_edge, label %32

32:                                               ; preds = %30
  %33 = getelementptr inbounds [9 x i32], ptr @ply_type_size, i64 0, i64 %.pre
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 1
  br i1 %35, label %36, label %._crit_edge

36:                                               ; preds = %32
  call void @_Z10swap_bytesPci(ptr noundef nonnull %.0, i32 noundef %34)
  br label %._crit_edge

._crit_edge:                                      ; preds = %30, %36, %32
  %37 = getelementptr inbounds [9 x i32], ptr @ply_type_size, i64 0, i64 %.pre
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = call i64 @fwrite(ptr noundef nonnull %.0, i64 noundef %39, i64 noundef 1, ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %12) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10swap_bytesPci(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 #3 = { mustprogress 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 }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}


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