#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 */
typedef int /*<<< orphan*/ sectors;
typedef int /*<<< orphan*/ addr1;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
long lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ write(int, ...);
int main(int argc, char *argv[]) {
  int fd, fd2;
  unsigned short sectors;
  long size, addr1, padd_size, i;
  unsigned char ch;
  if (argc != 3) {
    fprintf(stderr, "Usage: imgsize IFEM_IMG KERNEL_IMG\n");
    return 0;
  }
  if ((fd = open(argv[1], O_RDWR)) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  if ((fd2 = open(argv[2], O_RDWR)) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  if ((addr1 = lseek(fd2, 0, SEEK_END)) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  addr1 += 0x600;
  close(fd2);
  if ((size = lseek(fd, 0, SEEK_END)) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  sectors = (size - 512) / 512 + 1;
  if (lseek(fd, 2, SEEK_SET) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  if (write(fd, (char *)&sectors, sizeof(sectors)) <= 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  if (write(fd, (char *)&addr1, sizeof(addr1)) <= 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  padd_size = size % 512;
  if (lseek(fd, 0, SEEK_END) < 0) {
    fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
    exit((1));
  };
  for (ch = 0, i = padd_size; i > 0; i--)
    if (write(fd, &ch, 1) < 0) {
      fprintf(stderr, "(imgsize) Error: %s\n", strerror(errno));
      exit((1));
    };
  close(fd);
  fprintf(stderr, "===============\n");
  fprintf(stderr, "imgsize report:\n");
  fprintf(stderr, "===============\n");
  fprintf(stderr, "Kernel image size = %ld bytes\n", size);
  fprintf(stderr, "Kernel image size = %d sectors\n", sectors);
  fprintf(stderr, "Padding size      = %ld bytes\n", padd_size);
  fprintf(stderr, "Kernel image successfully modified!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15f2 <main+0x482>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120d <main+0x9d>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1267 <main+0xf7>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jge    12c0 <main+0x150>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x600,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    132f <main+0x1bf>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rax
sub    $0x200,%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    %ax,-0x1a(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c6b(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    13a3 <main+0x233>
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x0,%rax
jg     13f8 <main+0x288>
mov    0x2c09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xc3d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x0,%rax
jg     144d <main+0x2dd>
mov    0x2bb4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xbe8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2b77(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    14b4 <main+0x344>
mov    0x2b4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xb81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movb   $0x0,-0x41(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jle    1536 <main+0x3c6>
mov    -0x14(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1520 <main+0x3b0>
mov    0x2ae1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2acd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xb15(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1525 <main+0x3b5>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
jmp    14c0 <main+0x350>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2a8b(%rip),%rax
mov    (%rax),%edi
lea    0xaeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a74(%rip),%rax
mov    (%rax),%edi
lea    0xae5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
lea    0xabd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a46(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xac4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a2b(%rip),%rax
mov    (%rax),%edi
movzwl -0x1a(%rbp),%edx
lea    0xac8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2a10(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xacd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x29f5(%rip),%rax
mov    (%rax),%edi
lea    0xad5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1360 <main+0x1f0>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e55(%rip),%rbx
mov    (%rbx),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1386 <main+0x216>
mov    %eax,%r12d
mov    0x10(%rbp),%rdi
mov    (%rbx),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1386 <main+0x216>
mov    %eax,%ebp
mov    0x2e1f(%rip),%r15
mov    (%r15),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1386 <main+0x216>
add    $0x600,%rax
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
call   1050 <close@plt>
mov    (%r15),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1386 <main+0x216>
mov    %rax,%r14
add    $0xfffffffffffffe00,%rax
lea    0x1ff(%rax),%ecx
test   %rax,%rax
cmovns %rax,%rcx
shr    $0x9,%rcx
add    $0x1,%ecx
mov    %cx,0x6(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    $0x2,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1386 <main+0x216>
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <write@plt>
test   %rax,%rax
jle    1386 <main+0x216>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <write@plt>
test   %rax,%rax
jle    1386 <main+0x216>
mov    (%r15),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1386 <main+0x216>
mov    %r14d,%r15d
and    $0x1ff,%r15d
movb   $0x0,0x5(%rsp)
test   %r15,%r15
je     12d5 <main+0x165>
lea    0x1(%r15),%rbx
lea    0x5(%rsp),%rbp
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
test   %rax,%rax
js     1386 <main+0x216>
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
jge    12b0 <main+0x140>
mov    %r12d,%edi
call   1050 <close@plt>
mov    0x2cec(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd4b(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd48(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd3b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
movzwl 0x6(%rsp),%edx
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd50(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd5b(%rip),%rsi
jmp    1370 <main+0x200>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xc80(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: imgsize IFEM_IMG KERNEL_IMG\0A\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"(imgsize) Error: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [17 x i8] c"===============\0A\00"
@.str.3 = [17 x i8] c"imgsize report:\0A\00"
@.str.4 = [31 x i8] c"Kernel image size = %ld bytes\0A\00"
@.str.5 = [32 x i8] c"Kernel image size = %d sectors\0A\00"
@.str.6 = [31 x i8] c"Padding size = %ld bytes\0A\00"
@.str.7 = [37 x i8] c"Kernel image successfully modified!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %162
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_RDWR
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = load i32, i32* %7
%47 = load i32, i32* @SEEK_END
%48 = call i64 @lseek(i32 %46, i32 0, i32 %47)
store i64 %48, i64* %10
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %45
%57 = load i64, i64* %10
%58 = add nsw i64 %57, 1536
store i64 %58, i64* %10
%59 = load i32, i32* %7
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %6
%62 = load i32, i32* @SEEK_END
%63 = call i64 @lseek(i32 %61, i32 0, i32 %62)
store i64 %63, i64* %9
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %56
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %56
%72 = load i64, i64* %9
%73 = sub nsw i64 %72, 512
%74 = sdiv i64 %73, 512
%75 = add nsw i64 %74, 1
%76 = trunc i64 %75 to i16
store i16 %76, i16* %8
%77 = load i32, i32* %6
%78 = load i32, i32* @SEEK_SET
%79 = call i64 @lseek(i32 %77, i32 2, i32 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %87
81: ; preds = %71
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %71
%88 = load i32, i32* %6
%89 = bitcast i16* %8 to i8*
%90 = call i64 (i32, ...) @write(i32 %88, i8* %89, i64 2)
%91 = icmp sle i64 %90, 0
br i1 %91, label %92, label %98
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %87
%99 = load i32, i32* %6
%100 = bitcast i64* %10 to i8*
%101 = call i64 (i32, ...) @write(i32 %99, i8* %100, i64 8)
%102 = icmp sle i64 %101, 0
br i1 %102, label %103, label %109
103: ; preds = %98
%104 = load i32, i32* @stderr
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %106)
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %98
%110 = load i64, i64* %9
%111 = srem i64 %110, 512
store i64 %111, i64* %11
%112 = load i32, i32* %6
%113 = load i32, i32* @SEEK_END
%114 = call i64 @lseek(i32 %112, i32 0, i32 %113)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %122
116: ; preds = %109
%117 = load i32, i32* @stderr
%118 = load i32, i32* @errno
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %119)
%121 = call i32 @exit(i32 1)
unreachable
122: ; preds = %109
store i8 0, i8* %13
%123 = load i64, i64* %11
store i64 %123, i64* %12
br label %124
124: ; preds = %138, %122
%125 = load i64, i64* %12
%126 = icmp sgt i64 %125, 0
br i1 %126, label %127, label %141
127: ; preds = %124
%128 = load i32, i32* %6
%129 = call i64 (i32, ...) @write(i32 %128, i8* %13, i32 1)
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %137
131: ; preds = %127
%132 = load i32, i32* @stderr
%133 = load i32, i32* @errno
%134 = call i8* @strerror(i32 %133)
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %134)
%136 = call i32 @exit(i32 1)
unreachable
137: ; preds = %127
br label %138
138: ; preds = %137
%139 = load i64, i64* %12
%140 = add nsw i64 %139, -1
store i64 %140, i64* %12
br label %124
141: ; preds = %124
%142 = load i32, i32* %6
%143 = call i32 @close(i32 %142)
%144 = load i32, i32* @stderr
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%146 = load i32, i32* @stderr
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%150 = load i32, i32* @stderr
%151 = load i64, i64* %9
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %151)
%153 = load i32, i32* @stderr
%154 = load i16, i16* %8
%155 = zext i16 %154 to i32
%156 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %155)
%157 = load i32, i32* @stderr
%158 = load i64, i64* %11
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i64 %158)
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %162
162: ; preds = %141, %16
%163 = load i32, i32* %3
ret i32 %163
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: imgsize IFEM_IMG KERNEL_IMG\0A\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"(imgsize) Error: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [17 x i8] c"===============\0A\00"
@.str.3 = [17 x i8] c"imgsize report:\0A\00"
@.str.4 = [31 x i8] c"Kernel image size = %ld bytes\0A\00"
@.str.5 = [32 x i8] c"Kernel image size = %d sectors\0A\00"
@.str.6 = [31 x i8] c"Padding size = %ld bytes\0A\00"
@.str.7 = [37 x i8] c"Kernel image successfully modified!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i64
%5 = alloca i8
%6 = bitcast i16* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = icmp eq i32 %0, 3
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %134
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %12
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = tail call i32 @open(i8* %26, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %24
%37 = load i32, i32* @SEEK_END
%38 = tail call i64 @lseek(i32 %28, i32 0, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = add nuw nsw i64 %38, 1536
store i64 %47, i64* %4
%48 = tail call i32 @close(i32 %28)
%49 = load i32, i32* @SEEK_END
%50 = tail call i64 @lseek(i32 %16, i32 0, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = tail call i8* @strerror(i32 %54)
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %46
%59 = add nsw i64 %50, -512
%60 = sdiv i64 %59, 512
%61 = trunc i64 %60 to i16
%62 = add i16 %61, 1
store i16 %62, i16* %3
%63 = load i32, i32* @SEEK_SET
%64 = tail call i64 @lseek(i32 %16, i32 2, i32 %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %58
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = tail call i8* @strerror(i32 %68)
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %69)
%71 = tail call i32 @exit(i32 1)
unreachable
72: ; preds = %58
%73 = call i64 (i32, ...) @write(i32 %16, i16* %3, i64 2)
%74 = icmp slt i64 %73, 1
br i1 %74, label %75, label %81
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %72
%82 = call i64 (i32, ...) @write(i32 %16, i64* %4, i64 8)
%83 = icmp slt i64 %82, 1
br i1 %83, label %84, label %90
84: ; preds = %81
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %87)
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %81
%91 = and i64 %50, 511
%92 = load i32, i32* @SEEK_END
%93 = call i64 @lseek(i32 %16, i32 0, i32 %92)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %90
%96 = load i32, i32* @stderr
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %90
store i8 0, i8* %5
%102 = icmp eq i64 %91, 0
br i1 %102, label %116, label %106
103: ; preds = %106
%104 = add nsw i64 %107, -1
%105 = icmp sgt i64 %107, 1
br i1 %105, label %106, label %116
106: ; preds = %101, %103
%107 = phi i64 [ %104, %103 ], [ %91, %101 ]
%108 = call i64 (i32, ...) @write(i32 %16, i8* %5, i32 1)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %103
110: ; preds = %106
%111 = load i32, i32* @stderr
%112 = load i32, i32* @errno
%113 = call i8* @strerror(i32 %112)
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %113)
%115 = call i32 @exit(i32 1)
unreachable
116: ; preds = %103, %101
%117 = call i32 @close(i32 %16)
%118 = load i32, i32* @stderr
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%124 = load i32, i32* @stderr
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %50)
%126 = load i32, i32* @stderr
%127 = load i16, i16* %3
%128 = zext i16 %127 to i32
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %128)
%130 = load i32, i32* @stderr
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i64 %91)
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %134
134: ; preds = %116, %9
ret i32 0
}