; LLVM IR from wgtdkp/wgtcc :: test (struct)

; 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.foo_t.2 = type { %union.anon, i8, i8 }
%union.anon = type { i8 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@__const.test4.foo = external hidden unnamed_addr constant %struct.foo_t.2, align 1
@__func__.test4 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @test4() #3 {
  %1 = alloca %struct.foo_t.2, align 1
  call void @llvm.lifetime.start.p0(i64 3, ptr %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 @__const.test4.foo, i64 3, i1 false)
  %2 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 0
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = sext i8 %3 to i32
  %5 = icmp ne i32 %4, 1
  br i1 %5, label %6, label %12

6:                                                ; preds = %0
  %7 = load ptr, ptr @stderr, align 8, !tbaa !8
  %8 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 0
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = sext i8 %9 to i32
  %11 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test4, i32 noundef 381, i32 noundef %10, i32 noundef 1) #4
  br label %12

12:                                               ; preds = %6, %0
  %13 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 0
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 1
  br i1 %16, label %17, label %23

17:                                               ; preds = %12
  %18 = load ptr, ptr @stderr, align 8, !tbaa !8
  %19 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 0
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test4, i32 noundef 382, i32 noundef %21, i32 noundef 1) #4
  br label %23

23:                                               ; preds = %17, %12
  %24 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 1
  %25 = load i8, ptr %24, align 1, !tbaa !10
  %26 = sext i8 %25 to i32
  %27 = icmp ne i32 %26, 2
  br i1 %27, label %28, label %34

28:                                               ; preds = %23
  %29 = load ptr, ptr @stderr, align 8, !tbaa !8
  %30 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 1
  %31 = load i8, ptr %30, align 1, !tbaa !10
  %32 = sext i8 %31 to i32
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test4, i32 noundef 383, i32 noundef %32, i32 noundef 2) #4
  br label %34

34:                                               ; preds = %28, %23
  %35 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 2
  %36 = load i8, ptr %35, align 1, !tbaa !12
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 3
  br i1 %38, label %39, label %45

39:                                               ; preds = %34
  %40 = load ptr, ptr @stderr, align 8, !tbaa !8
  %41 = getelementptr inbounds %struct.foo_t.2, ptr %1, i32 0, i32 2
  %42 = load i8, ptr %41, align 1, !tbaa !12
  %43 = sext i8 %42 to i32
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test4, i32 noundef 384, i32 noundef %43, i32 noundef 3) #4
  br label %45

45:                                               ; preds = %39, %34
  call void @llvm.lifetime.end.p0(i64 3, ptr %1) #4
  ret void
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 1}
!11 = !{!"", !6, i64 0, !6, i64 1, !6, i64 2}
!12 = !{!11, !6, i64 2}


; 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.foo_t.2 = type { %union.anon, i8, i8 }
%union.anon = type { i8 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@__const.test4.foo = external hidden unnamed_addr constant %struct.foo_t.2, align 1
@__func__.test4 = external hidden unnamed_addr constant [6 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: nofree nounwind uwtable
define dso_local void @test4() local_unnamed_addr #1 {
  %.sroa.0.0.copyload = load i8, ptr @__const.test4.foo, align 1
  %.sroa.7.0.copyload = load i8, ptr getelementptr inbounds (i8, ptr @__const.test4.foo, i64 1), align 1
  %.sroa.9.0.copyload = load i8, ptr getelementptr inbounds (i8, ptr @__const.test4.foo, i64 2), align 1
  %.not = icmp eq i8 %.sroa.0.0.copyload, 1
  br i1 %.not, label %.critedge, label %1

1:                                                ; preds = %0
  %2 = sext i8 %.sroa.0.0.copyload to i32
  %3 = load ptr, ptr @stderr, align 8, !tbaa !5
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %3, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test4, i32 noundef 381, i32 noundef %2, i32 noundef 1) #2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test4, i32 noundef 382, i32 noundef %2, i32 noundef 1) #2
  br label %.critedge

.critedge:                                        ; preds = %0, %1
  %.not8 = icmp eq i8 %.sroa.7.0.copyload, 2
  br i1 %.not8, label %11, label %7

7:                                                ; preds = %.critedge
  %8 = sext i8 %.sroa.7.0.copyload to i32
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test4, i32 noundef 383, i32 noundef %8, i32 noundef 2) #2
  br label %11

11:                                               ; preds = %7, %.critedge
  %.not9 = icmp eq i8 %.sroa.9.0.copyload, 3
  br i1 %.not9, label %16, label %12

12:                                               ; preds = %11
  %13 = sext i8 %.sroa.9.0.copyload to i32
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test4, i32 noundef 384, i32 noundef %13, i32 noundef 3) #2
  br label %16

16:                                               ; preds = %12, %11
  ret void
}

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 = { nofree 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 = { 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"}


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