; LLVM IR from pupnp/pupnp :: upnp/generator (generator)

; 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.s_Class = type { ptr, i32, ptr, ptr, ptr }

@my_classes = external hidden global [13 x %struct.s_Class], align 16
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr @my_classes, ptr %8, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 13, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %13)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %77, %2
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %80

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.s_Class, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.s_Class, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = call noalias ptr @fopen(ptr noundef %25, ptr noundef @.str.1)
  store ptr %26, ptr %9, align 8, !tbaa !9
  %27 = load ptr, ptr %9, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %19
  store i32 4, ptr %10, align 4
  br label %74

30:                                               ; preds = %19
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.s_Class, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.s_Class, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %36)
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.s_Class, ptr %39, i64 %41
  %43 = call i32 @write_header(ptr noundef %38, ptr noundef %42)
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = call i32 @fclose(ptr noundef %44)
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.s_Class, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.s_Class, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = call noalias ptr @fopen(ptr noundef %52, ptr noundef @.str.1)
  store ptr %53, ptr %9, align 8, !tbaa !9
  %54 = load ptr, ptr %9, align 8, !tbaa !9
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %30
  store i32 4, ptr %10, align 4
  br label %74

57:                                               ; preds = %30
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.s_Class, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.s_Class, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %63)
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.s_Class, ptr %66, i64 %68
  %70 = call i32 @write_source(ptr noundef %65, ptr noundef %69)
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = call i32 @fclose(ptr noundef %71)
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %10, align 4
  br label %74

74:                                               ; preds = %57, %56, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %75 = load i32, ptr %10, align 4
  switch i32 %75, label %82 [
    i32 0, label %76
    i32 4, label %77
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %74
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !14

80:                                               ; preds = %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %81 = load i32, ptr %3, align 4
  ret i32 %81

82:                                               ; preds = %74
  unreachable
}

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

declare i32 @printf(ptr noundef, ...) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @write_header(ptr noundef, ptr noundef) #0

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @write_source(ptr noundef, ptr noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"s_Class", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!12, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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.s_Class = type { ptr, i32, ptr, ptr, ptr }

@my_classes = external hidden global [13 x %struct.s_Class], align 16
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 13)
  br label %4

4:                                                ; preds = %2, %24
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %24 ]
  %5 = getelementptr inbounds %struct.s_Class, ptr @my_classes, i64 %indvars.iv
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call noalias ptr @fopen(ptr noundef %7, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %24, label %9

9:                                                ; preds = %4
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %10)
  %12 = tail call i32 @write_header(ptr noundef nonnull %8, ptr noundef nonnull %5)
  %13 = tail call i32 @fclose(ptr noundef nonnull %8)
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %15 = getelementptr inbounds i8, ptr %5, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = tail call noalias ptr @fopen(ptr noundef %16, ptr noundef nonnull @.str.1)
  %.not26 = icmp eq ptr %17, null
  br i1 %.not26, label %24, label %18

18:                                               ; preds = %9
  %19 = load ptr, ptr %15, align 8, !tbaa !11
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %19)
  %21 = tail call i32 @write_source(ptr noundef nonnull %17, ptr noundef nonnull %5)
  %22 = tail call i32 @fclose(ptr noundef nonnull %17)
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %24

24:                                               ; preds = %9, %4, %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 13
  br i1 %exitcond.not, label %25, label %4, !llvm.loop !12

25:                                               ; preds = %24
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @write_header(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @write_source(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { 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" }

!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, !7, i64 32}
!6 = !{!"s_Class", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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