// #target: macos-x64
// #debuginfo: yes
module test;
import std::io;

struct Ghh
{
	int a;
	int b;
	int c;
}
fn void main()
{
	int a = 111;
	int x = @atomic_load(a);
	int y = @atomic_load(a, RELAXED, true);
	@atomic_store(a, 123 + x);
	@atomic_store(a, 33 + y, RELAXED, true);
	io::printfn("%d", a);
}

/* #expect: test.ll
%.introspect = type { i8, i64, ptr, i64, i64, i64, [0 x i64] }
%any = type { ptr, i64 }

@"$ct.test.Ghh" = linkonce global %.introspect { i8 10, i64 0, ptr null, i64 12, i64 0, i64 3, [0 x i64] zeroinitializer }, align 8
@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@"$ct.int" = linkonce global %.introspect { i8 2, i64 0, ptr null, i64 4, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8

define void @test.main() #0 !dbg !8 {
entry:
  %a = alloca i32, align 4
  %x = alloca i32, align 4
  %y = alloca i32, align 4
  %value = alloca i32, align 4
  %value2 = alloca i32, align 4
  %varargslots = alloca [1 x %any], align 16
  %retparam = alloca i64, align 8
  store i32 111, ptr %a, align 4, !dbg !15
  %0 = load atomic i32, ptr %a seq_cst, align 4, !dbg !18
  store i32 %0, ptr %x, align 4, !dbg !18
  %1 = load atomic volatile i32, ptr %a monotonic, align 4, !dbg !24
  store i32 %1, ptr %y, align 4, !dbg !24
  %2 = load i32, ptr %x, align 4, !dbg !27
  %add = add i32 123, %2, !dbg !28
  store i32 %add, ptr %value, align 4
  %3 = load i32, ptr %value, align 4, !dbg !29
  store atomic i32 %3, ptr %a seq_cst, align 4, !dbg !29
  %4 = load i32, ptr %y, align 4, !dbg !32
  %add1 = add i32 33, %4, !dbg !33
  store i32 %add1, ptr %value2, align 4
  %5 = load i32, ptr %value2, align 4, !dbg !34
  store atomic volatile i32 %5, ptr %a monotonic, align 4, !dbg !34
  %6 = insertvalue %any undef, ptr %a, 0, !dbg !37
  %7 = insertvalue %any %6, i64 ptrtoint (ptr @"$ct.int" to i64), 1, !dbg !37
  store %any %7, ptr %varargslots, align 16, !dbg !37
  %8 = call i64 @std.io.printfn(ptr %retparam, ptr @.str, i64 2, ptr %varargslots, i64 1), !dbg !38
  ret void, !dbg !38
}

define i32 @main(i32 %0, ptr %1) #0 !dbg !39 {
entry:
  %.anon = alloca i32, align 4
  %.anon1 = alloca ptr, align 8
  %.anon2 = alloca i32, align 4
  %.anon3 = alloca ptr, align 8
  store i32 %0, ptr %.anon, align 4
  store ptr %1, ptr %.anon1, align 8
  %2 = load i32, ptr %.anon, align 4
  store i32 %2, ptr %.anon2, align 4
  %3 = load ptr, ptr %.anon1, align 8
  store ptr %3, ptr %.anon3, align 8
  call void @test.main(), !dbg !48
  ret i32 0, !dbg !51
}

declare extern_weak i64 @std.io.printfn(ptr, ptr, i64, ptr, i64) #0

declare i1 @llvm.expect.i1(i1, i1)

!llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
!llvm.dbg.cu = !{!6}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 2, !"Debug Info Version", i32 3}
!2 = !{i32 2, !"wchar_size", i32 4}
!3 = !{i32 4, !"PIC Level", i32 2}
!4 = !{i32 1, !"uwtable", i32 2}
!5 = !{i32 2, !"frame-pointer", i32 2}
!6 = distinct !DICompileUnit(language: DW_LANG_C11, file: !7, producer: "c3c", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
!7 = !DIFile(filename: "atomic_load_store_debug.c3"
!8 = distinct !DISubprogram(name: "main", linkageName: "test.main", scope: !7, file: !7, line: 10, type: !9, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !11)
!9 = !DISubroutineType(types: !10)
!10 = !{null}
!11 = !{}
!12 = !DILocalVariable(name: "a", scope: !8, file: !7, line: 12, type: !13, align: 32)
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !DILocation(line: 12, column: 6, scope: !8)
!15 = !DILocation(line: 12, column: 10, scope: !8)
!16 = !DILocalVariable(name: "x", scope: !8, file: !7, line: 13, type: !13, align: 32)
!17 = !DILocation(line: 13, column: 6, scope: !8)
!18 = !DILocation(
!19 = distinct !DISubprogram(name: "@atomic_load",
!20 = !DIFile(filename: "mem.c3",
!21 = !DILocation(line: 13, column: 10, scope: !8)
!22 = !DILocalVariable(name: "y", scope: !8, file: !7, line: 14, type: !13, align: 32)
!23 = !DILocation(line: 14, column: 6, scope: !8)
!24 = !DILocation(
!25 = distinct !DISubprogram(name: "@atomic_load", linkageName: "@atomic_load", scope: !20, file: !20
!26 = !DILocation(line: 14, column: 10, scope: !8)
!27 = !DILocation(line: 15, column: 25, scope: !8)
!28 = !DILocation(line: 15, column: 19, scope: !8)
!29 = !DILocation(
!30 = distinct !DISubprogram(name: "@atomic_store", linkageName: "@atomic_store", scope: !20, file: !20
!31 = !DILocation(line: 15, column: 2, scope: !8)
!32 = !DILocation(line: 16, column: 24, scope: !8)
!33 = !DILocation(line: 16, column: 19, scope: !8)
!34 = !DILocation(
!35 = distinct !DISubprogram(name: "@atomic_store", linkageName: "@atomic_store", scope: !20, file: !20
!36 = !DILocation(line: 16, column: 2, scope: !8)
!37 = !DILocation(line: 17, column: 20, scope: !8)
!38 = !DILocation(line: 17, column: 2, scope: !8)
!39 = distinct !DISubprogram(name: "_$main", linkageName: "main", scope: !7, file: !7, line: 10, type: !40, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !11)
!40 = !DISubroutineType(types: !41)
!41 = !{!13, !13, !42}
!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !43, size: 64, align: 64, dwarfAddressSpace: 0)
!43 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !44, size: 64, align: 64, dwarfAddressSpace: 0)
!44 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
!45 = !DILocalVariable(name: ".anon", arg: 1, scope: !39, file: !7, line: 10, type: !13)
!46 = !DILocation(line: 10, column: 9, scope: !39)
!47 = !DILocalVariable(name: ".anon", arg: 2, scope: !39, file: !7, line: 10, type: !42)
!48 = !DILocation(
!49 = distinct !DISubprogram(name: "@main_no_args", linkageName: "@main_no_args"
!50 = !DIFile(filename: "main_stub.c3"
!51 = !DILocation(