#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
long file_size(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ init_frec(char *, int, int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 5) {
    printf("usage: imgmake <bootsector.bin> <kernel.bin> <initramfs> "
           "<floppy.img>\n");
    exit(EXIT_FAILURE);
  }
  char data[512];
  FILE *boot = fopen(argv[1], "rb");
  fread(data, 512, 1, boot);
  fclose(boot);
  FILE *img = fopen(argv[4], "wb");
  fwrite(data, 512, 1, img);
  memset(data, 0, 512);
  fwrite(data, 512, 1, img);
  init_frec(data, 0, 1, 2);
  long krn_sz = file_size(argv[2]);
  int krn_scnt = krn_sz / 512;
  if (krn_sz % 512)
    krn_scnt++;
  printf("kernel size:%ld byte(s) or %d sector(s)\n", krn_sz, krn_scnt);
  long irfs_sz = file_size(argv[3]);
  int irfs_scnt = irfs_sz / 512;
  if (irfs_sz % 512)
    irfs_scnt++;
  printf("initramfs size:%ld byte(s) or %d sector(s)\n", irfs_sz, irfs_scnt);
  init_frec(data, 1, 3, krn_scnt + 1);
  init_frec(data, 2, 3 + krn_scnt + 1, irfs_scnt + 1);
  fwrite(data, 512, 1, img);
  memset(data, 0, 512);
  fwrite(data, 512, 1, img);
  char krn_data[krn_sz];
  FILE *krn = fopen(argv[2], "rb");
  fread(krn_data, krn_sz, 1, krn);
  fclose(krn);
  fwrite(krn_data, krn_sz, 1, img);
  fwrite(data, krn_scnt * 512 - krn_sz, 1, img);
  memset(data, 0, 512);
  fwrite(data, 512, 1, img);
  char irfs_data[irfs_sz];
  FILE *irfs = fopen(argv[3], "rb");
  fread(irfs_data, irfs_sz, 1, irfs);
  fclose(irfs);
  fwrite(irfs_data, irfs_sz, 1, img);
  fwrite(data, irfs_scnt * 512 - irfs_sz, 1, img);
  for (int i = 6 + krn_scnt; i < 1440 * 2; i++)
    fwrite(data, 512, 1, img);
  fclose(img);
  printf("img builded\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11cf <main+0x3f>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x218(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1030 <init_frec@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <file_size@plt>
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
mov    %eax,-0x22c(%rbp)
mov    -0x228(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     12e8 <main+0x158>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
mov    -0x228(%rbp),%rsi
mov    -0x22c(%rbp),%edx
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <file_size@plt>
mov    %rax,-0x238(%rbp)
mov    -0x238(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
mov    %eax,-0x23c(%rbp)
mov    -0x238(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     1358 <main+0x1c8>
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
mov    -0x238(%rbp),%rsi
mov    -0x23c(%rbp),%edx
lea    0xd0a(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x28c(%rbp)
call   1060 <printf@plt>
mov    -0x22c(%rbp),%ecx
add    $0x1,%ecx
lea    -0x210(%rbp),%rdi
mov    %rdi,-0x288(%rbp)
mov    $0x1,%esi
mov    %esi,-0x27c(%rbp)
mov    $0x3,%edx
call   1030 <init_frec@plt>
mov    -0x288(%rbp),%rdi
mov    -0x22c(%rbp),%edx
add    $0x4,%edx
mov    -0x23c(%rbp),%ecx
add    $0x1,%ecx
mov    $0x2,%esi
call   1030 <init_frec@plt>
mov    -0x288(%rbp),%rdi
mov    -0x27c(%rbp),%edx
mov    -0x220(%rbp),%rcx
mov    $0x200,%esi
mov    %esi,-0x280(%rbp)
call   10b0 <fwrite@plt>
mov    -0x28c(%rbp),%esi
mov    -0x288(%rbp),%rdi
mov    -0x280(%rbp),%edx
call   1070 <memset@plt>
mov    -0x288(%rbp),%rdi
mov    -0x280(%rbp),%esi
mov    -0x27c(%rbp),%edx
mov    -0x220(%rbp),%rcx
call   10b0 <fwrite@plt>
mov    -0x228(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x248(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x298(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x250(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xbe2(%rip),%rsi
call   1090 <fopen@plt>
mov    -0x298(%rbp),%rdi
mov    -0x27c(%rbp),%edx
mov    %rax,-0x258(%rbp)
mov    -0x228(%rbp),%rsi
mov    -0x258(%rbp),%rcx
call   1040 <fread@plt>
mov    -0x258(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x298(%rbp),%rdi
mov    -0x27c(%rbp),%edx
mov    -0x228(%rbp),%esi
mov    -0x220(%rbp),%rcx
call   10b0 <fwrite@plt>
mov    -0x288(%rbp),%rdi
mov    -0x27c(%rbp),%edx
mov    -0x22c(%rbp),%esi
shl    $0x9,%esi
mov    -0x228(%rbp),%eax
sub    %eax,%esi
mov    -0x220(%rbp),%rcx
call   10b0 <fwrite@plt>
mov    -0x28c(%rbp),%esi
mov    -0x288(%rbp),%rdi
mov    -0x280(%rbp),%edx
call   1070 <memset@plt>
mov    -0x288(%rbp),%rdi
mov    -0x280(%rbp),%esi
mov    -0x27c(%rbp),%edx
mov    -0x220(%rbp),%rcx
call   10b0 <fwrite@plt>
mov    -0x238(%rbp),%rax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x278(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x260(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xaf2(%rip),%rsi
call   1090 <fopen@plt>
mov    -0x278(%rbp),%rdi
mov    %rax,-0x268(%rbp)
mov    -0x238(%rbp),%rsi
mov    -0x268(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x268(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x278(%rbp),%rdi
mov    -0x238(%rbp),%rax
mov    %eax,%esi
mov    -0x220(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
lea    -0x210(%rbp),%rdi
mov    -0x23c(%rbp),%eax
shl    $0x9,%eax
cltq
sub    -0x238(%rbp),%rax
mov    %eax,%esi
mov    -0x220(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x22c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x26c(%rbp)
cmpl   $0xb40,-0x26c(%rbp)
jge    1629 <main+0x499>
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x26c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x26c(%rbp)
jmp    15e8 <main+0x458>
mov    -0x220(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xa66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x298e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
cmp    $0x5,%edi
jne    14f0 <main+0x350>
mov    0x8(%rsi),%rdi
lea    0xe38(%rip),%rax
mov    %rsi,%r14
mov    %rax,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    -0x260(%rbp),%r15
mov    $0x200,%esi
mov    %r15,%rdi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x20(%r14),%rdi
mov    %r14,%rbx
lea    0xdfb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1030 <init_frec@plt>
mov    0x10(%rbx),%rdi
mov    %rbx,%r12
mov    %rbx,-0x38(%rbp)
call   1090 <file_size@plt>
mov    %rax,%r15
lea    0x1ff(%rax),%rbx
test   %rax,%rax
cmovns %rax,%rbx
shr    $0x9,%rbx
xor    %r13d,%r13d
test   $0x1ff,%r15d
setne  %r13b
lea    0x0(%r13,%rbx,1),%edx
mov    %edx,-0x2c(%rbp)
lea    0xd67(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%r12),%rdi
call   1090 <file_size@plt>
lea    0x1ff(%rax),%r12
test   %rax,%rax
cmovns %rax,%r12
shr    $0x9,%r12
mov    %eax,%ecx
mov    %rax,%rsi
mov    %rax,-0x50(%rbp)
and    $0x1ff,%ecx
cmp    $0x1,%rcx
sbb    $0xffffffff,%r12d
lea    0xd4c(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    (%rbx,%r13,1),%ecx
add    $0x1,%ecx
lea    -0x260(%rbp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <init_frec@plt>
mov    %rbx,-0x48(%rbp)
mov    %r13,-0x40(%rbp)
lea    (%rbx,%r13,1),%edx
add    $0x4,%edx
lea    0x1(%r12),%ecx
lea    -0x260(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <init_frec@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rsp,-0x58(%rbp)
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc71(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    -0x2c(%rbp),%esi
shl    $0x9,%esi
sub    %r15d,%esi
lea    -0x260(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rsp,%rbx
mov    -0x50(%rbp),%r13
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xbd3(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
shl    $0x9,%r12d
sub    %r13d,%r12d
lea    -0x260(%rbp),%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
cmpl   $0xb39,-0x2c(%rbp)
jg     14c0 <main+0x320>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
lea    (%rcx,%rax,1),%ebx
add    $0x5,%ebx
lea    -0x260(%rbp),%r15
nop
mov    %r15,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
add    $0x1,%ebx
cmp    $0xb3f,%ebx
jl     14a0 <main+0x300>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xb8c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2afd(%rip),%rax
mov    (%rax),%eax
mov    -0x58(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb70(%rip),%rdi
call   1040 <puts@plt>
mov    0x2add(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [71 x i8] c"usage: imgmake <bootsector.bin> <kernel.bin> <initramfs> <floppy.img>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [41 x i8] c"kernel size:%ld byte(s) or %d sector(s)\0A\00"
@.str.4 = [44 x i8] c"initramfs size:%ld byte(s) or %d sector(s)\0A\00"
@.str.5 = [13 x i8] c"img builded\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
%16 = alloca i64
%17 = alloca i32*
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 5
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %7
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %7
%32 = call i32 @fread(i8* %30, i64 512, i32 1, i32* %31)
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 4
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %8
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%40 = load i32*, i32** %8
%41 = call i32 @fwrite(i8* %39, i32 512, i32 1, i32* %40)
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%43 = call i32 @memset(i8* %42, i32 0, i32 512)
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = load i32*, i32** %8
%46 = call i32 @fwrite(i8* %44, i32 512, i32 1, i32* %45)
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%48 = call i32 @init_frec(i8* %47, i32 0, i32 1, i32 2)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i64 @file_size(i8* %51)
store i64 %52, i64* %9
%53 = load i64, i64* %9
%54 = sdiv i64 %53, 512
%55 = trunc i64 %54 to i32
store i32 %55, i32* %10
%56 = load i64, i64* %9
%57 = srem i64 %56, 512
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %25
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %62
62: ; preds = %59, %25
%63 = load i64, i64* %9
%64 = load i32, i32* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i64 %63, i32 %64)
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 3
%68 = load i8*, i8** %67
%69 = call i64 @file_size(i8* %68)
store i64 %69, i64* %11
%70 = load i64, i64* %11
%71 = sdiv i64 %70, 512
%72 = trunc i64 %71 to i32
store i32 %72, i32* %12
%73 = load i64, i64* %11
%74 = srem i64 %73, 512
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %62
%77 = load i32, i32* %12
%78 = add nsw i32 %77, 1
store i32 %78, i32* %12
br label %79
79: ; preds = %76, %62
%80 = load i64, i64* %11
%81 = load i32, i32* %12
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 %80, i32 %81)
%83 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%84 = load i32, i32* %10
%85 = add nsw i32 %84, 1
%86 = call i32 @init_frec(i8* %83, i32 1, i32 3, i32 %85)
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%88 = load i32, i32* %10
%89 = add nsw i32 3, %88
%90 = add nsw i32 %89, 1
%91 = load i32, i32* %12
%92 = add nsw i32 %91, 1
%93 = call i32 @init_frec(i8* %87, i32 2, i32 %90, i32 %92)
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%95 = load i32*, i32** %8
%96 = call i32 @fwrite(i8* %94, i32 512, i32 1, i32* %95)
%97 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%98 = call i32 @memset(i8* %97, i32 0, i32 512)
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%100 = load i32*, i32** %8
%101 = call i32 @fwrite(i8* %99, i32 512, i32 1, i32* %100)
%102 = load i64, i64* %9
%103 = call i8* @llvm.stacksave()
store i8* %103, i8** %13
%104 = alloca i8, i64 %102
store i64 %102, i64* %14
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 2
%107 = load i8*, i8** %106
%108 = call i32* @fopen(i8* %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %108, i32** %15
%109 = load i64, i64* %9
%110 = load i32*, i32** %15
%111 = call i32 @fread(i8* %104, i64 %109, i32 1, i32* %110)
%112 = load i32*, i32** %15
%113 = call i32 @fclose(i32* %112)
%114 = load i64, i64* %9
%115 = trunc i64 %114 to i32
%116 = load i32*, i32** %8
%117 = call i32 @fwrite(i8* %104, i32 %115, i32 1, i32* %116)
%118 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%119 = load i32, i32* %10
%120 = mul nsw i32 %119, 512
%121 = sext i32 %120 to i64
%122 = load i64, i64* %9
%123 = sub nsw i64 %121, %122
%124 = trunc i64 %123 to i32
%125 = load i32*, i32** %8
%126 = call i32 @fwrite(i8* %118, i32 %124, i32 1, i32* %125)
%127 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%128 = call i32 @memset(i8* %127, i32 0, i32 512)
%129 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%130 = load i32*, i32** %8
%131 = call i32 @fwrite(i8* %129, i32 512, i32 1, i32* %130)
%132 = load i64, i64* %11
%133 = alloca i8, i64 %132
store i64 %132, i64* %16
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 3
%136 = load i8*, i8** %135
%137 = call i32* @fopen(i8* %136, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %137, i32** %17
%138 = load i64, i64* %11
%139 = load i32*, i32** %17
%140 = call i32 @fread(i8* %133, i64 %138, i32 1, i32* %139)
%141 = load i32*, i32** %17
%142 = call i32 @fclose(i32* %141)
%143 = load i64, i64* %11
%144 = trunc i64 %143 to i32
%145 = load i32*, i32** %8
%146 = call i32 @fwrite(i8* %133, i32 %144, i32 1, i32* %145)
%147 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%148 = load i32, i32* %12
%149 = mul nsw i32 %148, 512
%150 = sext i32 %149 to i64
%151 = load i64, i64* %11
%152 = sub nsw i64 %150, %151
%153 = trunc i64 %152 to i32
%154 = load i32*, i32** %8
%155 = call i32 @fwrite(i8* %147, i32 %153, i32 1, i32* %154)
%156 = load i32, i32* %10
%157 = add nsw i32 6, %156
store i32 %157, i32* %18
br label %158
158: ; preds = %165, %79
%159 = load i32, i32* %18
%160 = icmp slt i32 %159, 2880
br i1 %160, label %161, label %168
161: ; preds = %158
%162 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%163 = load i32*, i32** %8
%164 = call i32 @fwrite(i8* %162, i32 512, i32 1, i32* %163)
br label %165
165: ; preds = %161
%166 = load i32, i32* %18
%167 = add nsw i32 %166, 1
store i32 %167, i32* %18
br label %158
168: ; preds = %158
%169 = load i32*, i32** %8
%170 = call i32 @fclose(i32* %169)
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%172 = load i32, i32* @EXIT_SUCCESS
store i32 %172, i32* %3
%173 = load i8*, i8** %13
%174 = load i32, i32* %3
ret i32 %174
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [41 x i8] c"kernel size:%ld byte(s) or %d sector(s)\0A\00"
@.str.4 = [44 x i8] c"initramfs size:%ld byte(s) or %d sector(s)\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"img builded\00"
@str.6 = [70 x i8] c"usage: imgmake <bootsector.bin> <kernel.bin> <initramfs> <floppy.img>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = icmp eq i32 %0, 5
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.6, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @fread(i8* %10, i64 512, i32 1, i32* %13)
%15 = tail call i32 @fclose(i32* %13)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%20 = call i32 @memset(i8* %10, i32 0, i32 512)
%21 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%22 = call i32 @init_frec(i8* %10, i32 0, i32 1, i32 2)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @file_size(i8* %24)
%26 = sdiv i64 %25, 512
%27 = trunc i64 %26 to i32
%28 = and i64 %25, 511
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
%31 = add nsw i32 %30, %27
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i64 %25, i32 %31)
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = call i64 @file_size(i8* %34)
%36 = sdiv i64 %35, 512
%37 = trunc i64 %36 to i32
%38 = and i64 %35, 511
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i32
%41 = add nsw i32 %40, %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 %35, i32 %41)
%43 = add nsw i32 %31, 1
%44 = call i32 @init_frec(i8* %10, i32 1, i32 3, i32 %43)
%45 = add nsw i32 %31, 4
%46 = add nsw i32 %41, 1
%47 = call i32 @init_frec(i8* %10, i32 2, i32 %45, i32 %46)
%48 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%49 = call i32 @memset(i8* %10, i32 0, i32 512)
%50 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%51 = call i8* @llvm.stacksave()
%52 = alloca i8, i64 %25
%53 = load i8*, i8** %23
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 @fread(i8* %52, i64 %25, i32 1, i32* %54)
%56 = call i32 @fclose(i32* %54)
%57 = trunc i64 %25 to i32
%58 = call i32 @fwrite(i8* %52, i32 %57, i32 1, i32* %18)
%59 = shl nsw i32 %31, 9
%60 = sub i32 %59, %57
%61 = call i32 @fwrite(i8* %10, i32 %60, i32 1, i32* %18)
%62 = call i32 @memset(i8* %10, i32 0, i32 512)
%63 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%64 = alloca i8, i64 %35
%65 = load i8*, i8** %33
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%67 = call i32 @fread(i8* %64, i64 %35, i32 1, i32* %66)
%68 = call i32 @fclose(i32* %66)
%69 = trunc i64 %35 to i32
%70 = call i32 @fwrite(i8* %64, i32 %69, i32 1, i32* %18)
%71 = shl nsw i32 %41, 9
%72 = sub i32 %71, %69
%73 = call i32 @fwrite(i8* %10, i32 %72, i32 1, i32* %18)
%74 = icmp slt i32 %31, 2874
br i1 %74, label %75, label %77
75: ; preds = %9
%76 = add nsw i32 %31, 6
br label %81
77: ; preds = %81, %9
%78 = call i32 @fclose(i32* %18)
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%80 = load i32, i32* @EXIT_SUCCESS
ret i32 %80
81: ; preds = %75, %81
%82 = phi i32 [ %84, %81 ], [ %76, %75 ]
%83 = call i32 @fwrite(i8* %10, i32 512, i32 1, i32* %18)
%84 = add nsw i32 %82, 1
%85 = icmp slt i32 %82, 2879
br i1 %85, label %81, label %77
}