#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 SEEK_SET;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, int, int);
long lseek(int, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, unsigned short *, int);
void WriteKernelInformation(int iTargetFd, int iKernelSectorCount) {
  unsigned short usData;
  long lPosition;
  lPosition = lseek(iTargetFd, 5, SEEK_SET);
  if (lPosition == -1) {
    fprintf(stderr, "lseek fail. Return value = %d, errno = %d, %d\n",
            lPosition, errno, SEEK_SET);
    exit(-1);
  }
  usData = (unsigned short)iKernelSectorCount;
  write(iTargetFd, &usData, 2);
  printf("[INFO] Total sector count except boot loader [%d]\n",
         iKernelSectorCount);
}


x86 assembly (clang, -O0):
<WriteKernelInformation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1050 <lseek@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11b9 <WriteKernelInformation+0x69>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    0x2e41(%rip),%rax
mov    (%rax),%ecx
mov    0x2e30(%rip),%rax
mov    (%rax),%r8d
lea    0xe56(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %ax,-0xa(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%esi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteKernelInformation>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e6d(%rip),%r14
mov    (%r14),%edx
mov    $0x5,%esi
call   1050 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     11a2 <WriteKernelInformation+0x52>
mov    %bx,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    (%r14),%r8d
lea    0xe42(%rip),%rsi
mov    $0xffffffffffffffff,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"lseek fail. Return value = %d, errno = %d, %d\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"[INFO] Total sector count except boot loader [%d]\0A\00"
define void @WriteKernelInformation(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i16
%6 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @SEEK_SET
%9 = call i64 @lseek(i32 %7, i32 5, i32 %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i64, i64* %6
%15 = load i32, i32* @errno
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %15, i32 %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i32, i32* %4
%21 = trunc i32 %20 to i16
store i16 %21, i16* %5
%22 = load i32, i32* %3
%23 = call i32 @write(i32 %22, i16* %5, i32 2)
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %24)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"lseek fail. Return value = %d, errno = %d, %d\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"[INFO] Total sector count except boot loader [%d]\0A\00"
define void @WriteKernelInformation(i32 %0, i32 %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @lseek(i32 %0, i32 5, i32 %5)
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 -1, i32 %10, i32 %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = trunc i32 %1 to i16
store i16 %15, i16* %3
%16 = call i32 @write(i32 %0, i16* %3, i32 2)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1)
ret void
}