#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 */

/* Variables and functions */
int /*<<< orphan*/ copy_lowcore_64();
int /*<<< orphan*/ free_page(unsigned long);
unsigned long get_zeroed_page();
int /*<<< orphan*/ memcpy(void *, void *, int);
int sigp(int, int, int /*<<< orphan*/, void *);
unsigned short stap();
void store_status(void) {
  unsigned short current_cpu;
  unsigned long page;
  int addr, cc;
  page = get_zeroed_page();
  memcpy((void *)page, (void *)0x1000, 4096);
  current_cpu = stap();
  copy_lowcore_64();
  for (addr = 0; addr < 1000; addr++) {
    if (addr == current_cpu)
      continue;
    do {
      cc = sigp(addr, 9, 0, ((void *)0));
    } while (cc == 2);
    if (cc != 0)
      continue;
    copy_lowcore_64();
  }
  memcpy((void *)0x1000, (void *)page, 4096);
  free_page(page);
}


x86 assembly (clang, -O0):
<store_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <get_zeroed_page@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
mov    $0x1000,%edx
call   1050 <memcpy@plt>
mov    $0x0,%al
call   1030 <stap@plt>
mov    %ax,-0x2(%rbp)
mov    $0x0,%al
call   1080 <copy_lowcore_64@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1209 <store_status+0xa9>
mov    -0x14(%rbp),%eax
movzwl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jne    11c0 <store_status+0x60>
jmp    11fb <store_status+0x9b>
jmp    11c5 <store_status+0x65>
mov    -0x14(%rbp),%edi
mov    $0x9,%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <sigp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
je     11c5 <store_status+0x65>
cmpl   $0x0,-0x18(%rbp)
je     11f4 <store_status+0x94>
jmp    11fb <store_status+0x9b>
mov    $0x0,%al
call   1080 <copy_lowcore_64@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <store_status+0x3f>
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edi
mov    $0x1000,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free_page@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_status>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <get_zeroed_page@plt>
mov    %rax,%r14
mov    $0x1000,%esi
mov    %rax,%rdi
mov    $0x1000,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
call   1030 <stap@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <copy_lowcore_64@plt>
movzwl %bp,%ebx
xor    %ebp,%ebp
jmp    11ab <store_status+0x4b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x3e8,%ebp
je     11d2 <store_status+0x72>
cmp    %ebx,%ebp
je     11a0 <store_status+0x40>
nop
mov    %ebp,%edi
mov    $0x9,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <sigp@plt>
cmp    $0x2,%eax
je     11b0 <store_status+0x50>
test   %eax,%eax
jne    11a0 <store_status+0x40>
xor    %eax,%eax
call   1080 <copy_lowcore_64@plt>
jmp    11a0 <store_status+0x40>
mov    $0x1000,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <free_page@plt>

LLVM IR (-O0):
define void @store_status() {
%1 = alloca i16
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = call i64 (...) @get_zeroed_page()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = inttoptr i64 %6 to i8*
%8 = call i32 @memcpy(i8* %7, i8* inttoptr (i64 4096 to i8*), i32 4096)
%9 = call zeroext i16 (...) @stap()
store i16 %9, i16* %1
%10 = call i32 (...) @copy_lowcore_64()
store i32 0, i32* %3
br label %11
11: ; preds = %33, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load i32, i32* %3
%16 = load i16, i16* %1
%17 = zext i16 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %14
br label %33
20: ; preds = %14
br label %21
21: ; preds = %24, %20
%22 = load i32, i32* %3
%23 = call i32 @sigp(i32 %22, i32 9, i32 0, i8* null)
store i32 %23, i32* %4
br label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %21, label %27
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %33
31: ; preds = %27
%32 = call i32 (...) @copy_lowcore_64()
br label %33
33: ; preds = %31, %30, %19
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %11
36: ; preds = %11
%37 = load i64, i64* %2
%38 = inttoptr i64 %37 to i8*
%39 = call i32 @memcpy(i8* inttoptr (i64 4096 to i8*), i8* %38, i32 4096)
%40 = load i64, i64* %2
%41 = call i32 @free_page(i64 %40)
ret void
}

LLVM IR (-O2):
define void @store_status() {
%1 = tail call i64 (...) @get_zeroed_page()
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @memcpy(i8* %2, i8* inttoptr (i64 4096 to i8*), i32 4096)
%4 = tail call zeroext i16 (...) @stap()
%5 = tail call i32 (...) @copy_lowcore_64()
%6 = zext i16 %4 to i32
br label %7
7: ; preds = %0, %14
%8 = phi i32 [ 0, %0 ], [ %15, %14 ]
%9 = icmp eq i32 %8, %6
br i1 %9, label %14, label %10
10: ; preds = %7, %10
%11 = tail call i32 @sigp(i32 %8, i32 9, i32 0, i8* null)
switch i32 %11, label %14 [
i32 2, label %10
i32 0, label %12
]
12: ; preds = %10
%13 = tail call i32 (...) @copy_lowcore_64()
br label %14
14: ; preds = %10, %7, %12
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %7
17: ; preds = %14
%18 = tail call i32 @memcpy(i8* inttoptr (i64 4096 to i8*), i8* %2, i32 4096)
%19 = tail call i32 @free_page(i64 %1)
ret void
}