; LLVM IR from freakout42/macrocalc :: mc/nro (nrocmd)

; 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.macros = type { [400 x ptr], i32, ptr, [80000 x i8], ptr, [200000 x i8] }

@mac = external global %struct.macros, align 8

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @putmac(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load i32, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 1), align 8, !tbaa !9
  %7 = icmp sge i32 %6, 400
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 -1, ptr %3, align 4
  br label %45

9:                                                ; preds = %2
  %10 = load ptr, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef %11) #3
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #3
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = icmp ugt ptr %17, getelementptr inbounds ([80000 x i8], ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 3), i64 0, i64 80000)
  br i1 %18, label %19, label %20

19:                                               ; preds = %9
  store i32 -1, ptr %3, align 4
  br label %45

20:                                               ; preds = %9
  %21 = load i32, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 1), align 8, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 1), align 8, !tbaa !9
  %23 = load ptr, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  %24 = load i32, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 1), align 8, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400 x ptr], ptr @mac, i64 0, i64 %25
  store ptr %23, ptr %26, align 8, !tbaa !5
  %27 = load ptr, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call ptr @strcpy(ptr noundef %27, ptr noundef %28) #4
  %30 = load ptr, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i64 @strlen(ptr noundef %31) #3
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call ptr @strcpy(ptr noundef %34, ptr noundef %35) #4
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call i64 @strlen(ptr noundef %37) #3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = call i64 @strlen(ptr noundef %39) #3
  %41 = add i64 %38, %40
  %42 = add i64 %41, 2
  %43 = load ptr, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  %44 = getelementptr inbounds i8, ptr %43, i64 %42
  store ptr %44, ptr getelementptr inbounds (%struct.macros, ptr @mac, i32 0, i32 2), align 8, !tbaa !12
  store i32 0, ptr %3, align 4
  br label %45

45:                                               ; preds = %20, %19, %8
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

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 willreturn memory(read) "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 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 willreturn memory(read) }
attributes #4 = { 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, !11, i64 3200}
!10 = !{!"macros", !7, i64 0, !11, i64 3200, !6, i64 3208, !7, i64 3216, !6, i64 83216, !7, i64 83224}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 3208}


; 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.macros = type { [400 x ptr], i32, ptr, [80000 x i8], ptr, [200000 x i8] }

@mac = external global %struct.macros, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @putmac(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @mac, i64 3200), align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 399
  br i1 %4, label %30, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @mac, i64 3208), align 8, !tbaa !11
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %8 = getelementptr inbounds i8, ptr %6, i64 %7
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %10 = getelementptr inbounds i8, ptr %8, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 1
  %12 = icmp ugt ptr %11, getelementptr inbounds (i8, ptr @mac, i64 83216)
  br i1 %12, label %30, label %13

13:                                               ; preds = %5
  %14 = add nsw i32 %3, 1
  store i32 %14, ptr getelementptr inbounds (i8, ptr @mac, i64 3200), align 8, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [400 x ptr], ptr @mac, i64 0, i64 %15
  store ptr %6, ptr %16, align 8, !tbaa !12
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @mac, i64 3208), align 8, !tbaa !11
  %18 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %17, ptr noundef nonnull dereferenceable(1) %0) #4
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @mac, i64 3208), align 8, !tbaa !11
  %20 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  %23 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %22, ptr noundef nonnull dereferenceable(1) %1) #4
  %24 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %25 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @mac, i64 3208), align 8, !tbaa !11
  %27 = getelementptr i8, ptr %26, i64 %24
  %28 = getelementptr i8, ptr %27, i64 %25
  %29 = getelementptr i8, ptr %28, i64 2
  store ptr %29, ptr getelementptr inbounds (i8, ptr @mac, i64 3208), align 8, !tbaa !11
  br label %30

30:                                               ; preds = %5, %2, %13
  %.0 = phi i32 [ 0, %13 ], [ -1, %2 ], [ -1, %5 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 nofree nounwind willreturn memory(argmem: read) "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 memory(readwrite, inaccessiblemem: none) 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 willreturn memory(read) }
attributes #4 = { 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, !9, i64 3200}
!6 = !{!"macros", !7, i64 0, !9, i64 3200, !10, i64 3208, !7, i64 3216, !10, i64 83216, !7, i64 83224}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !10, i64 3208}
!12 = !{!10, !10, i64 0}


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