#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*/ _sclp_setup(int /*<<< orphan*/);
scalar_t__ virtio_load_direct(unsigned long long, unsigned long long,
                              int /*<<< orphan*/, char *);
int /*<<< orphan*/ virtio_puts(char *);
int /*<<< orphan*/ virtio_zipl_fallback();
void virtio_load_stage2() {
  unsigned long long *sector = (void *)0x8020;
  char *stage2 = (void *)0x2000;
  void (*stage2_func)(void) = (void *)0x2008;
  unsigned long *bss = (void *)0x4500;
  _sclp_setup(0);
  while (*sector) {
    stage2 = (void *)virtio_load_direct(sector[0], sector[1], 0, stage2);
    sector += 2;
    if ((long)stage2 == -1)
      virtio_zipl_fallback();
  }
  virtio_puts("\n");
  while (1) {
    *bss = 0;
    bss++;
    if ((unsigned long)bss > 0x6000)
      break;
  }
  stage2_func();
}


x86 assembly (clang, -O0):
<virtio_load_stage2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8020,%eax
mov    %rax,-0x8(%rbp)
mov    $0x2000,%eax
mov    %rax,-0x10(%rbp)
mov    $0x2008,%eax
mov    %rax,-0x18(%rbp)
mov    $0x4500,%eax
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1050 <_sclp_setup@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c5 <virtio_load_stage2+0x85>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rcx
xor    %edx,%edx
call   1060 <virtio_load_direct@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
jne    11c0 <virtio_load_stage2+0x80>
mov    $0x0,%al
call   1030 <virtio_zipl_fallback@plt>
jmp    1173 <virtio_load_stage2+0x33>
lea    0xe34(%rip),%rdi
call   1040 <virtio_puts@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    $0x6000,%rax
jbe    11fd <virtio_load_stage2+0xbd>
jmp    1202 <virtio_load_stage2+0xc2>
jmp    11d1 <virtio_load_stage2+0x91>
call   *-0x18(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<virtio_load_stage2>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <_sclp_setup@plt>
mov    0x8020,%rdi
test   %rdi,%rdi
je     11ac <virtio_load_stage2+0x5c>
mov    $0x2000,%r14d
mov    $0x8030,%ebx
jmp    118c <virtio_load_stage2+0x3c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%rdi
add    $0x10,%rbx
test   %rdi,%rdi
je     11ac <virtio_load_stage2+0x5c>
mov    -0x8(%rbx),%rsi
xor    %edx,%edx
mov    %r14,%rcx
call   1070 <virtio_load_direct@plt>
mov    %rax,%r14
cmp    $0xffffffffffffffff,%rax
jne    1180 <virtio_load_stage2+0x30>
xor    %eax,%eax
call   1030 <virtio_zipl_fallback@plt>
jmp    1180 <virtio_load_stage2+0x30>
lea    0xe4d(%rip),%rdi
call   1040 <virtio_puts@plt>
mov    $0x4500,%edi
mov    $0x1b08,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x2008,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    *%rax

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @virtio_load_stage2() {
%1 = alloca i64*
%2 = alloca i8*
%3 = alloca void ()*
%4 = alloca i64*
store i64* inttoptr (i64 32800 to i64*), i64** %1
store i8* inttoptr (i64 8192 to i8*), i8** %2
store void ()* inttoptr (i64 8200 to void ()*), void ()** %3
store i64* inttoptr (i64 17664 to i64*), i64** %4
%5 = call i32 @_sclp_setup(i32 0)
br label %6
6: ; preds = %27, %0
%7 = load i64*, i64** %1
%8 = load i64, i64* %7
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i64*, i64** %1
%12 = getelementptr inbounds i64, i64* %11, i64 0
%13 = load i64, i64* %12
%14 = load i64*, i64** %1
%15 = getelementptr inbounds i64, i64* %14, i64 1
%16 = load i64, i64* %15
%17 = load i8*, i8** %2
%18 = call i64 @virtio_load_direct(i64 %13, i64 %16, i32 0, i8* %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %2
%20 = load i64*, i64** %1
%21 = getelementptr inbounds i64, i64* %20, i64 2
store i64* %21, i64** %1
%22 = load i8*, i8** %2
%23 = ptrtoint i8* %22 to i64
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %10
%26 = call i32 (...) @virtio_zipl_fallback()
br label %27
27: ; preds = %25, %10
br label %6
28: ; preds = %6
%29 = call i32 @virtio_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %38
%31 = load i64*, i64** %4
store i64 0, i64* %31
%32 = load i64*, i64** %4
%33 = getelementptr inbounds i64, i64* %32, i32 1
store i64* %33, i64** %4
%34 = load i64*, i64** %4
%35 = ptrtoint i64* %34 to i64
%36 = icmp ugt i64 %35, 24576
br i1 %36, label %37, label %38
37: ; preds = %30
br label %39
38: ; preds = %30
br label %30
39: ; preds = %37
%40 = load void ()*, void ()** %3
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @virtio_load_stage2() {
%1 = tail call i32 @_sclp_setup(i32 0)
%2 = load i64, i64* inttoptr (i64 32800 to i64*)
%3 = icmp eq i64 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %0, %16
%5 = phi i64 [ %17, %16 ], [ %2, %0 ]
%6 = phi i64* [ %12, %16 ], [ inttoptr (i64 32800 to i64*), %0 ]
%7 = phi i8* [ %11, %16 ], [ inttoptr (i64 8192 to i8*), %0 ]
%8 = getelementptr inbounds i64, i64* %6, i64 1
%9 = load i64, i64* %8
%10 = tail call i64 @virtio_load_direct(i64 %5, i64 %9, i32 0, i8* %7)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i64, i64* %6, i64 2
%13 = icmp eq i64 %10, -1
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = tail call i32 (...) @virtio_zipl_fallback()
br label %16
16: ; preds = %14, %4
%17 = load i64, i64* %12
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %16, %0
%20 = tail call i32 @virtio_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
tail call void inttoptr (i64 8200 to void ()*)()
ret void
}