#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int rrd(char *, char *);
int /*<<< orphan*/ wrt(char *, char *, int);
int main(int argc, char *argv[]) {
  char *buf = (char *)malloc(16384 * 1024);
  ;
  memset(buf, 0xff, 16384 * 1024);
  rrd("header.bin", buf);
  int klen = rrd("signed.bin", buf + 512);
  klen += 511;
  klen -= klen % 512;
  *(int *)(buf + 0x30) = klen / 512;
  wrt("final.bin", buf, 512 + klen);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000000,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1050 <rrd@plt>
mov    -0x18(%rbp),%rsi
add    $0x200,%rsi
lea    0xe72(%rip),%rdi
call   1050 <rrd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1ff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x200,%edx
lea    0xe2f(%rip),%rdi
call   1060 <wrt@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1000000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xff,%esi
mov    $0x1000000,%edx
call   1030 <memset@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1050 <rrd@plt>
lea    0x200(%rbx),%rsi
lea    0xe8e(%rip),%rdi
call   1050 <rrd@plt>
lea    0x1ff(%rax),%ecx
add    $0x3fe,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
mov    %eax,%edx
and    $0xfffffe00,%edx
sar    $0x9,%eax
mov    %eax,0x30(%rbx)
add    $0x200,%edx
lea    0xe69(%rip),%rdi
mov    %rbx,%rsi
call   1060 <wrt@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"header.bin\00"
@.str.1 = [11 x i8] c"signed.bin\00"
@.str.2 = [10 x i8] c"final.bin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @malloc(i32 16777216)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 255, i32 16777216)
%12 = load i8*, i8** %6
%13 = call i32 @rrd(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 512
%16 = call i32 @rrd(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 511
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = srem i32 %19, 512
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, %20
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = sdiv i32 %23, 512
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 48
%27 = bitcast i8* %26 to i32*
store i32 %24, i32* %27
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = add nsw i32 512, %29
%31 = call i32 @wrt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"header.bin\00"
@.str.1 = [11 x i8] c"signed.bin\00"
@.str.2 = [10 x i8] c"final.bin\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 16777216)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 255, i32 16777216)
%6 = tail call i32 @rrd(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = getelementptr inbounds i8, i8* %4, i64 512
%8 = tail call i32 @rrd(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = add nsw i32 %8, 511
%10 = srem i32 %9, 512
%11 = sdiv i32 %9, 512
%12 = getelementptr inbounds i8, i8* %4, i64 48
%13 = bitcast i8* %12 to i32*
store i32 %11, i32* %13
%14 = add i32 %8, 1023
%15 = sub i32 %14, %10
%16 = tail call i32 @wrt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %15)
ret i32 0
}