; LLVM IR from Aeternum-Veritas/Merry :: main (merry_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.MerryCLP = type { i8, i8, i8, ptr, ptr, i8, ptr, i64, i8, ptr }

@stdout = external global ptr, align 8
@cmd_opts = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@_os_init = external hidden global i8, align 1
@os_thread = external hidden global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [49 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @merry_main() #1 {
  %1 = alloca i32, align 4
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  %3 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef @.str.8, ptr noundef null) #3
  %4 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.MerryCLP, ptr %4, i32 0, i32 3
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MerryCLP, ptr %7, i32 0, i32 7
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = icmp ugt i64 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %0
  %12 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MerryCLP, ptr %12, i32 0, i32 6
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  br label %16

15:                                               ; preds = %0
  br label %16

16:                                               ; preds = %15, %11
  %17 = phi ptr [ %14, %11 ], [ null, %15 ]
  %18 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MerryCLP, ptr %18, i32 0, i32 7
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MerryCLP, ptr %21, i32 0, i32 2
  %23 = load i8, ptr %22, align 2, !tbaa !14
  %24 = call zeroext i8 @merry_os_init(ptr noundef %6, ptr noundef %17, i64 noundef %20, i8 noundef zeroext %23)
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %28

27:                                               ; preds = %16
  store i32 1, ptr %1, align 4
  br label %64

28:                                               ; preds = %16
  store i8 1, ptr @_os_init, align 1, !tbaa !15
  %29 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MerryCLP, ptr %29, i32 0, i32 5
  %31 = load i8, ptr %30, align 8, !tbaa !16
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %38

34:                                               ; preds = %28
  %35 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MerryCLP, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  call void @merry_os_produce_dump(ptr noundef %37)
  br label %38

38:                                               ; preds = %34, %28
  %39 = call ptr (...) @merry_thread_init()
  store ptr %39, ptr @os_thread, align 8, !tbaa !5
  %40 = load ptr, ptr @os_thread, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %45

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

45:                                               ; preds = %38
  %46 = load ptr, ptr @stdout, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.10, ptr noundef null) #3
  %48 = load ptr, ptr @os_thread, align 8, !tbaa !5
  %49 = call zeroext i8 @merry_create_thread(ptr noundef %48, ptr noundef @merry_os_start_vm, ptr noundef null)
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %55

52:                                               ; preds = %45
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.11) #3
  store i32 1, ptr %1, align 4
  br label %64

55:                                               ; preds = %45
  %56 = load ptr, ptr @stdout, align 8, !tbaa !5
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str.12, ptr noundef null) #3
  %58 = load ptr, ptr @stdout, align 8, !tbaa !5
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.13, ptr noundef null) #3
  %60 = load ptr, ptr @os_thread, align 8, !tbaa !5
  %61 = call zeroext i8 @merry_thread_join(ptr noundef %60, ptr noundef null)
  %62 = call i64 (...) @merry_os_get_ret()
  %63 = trunc i64 %62 to i32
  store i32 %63, ptr %1, align 4
  br label %64

64:                                               ; preds = %55, %52, %42, %27
  %65 = load i32, ptr %1, align 4
  ret i32 %65
}

declare zeroext i8 @merry_os_init(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) #2

declare void @merry_os_produce_dump(ptr noundef) #2

declare ptr @merry_thread_init(...) #2

declare zeroext i8 @merry_create_thread(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @merry_os_start_vm(ptr noundef) #2

declare zeroext i8 @merry_thread_join(ptr noundef, ptr noundef) #2

declare i64 @merry_os_get_ret(...) #2

attributes #0 = { 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 #1 = { 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 #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 = { 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, !6, i64 8}
!10 = !{!"MerryCLP", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 8, !6, i64 16, !7, i64 24, !6, i64 32, !11, i64 40, !7, i64 48, !6, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 40}
!13 = !{!10, !6, i64 32}
!14 = !{!10, !7, i64 2}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !7, i64 24}
!17 = !{!10, !6, i64 16}


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

@stdout = external local_unnamed_addr global ptr, align 8
@cmd_opts = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@_os_init = external hidden local_unnamed_addr global i8, align 1
@os_thread = external hidden local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [49 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @merry_main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdout, align 8, !tbaa !5
  %2 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.8, ptr noundef null) #3
  %3 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %3, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %0
  %9 = getelementptr inbounds i8, ptr %3, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %0, %8
  %12 = phi ptr [ %10, %8 ], [ null, %0 ]
  %13 = getelementptr inbounds i8, ptr %3, i64 2
  %14 = load i8, ptr %13, align 2, !tbaa !14
  %15 = tail call zeroext i8 @merry_os_init(ptr noundef %5, ptr noundef %12, i64 noundef %7, i8 noundef zeroext %14) #3
  %16 = icmp eq i8 %15, 1
  br i1 %16, label %49, label %17

17:                                               ; preds = %11
  store i8 1, ptr @_os_init, align 1, !tbaa !15
  %18 = load ptr, ptr @cmd_opts, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  %20 = load i8, ptr %19, align 8, !tbaa !16
  %21 = icmp eq i8 %20, 1
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %18, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  tail call void @merry_os_produce_dump(ptr noundef %24) #3
  br label %25

25:                                               ; preds = %22, %17
  %26 = tail call ptr (...) @merry_thread_init() #3
  store ptr %26, ptr @os_thread, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.9) #4
  br label %49

31:                                               ; preds = %25
  %32 = load ptr, ptr @stdout, align 8, !tbaa !5
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.10, ptr noundef null) #3
  %34 = load ptr, ptr @os_thread, align 8, !tbaa !5
  %35 = tail call zeroext i8 @merry_create_thread(ptr noundef %34, ptr noundef nonnull @merry_os_start_vm, ptr noundef null) #3
  %36 = icmp eq i8 %35, 1
  br i1 %36, label %37, label %40

37:                                               ; preds = %31
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.11) #4
  br label %49

40:                                               ; preds = %31
  %41 = load ptr, ptr @stdout, align 8, !tbaa !5
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.12, ptr noundef null) #3
  %43 = load ptr, ptr @stdout, align 8, !tbaa !5
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.13, ptr noundef null) #3
  %45 = load ptr, ptr @os_thread, align 8, !tbaa !5
  %46 = tail call zeroext i8 @merry_thread_join(ptr noundef %45, ptr noundef null) #3
  %47 = tail call i64 (...) @merry_os_get_ret() #3
  %48 = trunc i64 %47 to i32
  br label %49

49:                                               ; preds = %11, %40, %37, %28
  %.0 = phi i32 [ 1, %28 ], [ 1, %37 ], [ %48, %40 ], [ 1, %11 ]
  ret i32 %.0
}

declare zeroext i8 @merry_os_init(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

declare void @merry_os_produce_dump(ptr noundef) local_unnamed_addr #2

declare ptr @merry_thread_init(...) local_unnamed_addr #2

declare zeroext i8 @merry_create_thread(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @merry_os_start_vm(ptr noundef) #2

declare zeroext i8 @merry_thread_join(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i64 @merry_os_get_ret(...) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #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 = { nounwind }
attributes #4 = { cold 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, !6, i64 8}
!10 = !{!"MerryCLP", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 8, !6, i64 16, !7, i64 24, !6, i64 32, !11, i64 40, !7, i64 48, !6, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 40}
!13 = !{!10, !6, i64 32}
!14 = !{!10, !7, i64 2}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !7, i64 24}
!17 = !{!10, !6, i64 16}


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