#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*/ print_hex(char *, ...);
int /*<<< orphan*/ puts(char *);
int wait_core(void) {
  volatile unsigned long *sent;
  volatile unsigned long *rom;
  int i;
  unsigned long rom_val, sent_val;
  sent = (volatile unsigned long *)4;
  rom = ((volatile unsigned long *)(0x01f01c00 + 0x1A4));
  rom_val = *rom;
  sent_val = *sent;
  print_hex("ROM_START first seen with:", rom_val);
  print_hex("Sentinel first seen with:", sent_val);
  print_hex("Sentinel next seen with:", *sent);
  print_hex("ROM_START next seen with:", *rom);
  print_hex("Sentinel at:", sent);
  print_hex("ROM_START at:", rom);
  for (i = 0; i < 100; i++) {
    if (*sent != 0xdeadbeef) {
      break;
    }
  }
  if (*sent == 0xdeadbeef)
    return 0;
  puts("Signs of life\n");
  for (i = 0; i < 100; i++) {
    if (*sent == 0) {
      break;
    }
  }
  if (*sent == 0)
    return 1;
  print_hex("Core partly started with code:", *sent);
  return 0;
}


x86 assembly (clang, -O0):
<wait_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x4,%eax
mov    %rax,-0x10(%rbp)
mov    $0x1f01da4,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
mov    -0x30(%rbp),%rsi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
mov    -0x10(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
mov    -0x18(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    1200 <wait_core+0xe0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    $0xdeadbeef,%ecx
cmp    %rcx,%rax
je     11ed <wait_core+0xcd>
jmp    1200 <wait_core+0xe0>
jmp    11f2 <wait_core+0xd2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c9 <wait_core+0xa9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    $0xdeadbeef,%ecx
cmp    %rcx,%rax
jne    1221 <wait_core+0x101>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <wait_core+0x180>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    1267 <wait_core+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    $0x0,%rax
jne    1254 <wait_core+0x134>
jmp    1267 <wait_core+0x147>
jmp    1259 <wait_core+0x139>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1234 <wait_core+0x114>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    $0x0,%rax
jne    1284 <wait_core+0x164>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <wait_core+0x180>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <print_hex@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_core>:
push   %rbp
push   %rbx
push   %rax
mov    $0xdeadbeef,%ebx
mov    0x1f01da4,%rsi
01
mov    0x4,%rbp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <print_hex@plt>
lea    0xece(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <print_hex@plt>
mov    0x4,%rsi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1040 <print_hex@plt>
mov    0x1f01da4,%rsi
01
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <print_hex@plt>
lea    0xede(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <print_hex@plt>
lea    0xed8(%rip),%rdi
mov    $0x1f01da4,%esi
xor    %eax,%eax
call   1040 <print_hex@plt>
mov    $0x63,%eax
xchg   %ax,%ax
mov    0x4,%rdx
sub    $0x1,%eax
setb   %cl
cmp    %rbx,%rdx
jne    11c7 <wait_core+0xa7>
test   %cl,%cl
je     11b0 <wait_core+0x90>
mov    0x4,%rax
xor    %ebp,%ebp
cmp    %rbx,%rax
je     122f <wait_core+0x10f>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x63,%eax
nopw   0x0(%rax,%rax,1)
sub    $0x1,%eax
setb   %cl
cmpq   $0x0,0x4
je     1205 <wait_core+0xe5>
test   %cl,%cl
je     11f0 <wait_core+0xd0>
cmpq   $0x0,0x4
je     122a <wait_core+0x10a>
mov    0x4,%rsi
lea    0xe73(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <print_hex@plt>
jmp    122f <wait_core+0x10f>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"ROM_START first seen with:\00"
@.str.1 = [26 x i8] c"Sentinel first seen with:\00"
@.str.2 = [25 x i8] c"Sentinel next seen with:\00"
@.str.3 = [26 x i8] c"ROM_START next seen with:\00"
@.str.4 = [13 x i8] c"Sentinel at:\00"
@.str.5 = [14 x i8] c"ROM_START at:\00"
@.str.6 = [15 x i8] c"Signs of life\0A\00"
@.str.7 = [31 x i8] c"Core partly started with code:\00"
define i32 @wait_core() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i64* inttoptr (i64 4 to i64*), i64** %2
store i64* inttoptr (i64 32513444 to i64*), i64** %3
%7 = load i64*, i64** %3
%8 = load volatile i64, i64* %7
store i64 %8, i64* %5
%9 = load i64*, i64** %2
%10 = load volatile i64, i64* %9
store i64 %10, i64* %6
%11 = load i64, i64* %5
%12 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = load i64, i64* %6
%14 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = load i64*, i64** %2
%16 = load volatile i64, i64* %15
%17 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%18 = load i64*, i64** %3
%19 = load volatile i64, i64* %18
%20 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %19)
%21 = load i64*, i64** %2
%22 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64* %21)
%23 = load i64*, i64** %3
%24 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64* %23)
store i32 0, i32* %4
br label %25
25: ; preds = %34, %0
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 100
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i64*, i64** %2
%30 = load volatile i64, i64* %29
%31 = icmp ne i64 %30, 3735928559
br i1 %31, label %32, label %33
32: ; preds = %28
br label %37
33: ; preds = %28
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %25
37: ; preds = %32, %25
%38 = load i64*, i64** %2
%39 = load volatile i64, i64* %38
%40 = icmp eq i64 %39, 3735928559
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 0, i32* %1
br label %65
42: ; preds = %37
%43 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
br label %44
44: ; preds = %53, %42
%45 = load i32, i32* %4
%46 = icmp slt i32 %45, 100
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i64*, i64** %2
%49 = load volatile i64, i64* %48
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %56
52: ; preds = %47
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %44
56: ; preds = %51, %44
%57 = load i64*, i64** %2
%58 = load volatile i64, i64* %57
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %56
store i32 1, i32* %1
br label %65
61: ; preds = %56
%62 = load i64*, i64** %2
%63 = load volatile i64, i64* %62
%64 = call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64 %63)
store i32 0, i32* %1
br label %65
65: ; preds = %61, %60, %41
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [27 x i8] c"ROM_START first seen with:\00"
@.str.1 = [26 x i8] c"Sentinel first seen with:\00"
@.str.2 = [25 x i8] c"Sentinel next seen with:\00"
@.str.3 = [26 x i8] c"ROM_START next seen with:\00"
@.str.4 = [13 x i8] c"Sentinel at:\00"
@.str.5 = [14 x i8] c"ROM_START at:\00"
@.str.6 = [15 x i8] c"Signs of life\0A\00"
@.str.7 = [31 x i8] c"Core partly started with code:\00"
define i32 @wait_core() {
%1 = load volatile i64, i64* inttoptr (i64 32513444 to i64*)
%2 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%3 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %1)
%4 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%5 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%6 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%7 = load volatile i64, i64* inttoptr (i64 32513444 to i64*)
%8 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%9 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64* inttoptr (i64 4 to i64*))
%10 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64* inttoptr (i64 32513444 to i64*))
br label %11
11: ; preds = %11, %0
%12 = phi i32 [ 0, %0 ], [ %15, %11 ]
%13 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%14 = icmp ne i64 %13, 3735928559
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, 100
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%20 = icmp eq i64 %19, 3735928559
br i1 %20, label %36, label %21
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %23, %21
%24 = phi i32 [ 0, %21 ], [ %27, %23 ]
%25 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%26 = icmp eq i64 %25, 0
%27 = add nuw nsw i32 %24, 1
%28 = icmp eq i32 %27, 100
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %23
30: ; preds = %23
%31 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load volatile i64, i64* inttoptr (i64 4 to i64*)
%35 = tail call i32 (i8*, ...) @print_hex(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i64 %34)
br label %36
36: ; preds = %30, %18, %33
%37 = phi i32 [ 0, %33 ], [ 0, %18 ], [ 1, %30 ]
ret i32 %37
}