; LLVM IR from parallella/pal :: tests/runtest.epiphany (main)

; 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.status = type { i32, i32, i32, i32 }
%struct.p_mem_t = type { ptr, i64, ptr, i32, ptr, ptr }

@__const.main.status = external hidden unnamed_addr constant %struct.status, align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; 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 %struct.p_mem_t, align 8
  %9 = alloca %struct.p_mem_t, align 8
  %10 = alloca [1024 x i8], align 16
  %11 = alloca %struct.status, align 1
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca %struct.p_mem_t, align 8
  %16 = alloca %struct.p_mem_t, align 8
  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) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 1024, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 1024, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %11, ptr align 1 @__const.main.status, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 2
  br i1 %18, label %19, label %21

19:                                               ; preds = %2
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  call void @usage(ptr noundef %20)
  br label %21

21:                                               ; preds = %19, %2
  %22 = call ptr @p_init(i32 noundef 1, i32 noundef 0)
  store ptr %22, ptr %12, align 8, !tbaa !9
  %23 = load ptr, ptr %12, align 8, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %24, i64 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = call ptr @p_load(ptr noundef %23, ptr noundef %26, i32 noundef 0)
  store ptr %27, ptr %13, align 8, !tbaa !9
  %28 = load ptr, ptr %12, align 8, !tbaa !9
  %29 = call ptr @p_open(ptr noundef %28, i32 noundef 0, i32 noundef 1)
  store ptr %29, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %15) #5
  %30 = load ptr, ptr %12, align 8, !tbaa !9
  call void @p_map(ptr dead_on_unwind writable sret(%struct.p_mem_t) align 8 %15, ptr noundef %30, i64 noundef 2401239040, i64 noundef 16)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %15, i64 48, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 48, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %16) #5
  %31 = load ptr, ptr %12, align 8, !tbaa !9
  call void @p_map(ptr dead_on_unwind writable sret(%struct.p_mem_t) align 8 %16, ptr noundef %31, i64 noundef 2402287616, i64 noundef 1024)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %16, i64 48, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 48, ptr %16) #5
  %32 = call i64 @p_write(ptr noundef %8, ptr noundef %11, i64 noundef 0, i64 noundef 16, i32 noundef 0)
  %33 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %34 = call i64 @p_write(ptr noundef %9, ptr noundef %33, i64 noundef 0, i64 noundef 1024, i32 noundef 0)
  %35 = load ptr, ptr %13, align 8, !tbaa !9
  %36 = load ptr, ptr %14, align 8, !tbaa !9
  %37 = call i32 @p_run(ptr noundef %35, ptr noundef @.str.1, ptr noundef %36, i32 noundef 0, i32 noundef 1, i32 noundef 0, ptr noundef null, i32 noundef 0)
  store i32 %37, ptr %7, align 4, !tbaa !5
  %38 = call i64 @p_read(ptr noundef %8, ptr noundef %11, i64 noundef 0, i64 noundef 16, i32 noundef 0)
  %39 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %40 = call i64 @p_read(ptr noundef %9, ptr noundef %39, i64 noundef 0, i64 noundef 1024, i32 noundef 0)
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %21
  br label %47

44:                                               ; preds = %21
  %45 = getelementptr inbounds %struct.status, ptr %11, i32 0, i32 2
  %46 = load i32, ptr %45, align 1, !tbaa !14
  br label %47

47:                                               ; preds = %44, %43
  %48 = phi i32 [ 99, %43 ], [ %46, %44 ]
  store i32 %48, ptr %6, align 4, !tbaa !5
  %49 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %49)
  %51 = load ptr, ptr %14, align 8, !tbaa !9
  %52 = call i32 @p_close(ptr noundef %51)
  %53 = load ptr, ptr %12, align 8, !tbaa !9
  %54 = call i32 @p_finalize(ptr noundef %53)
  %55 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  ret i32 %55
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare ptr @p_init(i32 noundef, i32 noundef) #4

declare ptr @p_load(ptr noundef, ptr noundef, i32 noundef) #4

declare ptr @p_open(ptr noundef, i32 noundef, i32 noundef) #4

declare void @p_map(ptr dead_on_unwind writable sret(%struct.p_mem_t) align 8, ptr noundef, i64 noundef, i64 noundef) #4

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

declare i64 @p_write(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) #4

declare i32 @p_run(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #4

declare i64 @p_read(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) #4

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

declare i32 @p_close(ptr noundef) #4

declare i32 @p_finalize(ptr noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 = !{i64 0, i64 8, !9, i64 8, i64 8, !12, i64 16, i64 8, !9, i64 24, i64 4, !5, i64 32, i64 8, !9, i64 40, i64 8, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"status", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}


; 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.status = type { i32, i32, i32, i32 }
%struct.p_mem_t = type { ptr, i64, ptr, i32, ptr, ptr }

@__const.main.status = external hidden unnamed_addr constant %struct.status, align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.p_mem_t, align 8
  %4 = alloca %struct.p_mem_t, align 8
  %5 = alloca [1024 x i8], align 16
  %6 = alloca %struct.status, align 1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %5, i8 0, i64 1024, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %6, ptr noundef nonnull align 1 dereferenceable(16) @__const.main.status, i64 16, i1 false)
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %8, label %7

7:                                                ; preds = %2
  tail call void @usage(ptr noundef %1)
  br label %8

8:                                                ; preds = %7, %2
  %9 = tail call ptr @p_init(i32 noundef 1, i32 noundef 0) #6
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = tail call ptr @p_load(ptr noundef %9, ptr noundef %11, i32 noundef 0) #6
  %13 = tail call ptr @p_open(ptr noundef %9, i32 noundef 0, i32 noundef 1) #6
  call void @p_map(ptr dead_on_unwind nonnull writable sret(%struct.p_mem_t) align 8 %3, ptr noundef %9, i64 noundef 2401239040, i64 noundef 16) #6
  call void @p_map(ptr dead_on_unwind nonnull writable sret(%struct.p_mem_t) align 8 %4, ptr noundef %9, i64 noundef 2402287616, i64 noundef 1024) #6
  %14 = call i64 @p_write(ptr noundef nonnull %3, ptr noundef nonnull %6, i64 noundef 0, i64 noundef 16, i32 noundef 0) #6
  %15 = call i64 @p_write(ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef 0, i64 noundef 1024, i32 noundef 0) #6
  %16 = call i32 @p_run(ptr noundef %12, ptr noundef nonnull @.str.1, ptr noundef %13, i32 noundef 0, i32 noundef 1, i32 noundef 0, ptr noundef null, i32 noundef 0) #6
  %17 = call i64 @p_read(ptr noundef nonnull %3, ptr noundef nonnull %6, i64 noundef 0, i64 noundef 16, i32 noundef 0) #6
  %18 = call i64 @p_read(ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef 0, i64 noundef 1024, i32 noundef 0) #6
  %.not12 = icmp eq i32 %16, 0
  %19 = getelementptr inbounds i8, ptr %6, i64 8
  %20 = load i32, ptr %19, align 1
  %21 = select i1 %.not12, i32 %20, i32 99
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %5)
  %23 = call i32 @p_close(ptr noundef %13) #6
  %24 = call i32 @p_finalize(ptr noundef %9) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #6
  ret i32 %21
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress 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) #3

declare ptr @p_init(i32 noundef, i32 noundef) local_unnamed_addr #4

declare ptr @p_load(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare ptr @p_open(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

declare void @p_map(ptr dead_on_unwind writable sret(%struct.p_mem_t) align 8, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #4

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

declare i64 @p_write(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

declare i32 @p_run(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i64 @p_read(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

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

declare i32 @p_close(ptr noundef) local_unnamed_addr #4

declare i32 @p_finalize(ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 #6 = { 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,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass