; LLVM IR from kkumatani/distant_speech_recognition :: btk20_src/common/mach_ind_io.ll (Z9write_intP8_IO_FILEi)

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

%union.unionT = type { float }

@_ZL7machine = external hidden global i32, align 4
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@_ZTI9jio_error = external dso_local constant { ptr, ptr, ptr }, align 8

; 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

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9jio_errorC2EPKcz(ptr noundef nonnull align 8 dereferenceable(44), ptr noundef, ...) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZN7j_errorD2Ev(ptr noundef nonnull align 8 dereferenceable(44)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9write_intP8_IO_FILEi(ptr noundef %0, i32 noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %union.unionT, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = load i32, ptr @_ZL7machine, align 4, !tbaa !9
  switch i32 %8, label %27 [
    i32 1, label %9
    i32 2, label %11
    i32 3, label %11
  ]

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %10, ptr %5, align 4, !tbaa !11
  br label %35

11:                                               ; preds = %2, %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = shl i32 %12, 24
  %14 = and i32 %13, -16777216
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = shl i32 %15, 8
  %17 = and i32 %16, 16711680
  %18 = or i32 %14, %17
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = ashr i32 %19, 8
  %21 = and i32 %20, 65280
  %22 = or i32 %18, %21
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = ashr i32 %23, 24
  %25 = and i32 %24, 255
  %26 = or i32 %22, %25
  store i32 %26, ptr %5, align 4, !tbaa !11
  br label %35

27:                                               ; preds = %2
  %28 = call ptr @__cxa_allocate_exception(i64 48) #4
  %29 = load i32, ptr @_ZL7machine, align 4, !tbaa !9
  invoke void (ptr, ptr, ...) @_ZN9jio_errorC2EPKcz(ptr noundef nonnull align 8 dereferenceable(44) %28, ptr noundef @.str.3, i32 noundef %29)
          to label %30 unwind label %31

30:                                               ; preds = %27
  call void @__cxa_throw(ptr %28, ptr @_ZTI9jio_error, ptr @_ZN7j_errorD2Ev) #5
  unreachable

31:                                               ; preds = %27
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %6, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %7, align 4
  call void @__cxa_free_exception(ptr %28) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %38

35:                                               ; preds = %11, %9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call i64 @fwrite(ptr noundef %5, i64 noundef 4, i64 noundef 1, ptr noundef %36)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void

38:                                               ; preds = %31
  %39 = load ptr, ptr %6, align 8
  %40 = load i32, ptr %7, align 4
  %41 = insertvalue { ptr, i32 } poison, ptr %39, 0
  %42 = insertvalue { ptr, i32 } %41, i32 %40, 1
  resume { ptr, i32 } %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { "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 = { noreturn }

!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 = !{!7, !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"

%union.unionT = type { float }

@_ZL7machine = external hidden local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@_ZTI9jio_error = external dso_local constant { ptr, ptr, ptr }, align 8

; 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

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9jio_errorC2EPKcz(ptr noundef nonnull align 8 dereferenceable(44), ptr noundef, ...) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZN7j_errorD2Ev(ptr noundef nonnull align 8 dereferenceable(44)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9write_intP8_IO_FILEi(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca %union.unionT, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %4 = load i32, ptr @_ZL7machine, align 4, !tbaa !5
  switch i32 %4, label %7 [
    i32 1, label %13
    i32 2, label %5
    i32 3, label %5
  ]

5:                                                ; preds = %2, %2
  %6 = tail call i32 @llvm.bswap.i32(i32 %1)
  br label %13

7:                                                ; preds = %2
  %8 = tail call ptr @__cxa_allocate_exception(i64 48) #5
  %9 = load i32, ptr @_ZL7machine, align 4, !tbaa !5
  invoke void (ptr, ptr, ...) @_ZN9jio_errorC2EPKcz(ptr noundef nonnull align 8 dereferenceable(44) %8, ptr noundef nonnull @.str.3, i32 noundef %9)
          to label %10 unwind label %11

10:                                               ; preds = %7
  tail call void @__cxa_throw(ptr nonnull %8, ptr nonnull @_ZTI9jio_error, ptr nonnull @_ZN7j_errorD2Ev) #6
  unreachable

11:                                               ; preds = %7
  %12 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  resume { ptr, i32 } %12

13:                                               ; preds = %2, %5
  %storemerge = phi i32 [ %6, %5 ], [ %1, %2 ]
  store i32 %storemerge, ptr %3, align 4, !tbaa !9
  %14 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 4, i64 noundef 1, ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!7, !7, i64 0}


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