#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 3)
    return -1;
  srand(time(NULL));
  FILE *pf = fopen(argv[1], "rb+");
  unsigned int size = atoi(argv[2]);
  printf("%d bytes\n", size);
  fseek(pf, 0, 2);
  while (ftell(pf) < size)
    fputc(rand() % 256, pf);
  fclose(pf);
  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)
cmpl   $0x3,-0x8(%rbp)
je     11cc <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <main+0xc4>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
cmp    -0x1c(%rbp),%eax
jae    1254 <main+0xb4>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1223 <main+0x83>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x3,%edi
jne    124a <main+0xaa>
mov    %rsi,%rbp
xor    %r14d,%r14d
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x8(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
lea    0xe18(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1090 <fseek@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <ftell@plt>
cmp    %ebp,%eax
jae    1242 <main+0xa2>
xor    %eax,%eax
call   10c0 <rand@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
jmp    1210 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [10 x i8] c"%d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %39
11: ; preds = %2
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %6
%25 = call i32 @fseek(i32* %24, i32 0, i32 2)
br label %26
26: ; preds = %31, %11
%27 = load i32*, i32** %6
%28 = call i32 @ftell(i32* %27)
%29 = load i32, i32* %7
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = call i32 (...) @rand()
%33 = srem i32 %32, 256
%34 = load i32*, i32** %6
%35 = call i32 @fputc(i32 %33, i32* %34)
br label %26
36: ; preds = %26
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %36, %10
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [10 x i8] c"%d bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @fseek(i32* %9, i32 0, i32 2)
%15 = tail call i32 @ftell(i32* %9)
%16 = icmp ult i32 %15, %12
br i1 %16, label %17, label %23
17: ; preds = %4, %17
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 256
%20 = tail call i32 @fputc(i32 %19, i32* %9)
%21 = tail call i32 @ftell(i32* %9)
%22 = icmp ult i32 %21, %12
br i1 %22, label %17, label %23
23: ; preds = %17, %4
%24 = tail call i32 @fclose(i32* %9)
br label %25
25: ; preds = %2, %23
%26 = phi i32 [ 0, %23 ], [ -1, %2 ]
ret i32 %26
}