#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fin, *fout;
  char *buf;
  int n;
  int blocksize;
  if (argc != 4) {
    printf("usage: %s InputFile PaddedFile BlockSize\n", argv[0]);
    exit(1);
  }
  fin = fopen(argv[1], "rb");
  if (fin == NULL) {
    printf("Error opening %s\n", argv[1]);
    exit(1);
  }
  fout = fopen(argv[2], "wb");
  if (fout == NULL) {
    printf("Error opening %s\n", argv[2]);
    exit(1);
  }
  blocksize = strtol(argv[3], NULL, 0);
  if (blocksize < 0) {
    printf("Error in blocksize\n");
    exit(1);
  }
  printf("blocksize = %d (0x%0x)\n", blocksize, blocksize);
  buf = (char *)malloc(blocksize);
  if (buf == NULL) {
    printf("Error in blocksize\n");
    exit(1);
  }
  while ((n = fread(buf, sizeof(char), blocksize, fin)) == blocksize) {
    fwrite(buf, sizeof(char), blocksize, fout);
  }
  memset(buf + n, 0xff, blocksize - n);
  fwrite(buf, sizeof(char), blocksize, fout);
  free(buf);
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11df <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1222 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1265 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    129d <main+0xfd>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12e0 <main+0x140>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12e5 <main+0x145>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmp    -0x30(%rbp),%eax
jne    1320 <main+0x180>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
jmp    12e5 <main+0x145>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%edx
sub    -0x2c(%rbp),%edx
mov    $0xff,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    12cd <main+0x11d>
mov    0x8(%rbx),%rdi
lea    0xe5c(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0x129>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12df <main+0x12f>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
test   %eax,%eax
js     12b7 <main+0x107>
mov    %eax,%ebp
lea    0xe29(%rip),%rdi
mov    %eax,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12b7 <main+0x107>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
cmp    %eax,%ebp
jne    126a <main+0xba>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   10d0 <fwrite@plt>
jmp    1240 <main+0x90>
cltq
mov    %rbx,%rdi
add    %rax,%rdi
mov    %ebp,%edx
sub    %eax,%edx
mov    $0xff,%esi
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    (%rbx),%rsi
lea    0xd29(%rip),%rdi
jmp    12ea <main+0x13a>
mov    0x8(%rbx),%rsi
jmp    12e3 <main+0x133>
mov    0x10(%rbx),%rsi
lea    0xd43(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"usage: %s InputFile PaddedFile BlockSize\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Error opening %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [20 x i8] c"Error in blocksize\0A\00"
@.str.5 = [24 x i8] c"blocksize = %d (0x%0x)\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 i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, 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 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32 @strtol(i8* %48, i32* null, i32 0)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
%56 = load i32, i32* %10
%57 = load i32, i32* %10
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %56, i32 %57)
%59 = load i32, i32* %10
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i8*
store i8* %61, i8** %8
%62 = load i8*, i8** %8
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %55
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %55
br label %68
68: ; preds = %75, %67
%69 = load i8*, i8** %8
%70 = load i32, i32* %10
%71 = load i32*, i32** %6
%72 = call i32 @fread(i8* %69, i32 1, i32 %70, i32* %71)
store i32 %72, i32* %9
%73 = load i32, i32* %10
%74 = icmp eq i32 %72, %73
br i1 %74, label %75, label %80
75: ; preds = %68
%76 = load i8*, i8** %8
%77 = load i32, i32* %10
%78 = load i32*, i32** %7
%79 = call i32 @fwrite(i8* %76, i32 1, i32 %77, i32* %78)
br label %68
80: ; preds = %68
%81 = load i8*, i8** %8
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i32, i32* %10
%86 = load i32, i32* %9
%87 = sub nsw i32 %85, %86
%88 = call i32 @memset(i8* %84, i32 255, i32 %87)
%89 = load i8*, i8** %8
%90 = load i32, i32* %10
%91 = load i32*, i32** %7
%92 = call i32 @fwrite(i8* %89, i32 1, i32 %90, i32* %91)
%93 = load i8*, i8** %8
%94 = call i32 @free(i8* %93)
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
%97 = load i32*, i32** %7
%98 = call i32 @fclose(i32* %97)
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"usage: %s InputFile PaddedFile BlockSize\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Error opening %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"blocksize = %d (0x%0x)\0A\00"
@str.6 = [19 x i8] c"Error in blocksize\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8*, i8** %18
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 @strtol(i8* nocapture %28, i32* null, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %29, i32 %29)
%36 = tail call i64 @malloc(i32 %29)
%37 = inttoptr i64 %36 to i8*
%38 = icmp eq i64 %36, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = tail call i32 @fread(i8* %37, i32 1, i32 %29, i32* %11)
%41 = icmp eq i32 %29, %40
br i1 %41, label %45, label %49
42: ; preds = %34
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %39, %45
%46 = tail call i32 @fwrite(i8* %37, i32 1, i32 %29, i32* %20)
%47 = tail call i32 @fread(i8* %37, i32 1, i32 %29, i32* %11)
%48 = icmp eq i32 %29, %47
br i1 %48, label %45, label %49
49: ; preds = %45, %39
%50 = phi i32 [ %40, %39 ], [ %47, %45 ]
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %37, i64 %51
%53 = sub nsw i32 %29, %50
%54 = tail call i32 @memset(i8* %52, i32 255, i32 %53)
%55 = tail call i32 @fwrite(i8* %37, i32 1, i32 %29, i32* %20)
%56 = tail call i32 @free(i8* %37)
%57 = tail call i32 @fclose(i32* %11)
%58 = tail call i32 @fclose(i32* %20)
ret i32 0
}