; 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.anon.5 = type { i8, i8 }
%struct.foo_t.3 = type { %union.anon.4, i8, i8 }
%union.anon.4 = type { i16 }

@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.test5.foo = external hidden unnamed_addr constant { { %struct.anon.5 }, i8, i8 }, align 2
@__func__.test5 = 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 @test5() #3 {
  %1 = alloca %struct.foo_t.3, align 2
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %1, ptr align 2 @__const.test5.foo, i64 4, i1 false)
  %2 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 0
  %3 = load i16, ptr %2, align 2, !tbaa !5
  %4 = sext i16 %3 to i32
  %5 = icmp ne i32 %4, 257
  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.3, ptr %1, i32 0, i32 0
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = sext i16 %9 to i32
  %11 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test5, i32 noundef 402, i32 noundef %10, i32 noundef 257) #4
  br label %12

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

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

25:                                               ; preds = %18, %12
  %26 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 0
  %27 = getelementptr inbounds %struct.anon.5, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %38

31:                                               ; preds = %25
  %32 = load ptr, ptr @stderr, align 8, !tbaa !8
  %33 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 0
  %34 = getelementptr inbounds %struct.anon.5, ptr %33, i32 0, i32 1
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = sext i8 %35 to i32
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test5, i32 noundef 404, i32 noundef %36, i32 noundef 1) #4
  br label %38

38:                                               ; preds = %31, %25
  %39 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 1
  %40 = load i8, ptr %39, align 2, !tbaa !10
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %41, 2
  br i1 %42, label %43, label %49

43:                                               ; preds = %38
  %44 = load ptr, ptr @stderr, align 8, !tbaa !8
  %45 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 1
  %46 = load i8, ptr %45, align 2, !tbaa !10
  %47 = sext i8 %46 to i32
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test5, i32 noundef 405, i32 noundef %47, i32 noundef 2) #4
  br label %49

49:                                               ; preds = %43, %38
  %50 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 2
  %51 = load i8, ptr %50, align 1, !tbaa !12
  %52 = sext i8 %51 to i32
  %53 = icmp ne i32 %52, 3
  br i1 %53, label %54, label %60

54:                                               ; preds = %49
  %55 = load ptr, ptr @stderr, align 8, !tbaa !8
  %56 = getelementptr inbounds %struct.foo_t.3, ptr %1, i32 0, i32 2
  %57 = load i8, ptr %56, align 1, !tbaa !12
  %58 = sext i8 %57 to i32
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @__func__.test5, i32 noundef 406, i32 noundef %58, i32 noundef 3) #4
  br label %60

60:                                               ; preds = %54, %49
  call void @llvm.lifetime.end.p0(i64 4, 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 2}
!11 = !{!"", !6, i64 0, !6, i64 2, !6, i64 3}
!12 = !{!11, !6, i64 3}


; 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.anon.5 = type { i8, 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.test5.foo = external hidden unnamed_addr constant { { %struct.anon.5 }, i8, i8 }, align 2
@__func__.test5 = 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 @test5() local_unnamed_addr #1 {
  %.sroa.0.0.copyload = load i16, ptr @__const.test5.foo, align 2
  %.sroa.0.sroa.7.0.extract.shift = lshr i16 %.sroa.0.0.copyload, 8
  %.sroa.0.sroa.7.0.extract.trunc = zext nneg i16 %.sroa.0.sroa.7.0.extract.shift to i32
  %.sroa.9.0.copyload = load i8, ptr getelementptr inbounds (i8, ptr @__const.test5.foo, i64 2), align 2
  %.sroa.11.0.copyload = load i8, ptr getelementptr inbounds (i8, ptr @__const.test5.foo, i64 3), align 1
  %.not = icmp eq i16 %.sroa.0.0.copyload, 257
  br i1 %.not, label %.thread26, label %1

1:                                                ; preds = %0
  %.sroa.0.sroa.0.0.extract.trunc = zext i16 %.sroa.0.0.copyload to i32
  %2 = sext i16 %.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__.test5, i32 noundef 402, i32 noundef %2, i32 noundef 257) #2
  %sext = shl i32 %.sroa.0.sroa.0.0.extract.trunc, 24
  %.not19 = icmp eq i32 %sext, 16777216
  br i1 %.not19, label %9, label %5

5:                                                ; preds = %1
  %6 = ashr exact i32 %sext, 24
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test5, i32 noundef 403, i32 noundef %6, i32 noundef 1) #2
  br label %9

9:                                                ; preds = %5, %1
  %.not21 = icmp eq i16 %.sroa.0.sroa.7.0.extract.shift, 1
  br i1 %.not21, label %.thread26, label %10

10:                                               ; preds = %9
  %sext20 = shl nuw i32 %.sroa.0.sroa.7.0.extract.trunc, 24
  %11 = ashr exact i32 %sext20, 24
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test5, i32 noundef 404, i32 noundef %11, i32 noundef 1) #2
  br label %.thread26

.thread26:                                        ; preds = %0, %10, %9
  %.not22 = icmp eq i8 %.sroa.9.0.copyload, 2
  br i1 %.not22, label %18, label %14

14:                                               ; preds = %.thread26
  %15 = sext i8 %.sroa.9.0.copyload to i32
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test5, i32 noundef 405, i32 noundef %15, i32 noundef 2) #2
  br label %18

18:                                               ; preds = %14, %.thread26
  %.not23 = icmp eq i8 %.sroa.11.0.copyload, 3
  br i1 %.not23, label %23, label %19

19:                                               ; preds = %18
  %20 = sext i8 %.sroa.11.0.copyload to i32
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.test5, i32 noundef 406, i32 noundef %20, i32 noundef 3) #2
  br label %23

23:                                               ; preds = %19, %18
  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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass