#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;
char *basename(char *);
int /*<<< orphan*/ convert(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    usage(argv[0]);
    exit(1);
  }
  for (int i = 1; i < argc; ++i) {
    char *infile = argv[i];
    char *outfile = malloc(strlen(infile) + 4);
    char *ext = strrchr(basename(infile), '.');
    FILE *fi;
    if (ext != NULL) {
      strcpy(outfile, infile);
      strcpy(strrchr(outfile, '.'), ".C16");
    } else {
      strcat(strcpy(outfile, infile), ".C16");
    }
    printf("%s", infile);
    fi = fopen(infile, "rb");
    if (fi == NULL) {
      puts(" cannot be opened.");
    } else {
      FILE *fo = fopen(outfile, "wb");
      if (fo == NULL) {
        puts(": Cannot open output file.");
      } else {
        fseek(fi, 0, SEEK_END);
        if (ftell(fi) != 0x1000) {
          puts(" is not 4096 bytes long.");
        } else {
          printf(" -> %s\n", outfile);
          fseek(fi, 0, SEEK_SET);
          convert(fi, fo);
        }
        fclose(fo);
      }
      fclose(fi);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1226 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13d0 <main+0x1e0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x4,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <basename@plt>
mov    %rax,%rdi
mov    $0x2e,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12b6 <main+0xc6>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1090 <strrchr@plt>
mov    %rax,%rdi
lea    0xd54(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12d1 <main+0xe1>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %eax,%edi
lea    0xd34(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x20(%rbp),%rsi
lea    0xd29(%rip),%rdi
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd1c(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1311 <main+0x121>
lea    0xd04(%rip),%rdi
call   1050 <puts@plt>
jmp    13bd <main+0x1cd>
mov    -0x28(%rbp),%rdi
lea    0xd02(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1341 <main+0x151>
lea    0xcea(%rip),%rdi
call   1050 <puts@plt>
jmp    13b4 <main+0x1c4>
mov    -0x38(%rbp),%rdi
mov    0x2c9c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <ftell@plt>
cmp    $0x1000,%eax
je     137a <main+0x18a>
lea    0xccc(%rip),%rdi
call   1050 <puts@plt>
jmp    13ab <main+0x1bb>
mov    -0x28(%rbp),%rsi
lea    0xcd0(%rip),%rdi
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2c43(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <convert@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
jmp    13c2 <main+0x1d2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122d <main+0x3d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
cmp    $0x2,%edi
jl     1380 <main+0x190>
mov    %edi,%r12d
mov    $0x1,%r15d
jmp    1239 <main+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xde4(%rip),%rdi
call   1050 <puts@plt>
add    $0x1,%r15
cmp    %r15,%r12
je     136f <main+0x17f>
mov    (%rsp),%rax
mov    (%rax,%r15,8),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    0x4(%rax),%rdi
call   10c0 <malloc@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   10b0 <basename@plt>
mov    %rax,%rdi
mov    $0x2e,%esi
call   1090 <strrchr@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
test   %rbx,%rbx
je     12a0 <main+0xb0>
mov    %r13,%rdi
mov    $0x2e,%esi
call   1090 <strrchr@plt>
mov    %rax,%rdi
lea    0xd6c(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12ae <main+0xbe>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
lea    0xd57(%rip),%rsi
call   1100 <strcat@plt>
lea    0xd50(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    %rbp,%rdi
lea    0xd41(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1220 <main+0x30>
mov    %rax,%rbp
mov    %r13,%rdi
lea    0xd3c(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1340 <main+0x150>
mov    %rax,%r14
mov    0x2cf2(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
cmp    $0x1000,%eax
jne    134e <main+0x15e>
lea    0xd3d(%rip),%rdi
mov    %r13,%rsi
call   1080 <printf@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <convert@plt>
jmp    135a <main+0x16a>
lea    0xcda(%rip),%rdi
call   1050 <puts@plt>
jmp    1362 <main+0x172>
lea    0xce7(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    122c <main+0x3c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
mov    (%rax),%rdi
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".C16\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [19 x i8] c" cannot be opened.\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [27 x i8] c": Cannot open output file.\00"
@SEEK_END = global i32 0
@.str.6 = [25 x i8] c" is not 4096 bytes long.\00"
@.str.7 = [8 x i8] c" -> %s\0A\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @usage(i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store i32 1, i32* %6
br label %21
21: ; preds = %93, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %96
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 4
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %8
%35 = load i8*, i8** %7
%36 = call i8* @basename(i8* %35)
%37 = call i8* @strrchr(i8* %36, i8 signext 46)
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %47
40: ; preds = %25
%41 = load i8*, i8** %8
%42 = load i8*, i8** %7
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i8*, i8** %8
%45 = call i8* @strrchr(i8* %44, i8 signext 46)
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %52
47: ; preds = %25
%48 = load i8*, i8** %8
%49 = load i8*, i8** %7
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = call i32 @strcat(i32 %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %47, %40
%53 = load i8*, i8** %7
%54 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i8*, i8** %7
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %56, i32** %10
%57 = load i32*, i32** %10
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %92
61: ; preds = %52
%62 = load i8*, i8** %8
%63 = call i32* @fopen(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %63, i32** %11
%64 = load i32*, i32** %11
%65 = icmp eq i32* %64, null
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %89
68: ; preds = %61
%69 = load i32*, i32** %10
%70 = load i32, i32* @SEEK_END
%71 = call i32 @fseek(i32* %69, i32 0, i32 %70)
%72 = load i32*, i32** %10
%73 = call i32 @ftell(i32* %72)
%74 = icmp ne i32 %73, 4096
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %86
77: ; preds = %68
%78 = load i8*, i8** %8
%79 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %78)
%80 = load i32*, i32** %10
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @fseek(i32* %80, i32 0, i32 %81)
%83 = load i32*, i32** %10
%84 = load i32*, i32** %11
%85 = call i32 @convert(i32* %83, i32* %84)
br label %86
86: ; preds = %77, %75
%87 = load i32*, i32** %11
%88 = call i32 @fclose(i32* %87)
br label %89
89: ; preds = %86, %66
%90 = load i32*, i32** %10
%91 = call i32 @fclose(i32* %90)
br label %92
92: ; preds = %89, %59
br label %93
93: ; preds = %92
%94 = load i32, i32* %6
%95 = add nsw i32 %94, 1
store i32 %95, i32* %6
br label %21
96: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c".C16\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [19 x i8] c" cannot be opened.\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [27 x i8] c": Cannot open output file.\00"
@SEEK_END = global i32 0
@.str.6 = [25 x i8] c" is not 4096 bytes long.\00"
@.str.7 = [8 x i8] c" -> %s\0A\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %11
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %54
ret i32 0
11: ; preds = %4, %54
%12 = phi i64 [ 1, %4 ], [ %55, %54 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = add nsw i64 %15, 4
%17 = tail call i8* @malloc(i64 %16)
%18 = tail call i8* @basename(i8* %14)
%19 = tail call i8* @strrchr(i8* dereferenceable(1) %18, i8 signext 46)
%20 = icmp eq i8* %19, null
%21 = tail call i32 @strcpy(i8* %17, i8* %14)
br i1 %20, label %25, label %22
22: ; preds = %11
%23 = tail call i8* @strrchr(i8* dereferenceable(1) %17, i8 signext 46)
%24 = tail call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %27
25: ; preds = %11
%26 = tail call i32 @strcat(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%29 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %54
33: ; preds = %27
%34 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %52
38: ; preds = %33
%39 = load i32, i32* @SEEK_END
%40 = tail call i32 @fseek(i32* %29, i32 0, i32 %39)
%41 = tail call i32 @ftell(i32* %29)
%42 = icmp eq i32 %41, 4096
br i1 %42, label %45, label %43
43: ; preds = %38
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %50
45: ; preds = %38
%46 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %17)
%47 = load i32, i32* @SEEK_SET
%48 = tail call i32 @fseek(i32* %29, i32 0, i32 %47)
%49 = tail call i32 @convert(i32* %29, i32* %34)
br label %50
50: ; preds = %45, %43
%51 = tail call i32 @fclose(i32* %34)
br label %52
52: ; preds = %50, %36
%53 = tail call i32 @fclose(i32* %29)
br label %54
54: ; preds = %52, %31
%55 = add nuw nsw i64 %12, 1
%56 = icmp eq i64 %55, %5
br i1 %56, label %10, label %11
}