#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 /*<<< orphan*/, 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);
  }
  memset(buf, 0, blocksize);
  while ((n = fread(buf, sizeof(char), blocksize, fin))) {
    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>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     1329 <main+0x189>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
jmp    12ee <main+0x14e>
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    12a5 <main+0xf5>
mov    0x8(%rbx),%rdi
lea    0xe5c(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b1 <main+0x101>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b7 <main+0x107>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
test   %eax,%eax
js     128f <main+0xdf>
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     128f <main+0xdf>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1080 <memset@plt>
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     126a <main+0xba>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   10d0 <fwrite@plt>
jmp    1240 <main+0x90>
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    0xdc4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    (%rbx),%rsi
lea    0xd51(%rip),%rdi
jmp    12c2 <main+0x112>
mov    0x8(%rbx),%rsi
jmp    12bb <main+0x10b>
mov    0x10(%rbx),%rsi
lea    0xd6b(%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
%68 = load i8*, i8** %8
%69 = load i32, i32* %10
%70 = call i32 @memset(i8* %68, i32 0, i32 %69)
br label %71
71: ; preds = %77, %67
%72 = load i8*, i8** %8
%73 = load i32, i32* %10
%74 = load i32*, i32** %6
%75 = call i32 @fread(i8* %72, i32 1, i32 %73, i32* %74)
store i32 %75, i32* %9
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %71
%78 = load i8*, i8** %8
%79 = load i32, i32* %10
%80 = load i32*, i32** %7
%81 = call i32 @fwrite(i8* %78, i32 1, i32 %79, i32* %80)
br label %71
82: ; preds = %71
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %7
%88 = call i32 @fclose(i32* %87)
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 %39, label %42
39: ; preds = %34
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = tail call i32 @memset(i8* %37, i32 0, i32 %29)
%44 = tail call i32 @fread(i8* %37, i32 1, i32 %29, i32* %11)
%45 = icmp eq i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42, %46
%47 = tail call i32 @fwrite(i8* %37, i32 1, i32 %29, i32* %20)
%48 = tail call i32 @fread(i8* %37, i32 1, i32 %29, i32* %11)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %46
50: ; preds = %46, %42
%51 = tail call i32 @free(i8* %37)
%52 = tail call i32 @fclose(i32* %11)
%53 = tail call i32 @fclose(i32* %20)
ret i32 0
}