#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 */
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
int /*<<< orphan*/ makerom_copy(int, int);
int /*<<< orphan*/ makerom_pad(int, int, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ sum_write(int, int);
void makerom_process(int ifd, int ofd) {
  struct stat ifstat;
  if (fstat(ifd, &ifstat) == -1) {
    fprintf(stderr, "error stating input file\n");
  }
  makerom_copy(ifd, ofd);
  makerom_pad(ifd, ofd, ifstat.st_size, 1024 * 512);
  sum_write(ofd, 1024 * 512);
  printf("makerom: %lld out of %d kB used\n", ifstat.st_size / 1024,
         1024 * 512 / 1024);
}


x86 assembly (clang, -O0):
<makerom_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1198 <makerom_process+0x38>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <makerom_copy@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x80000,%ecx
call   1050 <makerom_pad@plt>
mov    -0x8(%rbp),%edi
mov    $0x80000,%esi
call   1070 <sum_write@plt>
mov    -0x10(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe43(%rip),%rdi
mov    $0x200,%edx
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makerom_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x8(%rsp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1191 <makerom_process+0x31>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <makerom_copy@plt>
mov    0x8(%rsp),%ebx
mov    %ebp,%edi
mov    %r14d,%esi
mov    %ebx,%edx
mov    $0x80000,%ecx
call   1050 <makerom_pad@plt>
mov    %r14d,%edi
mov    $0x80000,%esi
call   1070 <sum_write@plt>
lea    0x3ff(%rbx),%esi
test   %ebx,%ebx
cmovns %ebx,%esi
sar    $0xa,%esi
lea    0xe48(%rip),%rdi
mov    $0x200,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"error stating input file\0A\00"
@.str.1 = [33 x i8] c"makerom: %lld out of %d kB used\0A\00"
define void @makerom_process(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @fstat(i32 %6, %struct.stat* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @makerom_copy(i32 %13, i32 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @makerom_pad(i32 %16, i32 %17, i32 %19, i32 524288)
%21 = load i32, i32* %4
%22 = call i32 @sum_write(i32 %21, i32 524288)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sdiv i32 %24, 1024
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 512)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"error stating input file\0A\00"
@.str.1 = [33 x i8] c"makerom: %lld out of %d kB used\0A\00"
define void @makerom_process(i32 %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @fstat(i32 %0, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = tail call i32 @makerom_copy(i32 %0, i32 %1)
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @makerom_pad(i32 %0, i32 %1, i32 %13, i32 524288)
%15 = tail call i32 @sum_write(i32 %1, i32 524288)
%16 = sdiv i32 %13, 1024
%17 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 512)
ret void
}