; LLVM IR from greensoftwarelab/Energy-Languages :: C/chameneos-redux/chameneosredux.gcc-5 (join_and_output)

; 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.chameneos_t = type { i32, i64, i64, i32, ptr, ptr, i64, i32, i64, %union.pthread_attr_t }
%union.pthread_attr_t = type { i64, [48 x i8] }

@color_names = external dso_local global [3 x ptr], align 16
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @cache_aligned_free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @spell_number(i64 noundef) #1

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

11:                                               ; preds = %24, %4
  %12 = load i64, ptr %10, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ne i64 %12, %13
  br i1 %14, label %15, label %27

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = getelementptr inbounds i32, ptr %16, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [3 x ptr], ptr @color_names, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.24, ptr noundef %22)
  br label %24

24:                                               ; preds = %15
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %10, align 8, !tbaa !9
  br label %11, !llvm.loop !13

27:                                               ; preds = %11
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %47, %27
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = icmp ne i64 %30, %31
  br i1 %32, label %33, label %50

33:                                               ; preds = %29
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.chameneos_t, ptr %37, i32 0, i32 8
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = call i32 @pthread_join(i64 noundef %39, ptr noundef null)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.chameneos_t, ptr %44, i32 0, i32 9
  %46 = call i32 @pthread_attr_destroy(ptr noundef %45) #4
  br label %47

47:                                               ; preds = %33
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %10, align 8, !tbaa !9
  br label %29, !llvm.loop !17

50:                                               ; preds = %29
  store i64 0, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %82, %50
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = icmp ne i64 %52, %53
  br i1 %54, label %55, label %85

55:                                               ; preds = %51
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load i64, ptr %10, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.chameneos_t, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !18
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = add i64 %62, %61
  store i64 %63, ptr %9, align 8, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = getelementptr inbounds ptr, ptr %64, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.chameneos_t, ptr %67, i32 0, i32 1
  %69 = load i64, ptr %68, align 8, !tbaa !18
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.chameneos_t, ptr %73, i32 0, i32 2
  %75 = load i64, ptr %74, align 8, !tbaa !19
  %76 = call ptr @spell_number(i64 noundef %75)
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, i64 noundef %69, ptr noundef %76)
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load i64, ptr %10, align 8, !tbaa !9
  %80 = getelementptr inbounds ptr, ptr %78, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  call void @cache_aligned_free(ptr noundef %81)
  br label %82

82:                                               ; preds = %55
  %83 = load i64, ptr %10, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %10, align 8, !tbaa !9
  br label %51, !llvm.loop !20

85:                                               ; preds = %51
  %86 = load i64, ptr %9, align 8, !tbaa !9
  %87 = call ptr @spell_number(i64 noundef %86)
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.26, ptr noundef %87)
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  call void @cache_aligned_free(ptr noundef %89)
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  call void @cache_aligned_free(ptr noundef %90)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

declare i32 @pthread_join(i64 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @pthread_attr_destroy(ptr noundef) #3

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


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

@color_names = external dso_local local_unnamed_addr global [3 x ptr], align 16
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @cache_aligned_free(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @spell_number(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @join_and_output(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not30 = icmp eq i64 %1, 0
  br i1 %.not30, label %.preheader.thread, label %.lr.ph

.preheader.thread:                                ; preds = %4
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %._crit_edge40

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.031 = phi i64 [ %12, %.lr.ph ], [ 0, %4 ]
  %6 = getelementptr inbounds i32, ptr %0, i64 %.031
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [3 x ptr], ptr @color_names, i64 0, i64 %8
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.24, ptr noundef %10)
  %12 = add nuw i64 %.031, 1
  %.not = icmp eq i64 %12, %1
  br i1 %.not, label %.lr.ph35.preheader, label %.lr.ph, !llvm.loop !11

.lr.ph35.preheader:                               ; preds = %.lr.ph
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %.lr.ph35

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.lr.ph35
  %.133 = phi i64 [ %22, %.lr.ph35 ], [ 0, %.lr.ph35.preheader ]
  %14 = getelementptr inbounds ptr, ptr %3, i64 %.133
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 64
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = tail call i32 @pthread_join(i64 noundef %17, ptr noundef null) #4
  %19 = load ptr, ptr %14, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 72
  %21 = tail call i32 @pthread_attr_destroy(ptr noundef nonnull %20) #4
  %22 = add nuw i64 %.133, 1
  %.not28 = icmp eq i64 %22, %1
  br i1 %.not28, label %.lr.ph39, label %.lr.ph35, !llvm.loop !16

.lr.ph39:                                         ; preds = %.lr.ph35, %.lr.ph39
  %.238 = phi i64 [ %33, %.lr.ph39 ], [ 0, %.lr.ph35 ]
  %.02637 = phi i64 [ %27, %.lr.ph39 ], [ 0, %.lr.ph35 ]
  %23 = getelementptr inbounds ptr, ptr %3, i64 %.238
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !17
  %27 = add i64 %26, %.02637
  %28 = getelementptr inbounds i8, ptr %24, i64 16
  %29 = load i64, ptr %28, align 8, !tbaa !18
  %30 = tail call ptr @spell_number(i64 noundef %29)
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i64 noundef %26, ptr noundef %30)
  %32 = load ptr, ptr %23, align 8, !tbaa !9
  tail call void @cache_aligned_free(ptr noundef %32)
  %33 = add nuw i64 %.238, 1
  %.not29 = icmp eq i64 %33, %1
  br i1 %.not29, label %._crit_edge40, label %.lr.ph39, !llvm.loop !19

._crit_edge40:                                    ; preds = %.lr.ph39, %.preheader.thread
  %.026.lcssa = phi i64 [ 0, %.preheader.thread ], [ %27, %.lr.ph39 ]
  %34 = tail call ptr @spell_number(i64 noundef %.026.lcssa)
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26, ptr noundef %34)
  tail call void @cache_aligned_free(ptr noundef %3)
  tail call void @cache_aligned_free(ptr noundef %2)
  ret void
}

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @pthread_attr_destroy(ptr noundef) local_unnamed_addr #3

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" }
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 "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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 64}
!14 = !{!"chameneos_t", !6, i64 0, !15, i64 8, !15, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !15, i64 48, !6, i64 56, !15, i64 64, !7, i64 72}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !12}
!17 = !{!14, !15, i64 8}
!18 = !{!14, !15, i64 16}
!19 = distinct !{!19, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass