; LLVM IR from aap/pdp6 :: tools (as6)

; 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.Additive = type { i32, %struct.Value, ptr }
%struct.Value = type { i64, i32 }
%struct.Sym = type { i64, i32, %union.anon, ptr }
%union.anon = type { %struct.Value }

@pass2 = external dso_local global i32, align 4
@dot = external dso_local global 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @updateext(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load i32, ptr @pass2, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %3
  store i32 1, ptr %8, align 4
  br label %70

15:                                               ; preds = %11
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %34

18:                                               ; preds = %15
  %19 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Additive, ptr %20, i32 0, i32 0
  store i32 1, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Additive, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr @dot, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Sym, ptr %24, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 8 %25, i64 16, i1 false), !tbaa.struct !15
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Sym, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Additive, ptr %29, i32 0, i32 2
  store ptr %28, ptr %30, align 8, !tbaa !19
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Sym, ptr %32, i32 0, i32 3
  store ptr %31, ptr %33, align 8, !tbaa !17
  br label %69

34:                                               ; preds = %15
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Value, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !20
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %52

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Value, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !21
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %39
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Sym, ptr %46, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %47, i64 16, i1 false), !tbaa.struct !15
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Sym, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr @dot, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Sym, ptr %50, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 8 %51, i64 16, i1 false), !tbaa.struct !15
  br label %68

52:                                               ; preds = %39, %34
  %53 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %53, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Additive, ptr %54, i32 0, i32 0
  store i32 0, ptr %55, align 8, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Additive, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr @dot, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Sym, ptr %58, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %57, ptr align 8 %59, i64 16, i1 false), !tbaa.struct !15
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Sym, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Additive, ptr %63, i32 0, i32 2
  store ptr %62, ptr %64, align 8, !tbaa !19
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Sym, ptr %66, i32 0, i32 3
  store ptr %65, ptr %67, align 8, !tbaa !17
  br label %68

68:                                               ; preds = %52, %44
  br label %69

69:                                               ; preds = %68, %18
  store i32 0, ptr %8, align 4
  br label %70

70:                                               ; preds = %69, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %71 = load i32, ptr %8, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

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

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"Additive", !10, i64 0, !13, i64 8, !6, i64 24}
!13 = !{!"Value", !14, i64 0, !10, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{i64 0, i64 8, !16, i64 8, i64 4, !9}
!16 = !{!14, !14, i64 0}
!17 = !{!18, !6, i64 32}
!18 = !{!"Sym", !14, i64 0, !10, i64 8, !7, i64 16, !6, i64 32}
!19 = !{!12, !6, i64 24}
!20 = !{!13, !14, i64 0}
!21 = !{!13, !10, i64 8}


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

@pass2 = external dso_local local_unnamed_addr global i32, align 4
@dot = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local void @updateext(ptr noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = load i32, ptr @pass2, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  %6 = icmp eq ptr %0, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %35, label %7

7:                                                ; preds = %3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %16, label %8

8:                                                ; preds = %7
  %9 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 1, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr @dot, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull align 8 dereferenceable(16) %12, i64 16, i1 false), !tbaa.struct !15
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %14, ptr %15, align 8, !tbaa !19
  store ptr %9, ptr %13, align 8, !tbaa !17
  br label %35

16:                                               ; preds = %7
  %17 = load i64, ptr %1, align 8, !tbaa !20
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !21
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %24, i64 16, i1 false), !tbaa.struct !15
  %25 = load ptr, ptr @dot, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, ptr noundef nonnull align 8 dereferenceable(16) %26, i64 16, i1 false), !tbaa.struct !15
  br label %35

27:                                               ; preds = %19, %16
  %28 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #3
  store i32 0, ptr %28, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  %30 = load ptr, ptr @dot, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %29, ptr noundef nonnull align 8 dereferenceable(16) %31, i64 16, i1 false), !tbaa.struct !15
  %32 = getelementptr inbounds i8, ptr %0, i64 32
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %28, i64 24
  store ptr %33, ptr %34, align 8, !tbaa !19
  store ptr %28, ptr %32, align 8, !tbaa !17
  br label %35

35:                                               ; preds = %8, %27, %23, %3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { mustprogress nofree nounwind willreturn 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 allocsize(0) }

!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, !6, i64 0}
!10 = !{!"Additive", !6, i64 0, !11, i64 8, !13, i64 24}
!11 = !{!"Value", !12, i64 0, !6, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{i64 0, i64 8, !16, i64 8, i64 4, !5}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !13, i64 32}
!18 = !{!"Sym", !12, i64 0, !6, i64 8, !7, i64 16, !13, i64 32}
!19 = !{!10, !13, i64 24}
!20 = !{!11, !12, i64 0}
!21 = !{!11, !6, i64 8}


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