#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sony_clear(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  FILE *fp;
  char name[512], *buffer;
  int arg, length;
  for (arg = 1; arg < argc; arg++) {
    fp = fopen(argv[arg], "rb");
    if (!fp) {
      perror(argv[arg]);
      continue;
    }
    fseek(fp, 0, SEEK_END);
    length = ftell(fp);
    if (length < 0x100000) {
      fprintf(stderr, "%s is too small!\n", argv[arg]);
      fclose(fp);
      continue;
    }
    buffer = malloc(length);
    if (!buffer) {
      fprintf(stderr, "%s is too big!\n", argv[arg]);
      fclose(fp);
      continue;
    }
    fseek(fp, 0, SEEK_SET);
    fread(buffer, 1, length, fp);
    fclose(fp);
    sony_clear(buffer, length);
    strcpy(name, argv[arg]);
    strcat(name, ".clear");
    fp = fopen(name, "wb");
    fwrite(buffer, 1, length, fp);
    free(buffer);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x22c(%rbp)
mov    -0x22c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13cf <main+0x1ff>
mov    -0x10(%rbp),%rax
movslq -0x22c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xde8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <main+0x75>
mov    -0x10(%rbp),%rax
movslq -0x22c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10c0 <perror@plt>
jmp    13bb <main+0x1eb>
mov    -0x18(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x230(%rbp)
cmpl   $0x100000,-0x230(%rbp)
jge    12aa <main+0xda>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x22c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd6c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    13bb <main+0x1eb>
mov    -0x230(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    12fc <main+0x12c>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x22c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    13bb <main+0x1eb>
mov    -0x18(%rbp),%rdi
mov    0x2cc9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%esi
call   10d0 <sony_clear@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x22c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
lea    -0x220(%rbp),%rdi
lea    0xcb6(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x220(%rbp),%rdi
lea    0xcaa(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x228(%rbp),%rdi
mov    -0x230(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x228(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
jmp    11f3 <main+0x23>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x2,%edi
jl     1354 <main+0x184>
mov    %rsi,%r13
mov    %edi,%r15d
mov    $0x1,%r14d
lea    0xe03(%rip),%rbx
mov    %r15,0x8(%rsp)
jmp    123f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13,%r14,8),%rdx
lea    0xdde(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
add    $0x1,%r14
cmp    %r14,%r15
je     1354 <main+0x184>
mov    0x0(%r13,%r14,8),%rdi
mov    %rbx,%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1345 <main+0x175>
mov    %rax,%rbp
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
call   1080 <ftell@plt>
cmp    $0xfffff,%eax
jle    1210 <main+0x40>
mov    %eax,%r12d
mov    %eax,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1319 <main+0x149>
mov    %rax,%r15
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   10d0 <sony_clear@plt>
mov    0x0(%r13,%r14,8),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
lea    0xd40(%rip),%rsi
call   10e0 <strcat@plt>
mov    %rbp,%rdi
lea    0xd38(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1333 <main+0x163>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13,%r14,8),%rdx
lea    0xce7(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%r15
jmp    1232 <main+0x62>
mov    0x0(%r13,%r14,8),%rdi
call   10c0 <perror@plt>
jmp    1232 <main+0x62>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s is too small!\0A\00"
@.str.2 = [16 x i8] c"%s is too big!\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [7 x i8] c".clear\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [512 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
br label %11
11: ; preds = %96, %2
%12 = load i32, i32* %9
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %99
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @perror(i8* %29)
br label %96
31: ; preds = %15
%32 = load i32*, i32** %6
%33 = load i32, i32* @SEEK_END
%34 = call i32 @fseek(i32* %32, i32 0, i32 %33)
%35 = load i32*, i32** %6
%36 = call i32 @ftell(i32* %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 1048576
br i1 %38, label %39, label %49
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
br label %96
49: ; preds = %31
%50 = load i32, i32* %10
%51 = call i8* @malloc(i32 %50)
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = icmp ne i8* %52, null
br i1 %53, label %64, label %54
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %60)
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
br label %96
64: ; preds = %49
%65 = load i32*, i32** %6
%66 = load i32, i32* @SEEK_SET
%67 = call i32 @fseek(i32* %65, i32 0, i32 %66)
%68 = load i8*, i8** %8
%69 = load i32, i32* %10
%70 = load i32*, i32** %6
%71 = call i32 @fread(i8* %68, i32 1, i32 %69, i32* %70)
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i8*, i8** %8
%75 = load i32, i32* %10
%76 = call i32 @sony_clear(i8* %74, i32 %75)
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%78 = load i8**, i8*** %5
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @strcpy(i8* %77, i8* %82)
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%85 = call i32 @strcat(i8* %84, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%87 = call i32* @fopen(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %87, i32** %6
%88 = load i8*, i8** %8
%89 = load i32, i32* %10
%90 = load i32*, i32** %6
%91 = call i32 @fwrite(i8* %88, i32 1, i32 %89, i32* %90)
%92 = load i8*, i8** %8
%93 = call i32 @free(i8* %92)
%94 = load i32*, i32** %6
%95 = call i32 @fclose(i32* %94)
br label %96
96: ; preds = %64, %54, %39, %24
%97 = load i32, i32* %9
%98 = add nsw i32 %97, 1
store i32 %98, i32* %9
br label %11
99: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"%s is too small!\0A\00"
@.str.2 = [16 x i8] c"%s is too big!\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [7 x i8] c".clear\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %51
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %48
%9 = phi i64 [ 1, %6 ], [ %49, %48 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = call i32 @perror(i8* %15)
br label %48
17: ; preds = %8
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %12, i32 0, i32 %18)
%20 = call i32 @ftell(i32* %12)
%21 = icmp slt i32 %20, 1048576
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @fclose(i32* %12)
br label %48
27: ; preds = %17
%28 = call i8* @malloc(i32 %20)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %10
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 @fclose(i32* %12)
br label %48
35: ; preds = %27
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %12, i32 0, i32 %36)
%38 = call i32 @fread(i8* %28, i32 1, i32 %20, i32* %12)
%39 = call i32 @fclose(i32* %12)
%40 = call i32 @sony_clear(i8* %28, i32 %20)
%41 = load i8*, i8** %10
%42 = call i32 @strcpy(i8* %4, i8* %41)
%43 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @fwrite(i8* %28, i32 1, i32 %20, i32* %44)
%46 = call i32 @free(i8* %28)
%47 = call i32 @fclose(i32* %44)
br label %48
48: ; preds = %35, %30, %22, %14
%49 = add nuw nsw i64 %9, 1
%50 = icmp eq i64 %49, %7
br i1 %50, label %51, label %8
51: ; preds = %48, %2
ret i32 0
}