#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*/ CloseLibrary(int);
int OpenLibrary(char *, long);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int l;
  if (l = OpenLibrary("exec.library", 35L)) {
    fprintf(stderr, "Writing 512K Kickstart image...\n");
    fflush(stderr);
    fwrite((char *)0xF80000, sizeof(char), 0x80000, stdout);
    CloseLibrary(l);
  } else {
    fprintf(stderr, "Writing 256K Kickstart image...\n");
    fflush(stderr);
    fwrite((char *)0xF80000, sizeof(char), 0x40000, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x23,%esi
call   1030 <OpenLibrary@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11d0 <main+0x80>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
mov    $0xf80000,%edi
mov    $0x1,%esi
mov    $0x80000,%edx
call   1070 <fwrite@plt>
mov    -0x14(%rbp),%edi
call   1060 <CloseLibrary@plt>
jmp    1210 <main+0xc0>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%ecx
mov    $0xf80000,%edi
mov    $0x1,%esi
mov    $0x40000,%edx
call   1070 <fwrite@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
mov    $0x23,%esi
call   1030 <OpenLibrary@plt>
mov    0x2e74(%rip),%r14
mov    (%r14),%edi
test   %eax,%eax
je     11af <main+0x5f>
mov    %eax,%ebx
lea    0xe91(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%r14),%edi
call   1050 <fflush@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%ecx
mov    $0xf80000,%edi
mov    $0x1,%esi
mov    $0x80000,%edx
call   1070 <fwrite@plt>
mov    %ebx,%edi
call   1060 <CloseLibrary@plt>
jmp    11e0 <main+0x90>
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%r14),%edi
call   1050 <fflush@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%ecx
mov    $0xf80000,%edi
mov    $0x1,%esi
mov    $0x40000,%edx
call   1070 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"exec.library\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Writing 512K Kickstart image...\0A\00"
@stdout = global i32 0
@.str.2 = [33 x i8] c"Writing 256K Kickstart image...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @OpenLibrary(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 35)
store i32 %7, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 @fflush(i32 %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fwrite(i8* inttoptr (i64 16252928 to i8*), i32 1, i32 524288, i32 %14)
%16 = load i32, i32* %6
%17 = call i32 @CloseLibrary(i32 %16)
br label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fflush(i32 %21)
%23 = load i32, i32* @stdout
%24 = call i32 @fwrite(i8* inttoptr (i64 16252928 to i8*), i32 1, i32 262144, i32 %23)
br label %25
25: ; preds = %18, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"exec.library\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Writing 512K Kickstart image...\0A\00"
@stdout = global i32 0
@.str.2 = [33 x i8] c"Writing 256K Kickstart image...\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @OpenLibrary(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 35)
%4 = icmp eq i32 %3, 0
%5 = load i32, i32* @stderr
br i1 %4, label %13, label %6
6: ; preds = %2
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fflush(i32 %8)
%10 = load i32, i32* @stdout
%11 = tail call i32 @fwrite(i8* inttoptr (i64 16252928 to i8*), i32 1, i32 524288, i32 %10)
%12 = tail call i32 @CloseLibrary(i32 %3)
br label %19
13: ; preds = %2
%14 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 @fflush(i32 %15)
%17 = load i32, i32* @stdout
%18 = tail call i32 @fwrite(i8* inttoptr (i64 16252928 to i8*), i32 1, i32 262144, i32 %17)
br label %19
19: ; preds = %13, %6
ret i32 0
}