#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_kernel();
int /*<<< orphan*/ exit(int);
int fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ pad_to_four(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int strlen(char const *);
int /*<<< orphan*/ write_le_uint32(int);
scalar_t__ write_trailer_field(char *, char const *, int);
int main(int argc, char *argv[]) {
  size_t trailer_size = 0;
  char const *kernel_version = (argc >= 2 ? argv[1] : "unknown");
  pad_to_four(copy_kernel());
  trailer_size += write_trailer_field("\0\0\0\0", "", 0);
  trailer_size += write_trailer_field("283x", "\0\0\0\0", 4);
  trailer_size += write_trailer_field("DDTK", "\0\0\0\0", 4);
  trailer_size += write_trailer_field("DTOK", "\1\0\0\0", 4);
  trailer_size +=
      write_trailer_field("KVer", kernel_version, strlen(kernel_version));
  write_le_uint32(trailer_size + 8);
  write_le_uint32(4);
  if (fwrite("RPTL", 1, 4, stdout) != 4) {
    perror("write of RPTL label");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11b9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11c9 <main+0x49>
lea    0xe40(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c9 <main+0x49>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <copy_kernel@plt>
mov    %eax,%edi
call   1030 <pad_to_four@plt>
lea    0xe4f(%rip),%rdi
lea    0xe29(%rip),%rsi
xor    %edx,%edx
call   1060 <write_trailer_field@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe05(%rip),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xdea(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xdcf(%rip),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xd9d(%rip),%rdi
call   1060 <write_trailer_field@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %eax,%edi
call   1050 <write_le_uint32@plt>
mov    $0x4,%edi
call   1050 <write_le_uint32@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%ecx
lea    0xd6c(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10a0 <fwrite@plt>
cmp    $0x4,%eax
je     12de <main+0x15e>
lea    0xd52(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1193 <main+0x13>
mov    0x8(%rsi),%r14
jmp    119a <main+0x1a>
lea    0xe66(%rip),%r14
xor    %eax,%eax
call   1080 <copy_kernel@plt>
mov    %eax,%edi
call   1030 <pad_to_four@plt>
lea    0xe86(%rip),%r15
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1060 <write_trailer_field@plt>
mov    %rax,%r12
lea    0xe3e(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
mov    %rax,%rbx
add    %r12d,%ebx
lea    0xe29(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
mov    %rax,%r15
add    %ebx,%r15d
lea    0xe14(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x4,%edx
call   1060 <write_trailer_field@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xdf3(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <write_trailer_field@plt>
lea    (%rax,%rbx,1),%edi
add    $0x8,%edi
call   1050 <write_le_uint32@plt>
mov    $0x4,%edi
call   1050 <write_le_uint32@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%ecx
lea    0xdc9(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10a0 <fwrite@plt>
cmp    $0x4,%eax
jne    1275 <main+0xf5>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xda5(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [5 x i8] zeroinitializer
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"283x\00"
@.str.4 = [5 x i8] c"DDTK\00"
@.str.5 = [5 x i8] c"DTOK\00"
@.str.6 = [5 x i8] c"\01\00\00\00\00"
@.str.7 = [5 x i8] c"KVer\00"
@.str.8 = [5 x i8] c"RPTL\00"
@stdout = global i32 0
@.str.9 = [20 x i8] c"write of RPTL label\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %10
%16 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %14 ]
store i8* %16, i8** %7
%17 = call i32 (...) @copy_kernel()
%18 = call i32 @pad_to_four(i32 %17)
%19 = call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 0)
%20 = load i64, i64* %6
%21 = add i64 %20, %19
store i64 %21, i64* %6
%22 = call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%23 = load i64, i64* %6
%24 = add i64 %23, %22
store i64 %24, i64* %6
%25 = call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%26 = load i64, i64* %6
%27 = add i64 %26, %25
store i64 %27, i64* %6
%28 = call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%29 = load i64, i64* %6
%30 = add i64 %29, %28
store i64 %30, i64* %6
%31 = load i8*, i8** %7
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
%34 = call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %31, i32 %33)
%35 = load i64, i64* %6
%36 = add i64 %35, %34
store i64 %36, i64* %6
%37 = load i64, i64* %6
%38 = add i64 %37, 8
%39 = trunc i64 %38 to i32
%40 = call i32 @write_le_uint32(i32 %39)
%41 = call i32 @write_le_uint32(i32 4)
%42 = load i32, i32* @stdout
%43 = call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 4, i32 %42)
%44 = icmp ne i32 %43, 4
br i1 %44, label %45, label %48
45: ; preds = %15
%46 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [5 x i8] zeroinitializer
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"283x\00"
@.str.4 = [5 x i8] c"DDTK\00"
@.str.5 = [5 x i8] c"DTOK\00"
@.str.6 = [5 x i8] c"\01\00\00\00\00"
@.str.7 = [5 x i8] c"KVer\00"
@.str.8 = [5 x i8] c"RPTL\00"
@stdout = global i32 0
@.str.9 = [20 x i8] c"write of RPTL label\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %2, %4
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = tail call i32 (...) @copy_kernel()
%10 = tail call i32 @pad_to_four(i32 %9)
%11 = tail call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 0)
%12 = tail call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%13 = add i64 %12, %11
%14 = tail call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = add i64 %13, %14
%16 = tail call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%17 = add i64 %15, %16
%18 = tail call i32 @strlen(i8* %8)
%19 = tail call i64 @write_trailer_field(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %8, i32 %18)
%20 = add i64 %17, %19
%21 = trunc i64 %20 to i32
%22 = add i32 %21, 8
%23 = tail call i32 @write_le_uint32(i32 %22)
%24 = tail call i32 @write_le_uint32(i32 4)
%25 = load i32, i32* @stdout
%26 = tail call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 4, i32 %25)
%27 = icmp eq i32 %26, 4
br i1 %27, label %31, label %28
28: ; preds = %7
%29 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %7
ret i32 0
}