; LLVM IR from dyu/ffi-overhead :: wren (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"

%struct.WrenConfiguration = type { ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, ptr }

@DEFAULT_SCRIPT = external hidden constant [11 x i8], align 1
@count = external hidden global double, align 8
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@ts_stop = external hidden global i64, align 8
@ts_start = external hidden global i64, align 8
@.str.2 = external hidden unnamed_addr constant [31 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 ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.WrenConfiguration, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %15, label %19

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  br label %20

19:                                               ; preds = %2
  br label %20

20:                                               ; preds = %19, %15
  %21 = phi ptr [ %18, %15 ], [ @DEFAULT_SCRIPT, %19 ]
  store ptr %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 2
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %25, i64 2
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @atoi(ptr noundef %27) #6
  br label %30

29:                                               ; preds = %20
  br label %30

30:                                               ; preds = %29, %24
  %31 = phi i32 [ %28, %24 ], [ 1000000, %29 ]
  store i32 %31, ptr %7, align 4, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sitofp i32 %32 to double
  %34 = load double, ptr @count, align 8, !tbaa !11
  %35 = fadd double %34, %33
  store double %35, ptr @count, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = call ptr @readFile(ptr noundef %36)
  store ptr %37, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %44

40:                                               ; preds = %30
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str, ptr noundef %42) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %68

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 80, ptr %10) #5
  call void @wrenInitConfiguration(ptr noundef %10)
  %45 = getelementptr inbounds %struct.WrenConfiguration, ptr %10, i32 0, i32 2
  store ptr @bindForeignMethod, ptr %45, align 8, !tbaa !13
  %46 = getelementptr inbounds %struct.WrenConfiguration, ptr %10, i32 0, i32 4
  store ptr @write, ptr %46, align 8, !tbaa !16
  %47 = getelementptr inbounds %struct.WrenConfiguration, ptr %10, i32 0, i32 5
  store ptr @reportError, ptr %47, align 8, !tbaa !17
  %48 = getelementptr inbounds %struct.WrenConfiguration, ptr %10, i32 0, i32 6
  store i64 104857600, ptr %48, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %49 = call ptr @wrenNewVM(ptr noundef %10)
  store ptr %49, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = call i32 @wrenInterpret(ptr noundef %50, ptr noundef %51)
  store i32 %52, ptr %12, align 4, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %60

55:                                               ; preds = %44
  %56 = load i64, ptr @ts_stop, align 8, !tbaa !19
  %57 = load i64, ptr @ts_start, align 8, !tbaa !19
  %58 = sub nsw i64 %56, %57
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %58)
  br label %64

60:                                               ; preds = %44
  %61 = load ptr, ptr @stderr, align 8, !tbaa !9
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.2, i32 noundef %62) #5
  br label %64

64:                                               ; preds = %60, %55
  %65 = load ptr, ptr %11, align 8, !tbaa !9
  call void @wrenFreeVM(ptr noundef %65)
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %66) #5
  %67 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %9, 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 80, ptr %10) #5
  br label %68

68:                                               ; preds = %64, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %69 = load i32, ptr %3, align 4
  ret i32 %69
}

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @readFile(ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare void @wrenInitConfiguration(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden ptr @bindForeignMethod(ptr noundef, ptr noundef, ptr noundef, i1 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @write(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @reportError(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #0

declare ptr @wrenNewVM(ptr noundef) #4

declare i32 @wrenInterpret(ptr noundef, ptr noundef) #4

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

declare void @wrenFreeVM(ptr noundef) #4

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

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

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 = { inlinehint nounwind willreturn memory(read) 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 #3 = { 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 = { "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 willreturn memory(read) }

!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 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !15, i64 48, !15, i64 56, !6, i64 64, !10, i64 72}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !10, i64 32}
!17 = !{!14, !10, i64 40}
!18 = !{!14, !15, i64 48}
!19 = !{!20, !20, i64 0}
!20 = !{!"long 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"

%struct.WrenConfiguration = type { ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, ptr }

@DEFAULT_SCRIPT = external hidden constant [11 x i8], align 1
@count = external hidden local_unnamed_addr global double, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@ts_stop = external hidden local_unnamed_addr global i64, align 8
@ts_start = external hidden local_unnamed_addr global i64, align 8
@.str.2 = external hidden unnamed_addr constant [31 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 %struct.WrenConfiguration, align 8
  %4 = icmp sgt i32 %0, 1
  br i1 %4, label %5, label %.thread

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %.thread, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i32 @atoi(ptr nocapture noundef %10) #6
  %12 = sitofp i32 %11 to double
  br label %.thread

.thread:                                          ; preds = %2, %5, %8
  %13 = phi ptr [ %7, %8 ], [ %7, %5 ], [ @DEFAULT_SCRIPT, %2 ]
  %14 = phi double [ %12, %8 ], [ 1.000000e+06, %5 ], [ 1.000000e+06, %2 ]
  %15 = load double, ptr @count, align 8, !tbaa !9
  %16 = fadd double %14, %15
  store double %16, ptr @count, align 8, !tbaa !9
  %17 = tail call ptr @readFile(ptr noundef %13)
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %.thread
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef %13) #7
  br label %39

22:                                               ; preds = %.thread
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #8
  call void @wrenInitConfiguration(ptr noundef nonnull %3) #8
  %23 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr @bindForeignMethod, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr @write, ptr %24, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %3, i64 40
  store ptr @reportError, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %3, i64 48
  store i64 104857600, ptr %26, align 8, !tbaa !17
  %27 = call ptr @wrenNewVM(ptr noundef nonnull %3) #8
  %28 = call i32 @wrenInterpret(ptr noundef %27, ptr noundef nonnull %17) #8
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %22
  %31 = load i64, ptr @ts_stop, align 8, !tbaa !18
  %32 = load i64, ptr @ts_start, align 8, !tbaa !18
  %33 = sub nsw i64 %31, %32
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %33)
  br label %38

35:                                               ; preds = %22
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.2, i32 noundef %28) #7
  br label %38

38:                                               ; preds = %35, %30
  call void @wrenFreeVM(ptr noundef %27) #8
  call void @free(ptr noundef nonnull %17) #8
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #8
  br label %39

39:                                               ; preds = %38, %19
  %.0 = phi i32 [ 1, %19 ], [ %28, %38 ]
  ret i32 %.0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @readFile(ptr noundef) local_unnamed_addr #0

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

declare void @wrenInitConfiguration(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden ptr @bindForeignMethod(ptr noundef, ptr noundef, ptr noundef, i1 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @write(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @reportError(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #0

declare ptr @wrenNewVM(ptr noundef) local_unnamed_addr #4

declare i32 @wrenInterpret(ptr noundef, ptr noundef) local_unnamed_addr #4

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

declare void @wrenFreeVM(ptr noundef) local_unnamed_addr #4

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #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 = { "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 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 #6 = { nounwind willreturn memory(read) }
attributes #7 = { cold nounwind }
attributes #8 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 56, !14, i64 64, !6, i64 72}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !6, i64 40}
!17 = !{!12, !13, i64 48}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass