#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *i, *o;
  int x, s;
  char buf[2352];
  if (argc < 3) {
    printf("getpsxiso <input> <output>\n");
    return -1;
  }
  i = fopen(argv[1], "rb");
  if (i == NULL) {
    printf("Could not open specified input file.\n");
    return -1;
  }
  fseek(i, 0, SEEK_END);
  s = ftell(i) / 2352;
  fseek(i, 0, SEEK_SET);
  if (s % 2352 == 0) {
    printf("Input file size not a multiplier of 2352.\n");
    printf("Aborting.\n");
    return -1;
  }
  o = fopen(argv[2], "wb");
  for (x = 0; x < s; x++) {
    fread(buf, sizeof(char), 2352, i);
    fwrite(buf + 24, sizeof(char), 2048, o);
    printf("Sector %d/%d written\r", x + 1, s);
  }
  printf("\n");
  fclose(i);
  fclose(o);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x960,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ad <main+0x3d>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ea <main+0x7a>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    -0x18(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    $0x930,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x28(%rbp),%eax
mov    $0x930,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1262 <main+0xf2>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12ea <main+0x17a>
lea    -0x960(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x930,%edx
call   1030 <fread@plt>
lea    -0x960(%rbp),%rdi
add    $0x18,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1090 <fwrite@plt>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%edx
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1281 <main+0x111>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x960,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x938,%rsp
cmp    $0x2,%edi
jg     11b2 <main+0x22>
lea    0xec8(%rip),%rdi
jmp    12e7 <main+0x157>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe40(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12cb <main+0x13b>
mov    %rax,%r14
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %eax,%ebp
cltq
imul   $0x6f74ae27,%rax,%r13
mov    %r13,%rax
shr    $0x3f,%rax
sar    $0x2a,%r13
add    %eax,%r13d
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
imul   $0x8b51d9b,%r13d,%eax
add    $0xdee950,%eax
ror    $0x4,%eax
cmp    $0x1bdd2a,%eax
jbe    12d4 <main+0x144>
mov    0x10(%r15),%rdi
lea    0xdc6(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
cmp    $0x930,%ebp
jl     12ad <main+0x11d>
mov    %r13d,%ebx
neg    %ebx
mov    $0x1,%ebp
lea    0xda8(%rip),%r12
xchg   %ax,%ax
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x930,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
lea    0x18(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1260 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    12f1 <main+0x161>
lea    0xd7e(%rip),%rdi
jmp    12e7 <main+0x157>
lea    0xd41(%rip),%rdi
call   1040 <puts@plt>
lea    0xd5f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x938,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"getpsxiso <input> <output>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [38 x i8] c"Could not open specified input file.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [43 x i8] c"Input file size not a multiplier of 2352.\0A\00"
@.str.4 = [11 x i8] c"Aborting.\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [22 x i8] c"Sector %d/%d written\0D\00"
@.str.7 = [2 x i8] c"\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 i32
%9 = alloca i32
%10 = alloca [2352 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
24: ; preds = %15
%25 = load i32*, i32** %6
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %6
%29 = call i32 @ftell(i32* %28)
%30 = sdiv i32 %29, 2352
store i32 %30, i32* %9
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32, i32* %9
%35 = srem i32 %34, 2352
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %24
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
40: ; preds = %24
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %44, i32** %7
store i32 0, i32* %8
br label %45
45: ; preds = %61, %40
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %64
49: ; preds = %45
%50 = getelementptr inbounds [2352 x i8], [2352 x i8]* %10, i64 0, i64 0
%51 = load i32*, i32** %6
%52 = call i32 @fread(i8* %50, i32 1, i32 2352, i32* %51)
%53 = getelementptr inbounds [2352 x i8], [2352 x i8]* %10, i64 0, i64 0
%54 = getelementptr inbounds i8, i8* %53, i64 24
%55 = load i32*, i32** %7
%56 = call i32 @fwrite(i8* %54, i32 1, i32 2048, i32* %55)
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
%59 = load i32, i32* %9
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %58, i32 %59)
br label %61
61: ; preds = %49
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %45
64: ; preds = %45
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %3
br label %70
70: ; preds = %64, %37, %22, %13
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [22 x i8] c"Sector %d/%d written\0D\00"
@str = [42 x i8] c"Input file size not a multiplier of 2352.\00"
@str.8 = [10 x i8] c"Aborting.\00"
@str.9 = [37 x i8] c"Could not open specified input file.\00"
@str.10 = [27 x i8] c"getpsxiso <input> <output>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2352 x i8]
%4 = getelementptr inbounds [2352 x i8], [2352 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
br label %45
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 %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.9, i64 0, i64 0))
br label %45
15: ; preds = %8
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %11, i32 0, i32 %16)
%18 = tail call i32 @ftell(i32* %11)
%19 = sdiv i32 %18, 2352
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %11, i32 0, i32 %20)
%22 = srem i32 %19, 2352
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
br label %45
27: ; preds = %15
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp sgt i32 %18, 2351
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = getelementptr inbounds [2352 x i8], [2352 x i8]* %3, i64 0, i64 24
br label %34
34: ; preds = %32, %34
%35 = phi i32 [ 0, %32 ], [ %38, %34 ]
%36 = call i32 @fread(i8* %4, i32 1, i32 2352, i32* %11)
%37 = call i32 @fwrite(i8* %33, i32 1, i32 2048, i32* %30)
%38 = add nuw nsw i32 %35, 1
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %38, i32 %19)
%40 = icmp eq i32 %38, %19
br i1 %40, label %41, label %34
41: ; preds = %34, %27
%42 = tail call i32 @putchar(i32 10)
%43 = tail call i32 @fclose(i32* %11)
%44 = tail call i32 @fclose(i32* %30)
br label %45
45: ; preds = %41, %24, %13, %6
%46 = phi i32 [ -1, %6 ], [ -1, %13 ], [ -1, %24 ], [ 0, %41 ]
ret i32 %46
}