#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*/ delay_ms(int);
int /*<<< orphan*/ launch_core(int);
int /*<<< orphan*/ print_hex(char *, unsigned long volatile);
int /*<<< orphan*/ print_num(char *, int);
int /*<<< orphan*/ puts(char *);
int wait_core();
void test_one(int cpu) {
  int stat;
  print_hex("Sentinel found with:", *(volatile unsigned long *)4);
  print_hex("ROM_START found with:",
            *((volatile unsigned long *)(0x01f01c00 + 0x1A4)));
  *(volatile unsigned long *)4 = 0xdeadbeef;
  print_hex("Sentinel initialized with:", *(volatile unsigned long *)4);
  delay_ms(500);
  print_hex("Sentinel double checked after delay:",
            *(volatile unsigned long *)4);
  print_num("Starting core ...", cpu);
  launch_core(cpu);
  stat = wait_core();
  if (stat)
    puts(" Core verified to start\n");
  else
    puts("** Core failed to start\n");
  *((volatile unsigned long *)(0x01f01c00 + 0x1A4)) = 0;
}


x86 assembly (clang, -O0):
<test_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%eax
mov    (%rax),%rsi
lea    0xe86(%rip),%rdi
call   1050 <print_hex@plt>
mov    $0x1f01da4,%eax
mov    (%rax),%rsi
lea    0xe87(%rip),%rdi
call   1050 <print_hex@plt>
mov    $0x4,%eax
mov    $0xdeadbeef,%ecx
mov    %rcx,(%rax)
mov    $0x4,%eax
mov    (%rax),%rsi
lea    0xe7c(%rip),%rdi
call   1050 <print_hex@plt>
mov    $0x1f4,%edi
call   1060 <delay_ms@plt>
mov    $0x4,%eax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
call   1050 <print_hex@plt>
mov    -0x4(%rbp),%esi
lea    0xe8f(%rip),%rdi
call   1070 <print_num@plt>
mov    -0x4(%rbp),%edi
call   1040 <launch_core@plt>
mov    $0x0,%al
call   1080 <wait_core@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     120e <test_one+0xae>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
jmp    121a <test_one+0xba>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1f01da4,%eax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_one>:
push   %rbx
mov    %edi,%ebx
mov    0x4,%rsi
lea    0xe8e(%rip),%rdi
call   1050 <print_hex@plt>
mov    0x1f01da4,%rsi
01
lea    0xe8f(%rip),%rdi
call   1050 <print_hex@plt>
mov    $0xdeadbeef,%eax
mov    %rax,0x4
mov    0x4,%rsi
lea    0xe84(%rip),%rdi
call   1050 <print_hex@plt>
mov    $0x1f4,%edi
call   1060 <delay_ms@plt>
mov    0x4,%rsi
lea    0xe81(%rip),%rdi
call   1050 <print_hex@plt>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
call   1070 <print_num@plt>
mov    %ebx,%edi
call   1040 <launch_core@plt>
xor    %eax,%eax
call   1080 <wait_core@plt>
test   %eax,%eax
lea    0xea7(%rip),%rax
lea    0xe87(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
movq   $0x0,0x1f01da4
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Sentinel found with:\00"
@.str.1 = [22 x i8] c"ROM_START found with:\00"
@.str.2 = [27 x i8] c"Sentinel initialized with:\00"
@.str.3 = [37 x i8] c"Sentinel double checked after delay:\00"
@.str.4 = [18 x i8] c"Starting core ...\00"
@.str.5 = [25 x i8] c" Core verified to start\0A\00"
@.str.6 = [25 x i8] c"** Core failed to start\0A\00"
define void @test_one(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%5 = call i32 @print_hex(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = load volatile i64, i64* inttoptr (i64 32513444 to i64*)
%7 = call i32 @print_hex(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %6)
store volatile i64 3735928559, i64* inttoptr (i64 4 to i64*)
%8 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%9 = call i32 @print_hex(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %8)
%10 = call i32 @delay_ms(i32 500)
%11 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%12 = call i32 @print_hex(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %11)
%13 = load i32, i32* %2
%14 = call i32 @print_num(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @launch_core(i32 %15)
%17 = call i32 (...) @wait_core()
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %24
22: ; preds = %1
%23 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
store volatile i64 0, i64* inttoptr (i64 32513444 to i64*)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Sentinel found with:\00"
@.str.1 = [22 x i8] c"ROM_START found with:\00"
@.str.2 = [27 x i8] c"Sentinel initialized with:\00"
@.str.3 = [37 x i8] c"Sentinel double checked after delay:\00"
@.str.4 = [18 x i8] c"Starting core ...\00"
@.str.5 = [25 x i8] c" Core verified to start\0A\00"
@.str.6 = [25 x i8] c"** Core failed to start\0A\00"
define void @test_one(i32 %0) {
%2 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%3 = tail call i32 @print_hex(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = load volatile i64, i64* inttoptr (i64 32513444 to i64*)
%5 = tail call i32 @print_hex(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %4)
store volatile i64 3735928559, i64* inttoptr (i64 4 to i64*)
%6 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%7 = tail call i32 @print_hex(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %6)
%8 = tail call i32 @delay_ms(i32 500)
%9 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%10 = tail call i32 @print_hex(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %9)
%11 = tail call i32 @print_num(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%12 = tail call i32 @launch_core(i32 %0)
%13 = tail call i32 (...) @wait_core()
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0)
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
store volatile i64 0, i64* inttoptr (i64 32513444 to i64*)
ret void
}