; LLVM IR from Ryuk17/SpeechAlgorithms :: SpeechCodec/G711/src (g711_codec)

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

@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @get_file_size(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @allocate_buffer(i64 noundef) #0

declare void @perror(ptr noundef) #2

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

; 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 ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  %14 = call noalias ptr @fopen(ptr noundef @.str.1, ptr noundef @.str.2)
  store ptr %14, ptr %6, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  call void @perror(ptr noundef @.str.3)
  call void @exit(i32 noundef 1) #6
  unreachable

18:                                               ; preds = %2
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = call i64 @get_file_size(ptr noundef %20)
  store i64 %21, ptr %10, align 8, !tbaa !11
  %22 = load i64, ptr %10, align 8, !tbaa !11
  %23 = call ptr @allocate_buffer(i64 noundef %22)
  store ptr %23, ptr %8, align 8, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = load i64, ptr %10, align 8, !tbaa !11
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = call i64 @fread(ptr noundef %24, i64 noundef 1, i64 noundef %25, ptr noundef %26)
  store i64 %27, ptr %12, align 8, !tbaa !11
  %28 = load i64, ptr %12, align 8, !tbaa !11
  %29 = load i64, ptr %10, align 8, !tbaa !11
  %30 = icmp ne i64 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %18
  call void @perror(ptr noundef @.str.5)
  call void @exit(i32 noundef 1) #6
  unreachable

32:                                               ; preds = %18
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = call i32 @fclose(ptr noundef %33)
  %35 = load i32, ptr %13, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %46

37:                                               ; preds = %32
  call void (...) @alaw_pcm16_tableinit()
  %38 = load i64, ptr %10, align 8, !tbaa !11
  %39 = mul nsw i64 %38, 2
  store i64 %39, ptr %11, align 8, !tbaa !11
  %40 = load i64, ptr %11, align 8, !tbaa !11
  %41 = call ptr @allocate_buffer(i64 noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !9
  %42 = load i64, ptr %10, align 8, !tbaa !11
  %43 = trunc i64 %42 to i32
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  call void @alaw_to_pcm16(i32 noundef %43, ptr noundef %44, ptr noundef %45)
  br label %86

46:                                               ; preds = %32
  %47 = load i32, ptr %13, align 4, !tbaa !5
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %49, label %58

49:                                               ; preds = %46
  call void (...) @ulaw_pcm16_tableinit()
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = mul nsw i64 %50, 2
  store i64 %51, ptr %11, align 8, !tbaa !11
  %52 = load i64, ptr %11, align 8, !tbaa !11
  %53 = call ptr @allocate_buffer(i64 noundef %52)
  store ptr %53, ptr %9, align 8, !tbaa !9
  %54 = load i64, ptr %10, align 8, !tbaa !11
  %55 = trunc i64 %54 to i32
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  call void @ulaw_to_pcm16(i32 noundef %55, ptr noundef %56, ptr noundef %57)
  br label %85

58:                                               ; preds = %46
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %70

61:                                               ; preds = %58
  call void (...) @pcm16_alaw_tableinit()
  %62 = load i64, ptr %10, align 8, !tbaa !11
  %63 = sdiv i64 %62, 2
  store i64 %63, ptr %11, align 8, !tbaa !11
  %64 = load i64, ptr %11, align 8, !tbaa !11
  %65 = call ptr @allocate_buffer(i64 noundef %64)
  store ptr %65, ptr %9, align 8, !tbaa !9
  %66 = load i64, ptr %10, align 8, !tbaa !11
  %67 = trunc i64 %66 to i32
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  call void @pcm16_to_alaw(i32 noundef %67, ptr noundef %68, ptr noundef %69)
  br label %84

70:                                               ; preds = %58
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = icmp eq i32 %71, 3
  br i1 %72, label %73, label %82

73:                                               ; preds = %70
  call void (...) @pcm16_ulaw_tableinit()
  %74 = load i64, ptr %10, align 8, !tbaa !11
  %75 = sdiv i64 %74, 2
  store i64 %75, ptr %11, align 8, !tbaa !11
  %76 = load i64, ptr %11, align 8, !tbaa !11
  %77 = call ptr @allocate_buffer(i64 noundef %76)
  store ptr %77, ptr %9, align 8, !tbaa !9
  %78 = load i64, ptr %10, align 8, !tbaa !11
  %79 = trunc i64 %78 to i32
  %80 = load ptr, ptr %8, align 8, !tbaa !9
  %81 = load ptr, ptr %9, align 8, !tbaa !9
  call void @pcm16_to_ulaw(i32 noundef %79, ptr noundef %80, ptr noundef %81)
  br label %83

82:                                               ; preds = %70
  call void @perror(ptr noundef @.str.6)
  call void @exit(i32 noundef 1) #6
  unreachable

83:                                               ; preds = %73
  br label %84

84:                                               ; preds = %83, %61
  br label %85

85:                                               ; preds = %84, %49
  br label %86

86:                                               ; preds = %85, %37
  %87 = call noalias ptr @fopen(ptr noundef @.str.7, ptr noundef @.str.8)
  store ptr %87, ptr %7, align 8, !tbaa !9
  %88 = load ptr, ptr %7, align 8, !tbaa !9
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %91

90:                                               ; preds = %86
  call void @perror(ptr noundef @.str.9)
  call void @exit(i32 noundef 1) #6
  unreachable

91:                                               ; preds = %86
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %93 = load ptr, ptr %9, align 8, !tbaa !9
  %94 = load i64, ptr %11, align 8, !tbaa !11
  %95 = load ptr, ptr %7, align 8, !tbaa !9
  %96 = call i64 @fwrite(ptr noundef %93, i64 noundef 1, i64 noundef %94, ptr noundef %95)
  %97 = load ptr, ptr %7, align 8, !tbaa !9
  %98 = call i32 @fclose(ptr noundef %97)
  %99 = load ptr, ptr %9, align 8, !tbaa !9
  call void @free(ptr noundef %99) #5
  %100 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %100) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, 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 8, ptr %6) #5
  ret i32 0
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #2

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

declare void @alaw_pcm16_tableinit(...) #2

declare void @alaw_to_pcm16(i32 noundef, ptr noundef, ptr noundef) #2

declare void @ulaw_pcm16_tableinit(...) #2

declare void @ulaw_to_pcm16(i32 noundef, ptr noundef, ptr noundef) #2

declare void @pcm16_alaw_tableinit(...) #2

declare void @pcm16_to_alaw(i32 noundef, ptr noundef, ptr noundef) #2

declare void @pcm16_ulaw_tableinit(...) #2

declare void @pcm16_to_ulaw(i32 noundef, ptr noundef, ptr noundef) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @get_file_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @allocate_buffer(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  tail call void @perror(ptr noundef nonnull @.str.3) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

6:                                                ; preds = %2
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %8 = tail call i64 @get_file_size(ptr noundef nonnull %3)
  %9 = tail call ptr @allocate_buffer(i64 noundef %8)
  %10 = tail call i64 @fread(ptr noundef %9, i64 noundef 1, i64 noundef %8, ptr noundef nonnull %3)
  %.not = icmp eq i64 %10, %8
  br i1 %.not, label %12, label %11

11:                                               ; preds = %6
  tail call void @perror(ptr noundef nonnull @.str.5) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

12:                                               ; preds = %6
  %13 = tail call i32 @fclose(ptr noundef nonnull %3)
  tail call void (...) @alaw_pcm16_tableinit() #7
  %14 = shl nsw i64 %8, 1
  %15 = tail call ptr @allocate_buffer(i64 noundef %14)
  %16 = trunc i64 %8 to i32
  tail call void @alaw_to_pcm16(i32 noundef %16, ptr noundef %9, ptr noundef %15) #7
  %17 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.8)
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  tail call void @perror(ptr noundef nonnull @.str.9) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

20:                                               ; preds = %12
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %22 = tail call i64 @fwrite(ptr noundef %15, i64 noundef 1, i64 noundef %14, ptr noundef nonnull %17)
  %23 = tail call i32 @fclose(ptr noundef nonnull %17)
  tail call void @free(ptr noundef %15) #7
  tail call void @free(ptr noundef %9) #7
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

declare void @alaw_pcm16_tableinit(...) local_unnamed_addr #3

declare void @alaw_to_pcm16(i32 noundef, ptr noundef, ptr 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

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

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 = { 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 = { "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 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 #5 = { cold }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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)"}


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