#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*/ 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;
  }
  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    1182 <main+0x42>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fa <main+0xba>
mov    $0x0,%al
call   1060 <DidMainRun@plt>
cmp    $0x0,%rax
je     11b6 <main+0x76>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fa <main+0xba>
mov    $0x0,%al
call   1050 <FromPkg@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
je     11f3 <main+0xb3>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fa <main+0xba>
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     116c <main+0x2c>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <DidMainRun@plt>
test   %rax,%rax
je     118c <main+0x4c>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
jmp    117c <main+0x3c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1050 <FromPkg@plt>
cmp    $0x400,%eax
je     1188 <main+0x48>
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%edi
lea    0xeb2(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1183 <main+0x43>

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"
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 %23
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 %23
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 %23
22: ; preds = %14
store i32 0, i32* %1
br label %23
23: ; preds = %22, %18, %11, %5
%24 = load i32, i32* %1
ret i32 %24
}

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"
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 %18
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 %18
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 %18
18: ; preds = %12, %15, %9, %3
%19 = phi i32 [ 2, %9 ], [ 2, %15 ], [ 2, %3 ], [ 0, %12 ]
ret i32 %19
}