#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ CheckArgs();
int /*<<< orphan*/ DidInitRun();
scalar_t__ DidMainRun();
int FromPkg();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  int32_t res;
  if (!DidInitRun()) {
    fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
    return 2;
  }
  if (DidMainRun()) {
    fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
    return 2;
  }
  res = FromPkg();
  if (res != 1024) {
    fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
    return 2;
  }
  CheckArgs();
  fprintf(stderr, "PASS\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <DidInitRun@plt>
cmp    $0x0,%eax
jne    1192 <main+0x42>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1228 <main+0xd8>
mov    $0x0,%al
call   1070 <DidMainRun@plt>
cmp    $0x0,%rax
je     11c6 <main+0x76>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1228 <main+0xd8>
mov    $0x0,%al
call   1050 <FromPkg@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
je     1203 <main+0xb3>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1228 <main+0xd8>
mov    $0x0,%al
call   1060 <CheckArgs@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <DidInitRun@plt>
test   %eax,%eax
je     117a <main+0x2a>
xor    %eax,%eax
call   1070 <DidMainRun@plt>
test   %rax,%rax
je     119a <main+0x4a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
jmp    118a <main+0x3a>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <FromPkg@plt>
cmp    $0x400,%eax
jne    11ca <main+0x7a>
xor    %eax,%eax
call   1060 <CheckArgs@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1196 <main+0x46>
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%edi
lea    0xe82(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1191 <main+0x41>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR: buildmode=c-archive init should run\0A\00"
@.str.1 = [48 x i8] c"ERROR: buildmode=c-archive should not run main\0A\00"
@.str.2 = [32 x i8] c"ERROR: FromPkg()=%d, want 1024\0A\00"
@.str.3 = [6 x i8] c"PASS\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @DidInitRun()
%4 = icmp ne i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %26
8: ; preds = %0
%9 = call i64 (...) @DidMainRun()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %26
14: ; preds = %8
%15 = call i32 (...) @FromPkg()
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 1024
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 2, i32* %1
br label %26
22: ; preds = %14
%23 = call i32 (...) @CheckArgs()
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %26
26: ; preds = %22, %18, %11, %5
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR: buildmode=c-archive init should run\0A\00"
@.str.1 = [48 x i8] c"ERROR: buildmode=c-archive should not run main\0A\00"
@.str.2 = [32 x i8] c"ERROR: FromPkg()=%d, want 1024\0A\00"
@.str.3 = [6 x i8] c"PASS\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @DidInitRun()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %22
6: ; preds = %0
%7 = tail call i64 (...) @DidMainRun()
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %6
%13 = tail call i32 (...) @FromPkg()
%14 = icmp eq i32 %13, 1024
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %22
18: ; preds = %12
%19 = tail call i32 (...) @CheckArgs()
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %18, %15, %9, %3
%23 = phi i32 [ 2, %9 ], [ 2, %15 ], [ 0, %18 ], [ 2, %3 ]
ret i32 %23
}