#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 Iso2Raw_licenseFile(char *licFile, char *binFile) {
  FILE *lic, *bin;
  char buffer[37632];
  int sz;
  int ret;
  lic = fopen(licFile, "rb");
  if (lic == NULL) {
    printf("Error! Could not open license file!\n");
    ret = 0;
    goto Iso2Raw_licenseFile_end;
  }
  bin = fopen(binFile, "rb+");
  if (bin == NULL) {
    printf("Error! Could not open BIN file!\n");
    fclose(lic);
    ret = 0;
    goto Iso2Raw_licenseFile_end;
  }
  fseek(lic, 0, SEEK_END);
  sz = ftell(lic);
  fseek(lic, 0, SEEK_SET);
  if (sz != 37632) {
    printf("Error! License file size mismatch. Image not licensed!\n");
    fclose(lic);
    fclose(bin);
    ret = 0;
    goto Iso2Raw_licenseFile_end;
  }
  fseek(bin, 0, SEEK_END);
  sz = ftell(bin);
  fseek(bin, 0, SEEK_SET);
  if ((sz % 2352) != 0) {
    printf("Error! RAW image file size is not a multiple of 2352. Image not "
           "licensed!\n");
    fclose(lic);
    fclose(bin);
    ret = 0;
    goto Iso2Raw_licenseFile_end;
  }
  fread(buffer, sizeof(char), 37632, lic);
  fwrite(buffer, sizeof(char), 37632, bin);
  fclose(lic);
  fclose(bin);
  ret = 1;
Iso2Raw_licenseFile_end:
  if (ret == 0)
    printf("Error licensing file! You must NOT burn the RAW image!\n");
  return ret;
}


x86 assembly (clang, -O0):
<Iso2Raw_licenseFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9330,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <Iso2Raw_licenseFile+0x4d>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x9328(%rbp)
jmp    133f <Iso2Raw_licenseFile+0x1cf>
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1200 <Iso2Raw_licenseFile+0x90>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x9328(%rbp)
jmp    133f <Iso2Raw_licenseFile+0x1cf>
mov    -0x18(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x9324(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
cmpl   $0x9300,-0x9324(%rbp)
je     1274 <Iso2Raw_licenseFile+0x104>
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x9328(%rbp)
jmp    133f <Iso2Raw_licenseFile+0x1cf>
mov    -0x20(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x9324(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x9324(%rbp),%eax
mov    $0x930,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ef <Iso2Raw_licenseFile+0x17f>
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x9328(%rbp)
jmp    133f <Iso2Raw_licenseFile+0x1cf>
lea    -0x9320(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x9300,%edx
call   1030 <fread@plt>
lea    -0x9320(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x9300,%edx
call   1090 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x9328(%rbp)
cmpl   $0x0,-0x9328(%rbp)
jne    1358 <Iso2Raw_licenseFile+0x1e8>
lea    0xd7d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x9328(%rbp),%eax
add    $0x9330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Iso2Raw_licenseFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9300,%rsp
mov    %rsi,%rbp
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1233 <Iso2Raw_licenseFile+0xc3>
mov    %rax,%rbx
lea    0xe62(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1241 <Iso2Raw_licenseFile+0xd1>
mov    %rax,%r14
mov    0x2e2c(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    0x2dfe(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0x9300,%ebp
jne    1252 <Iso2Raw_licenseFile+0xe2>
mov    (%r15),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
imul   $0x8b51d9b,%ebp,%eax
add    $0xdee950,%eax
ror    $0x4,%eax
cmp    $0x1bdd2b,%eax
jb     128e <Iso2Raw_licenseFile+0x11e>
lea    0xe0d(%rip),%rdi
jmp    1259 <Iso2Raw_licenseFile+0xe9>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
jmp    126e <Iso2Raw_licenseFile+0xfe>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
jmp    1269 <Iso2Raw_licenseFile+0xf9>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd92(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x9300,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r15
mov    $0x1,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x9300,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x9300,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    127c <Iso2Raw_licenseFile+0x10c>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [37 x i8] c"Error! Could not open license file!\0A\00"
@.str.2 = [4 x i8] c"rb+\00"
@.str.3 = [33 x i8] c"Error! Could not open BIN file!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [56 x i8] c"Error! License file size mismatch. Image not licensed!\0A\00"
@.str.5 = [75 x i8] c"Error! RAW image file size is not a multiple of 2352. Image not licensed!\0A\00"
@.str.6 = [56 x i8] c"Error licensing file! You must NOT burn the RAW image!\0A\00"
define i32 @Iso2Raw_licenseFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [37632 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
br label %71
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %9
br label %71
25: ; preds = %16
%26 = load i32*, i32** %5
%27 = load i32, i32* @SEEK_END
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
%29 = load i32*, i32** %5
%30 = call i32 @ftell(i32* %29)
store i32 %30, i32* %8
%31 = load i32*, i32** %5
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 37632
br i1 %35, label %36, label %42
36: ; preds = %25
%37 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32*, i32** %5
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %9
br label %71
42: ; preds = %25
%43 = load i32*, i32** %6
%44 = load i32, i32* @SEEK_END
%45 = call i32 @fseek(i32* %43, i32 0, i32 %44)
%46 = load i32*, i32** %6
%47 = call i32 @ftell(i32* %46)
store i32 %47, i32* %8
%48 = load i32*, i32** %6
%49 = load i32, i32* @SEEK_SET
%50 = call i32 @fseek(i32* %48, i32 0, i32 %49)
%51 = load i32, i32* %8
%52 = srem i32 %51, 2352
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %42
%55 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32*, i32** %5
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
store i32 0, i32* %9
br label %71
60: ; preds = %42
%61 = getelementptr inbounds [37632 x i8], [37632 x i8]* %7, i64 0, i64 0
%62 = load i32*, i32** %5
%63 = call i32 @fread(i8* %61, i32 1, i32 37632, i32* %62)
%64 = getelementptr inbounds [37632 x i8], [37632 x i8]* %7, i64 0, i64 0
%65 = load i32*, i32** %6
%66 = call i32 @fwrite(i8* %64, i32 1, i32 37632, i32* %65)
%67 = load i32*, i32** %5
%68 = call i32 @fclose(i32* %67)
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
store i32 1, i32* %9
br label %71
71: ; preds = %60, %54, %36, %21, %14
%72 = load i32, i32* %9
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %71
%75 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
%77 = load i32, i32* %9
ret i32 %77
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.2 = [4 x i8] c"rb+\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [55 x i8] c"Error licensing file! You must NOT burn the RAW image!\00"
@str.7 = [74 x i8] c"Error! RAW image file size is not a multiple of 2352. Image not licensed!\00"
@str.8 = [55 x i8] c"Error! License file size mismatch. Image not licensed!\00"
@str.9 = [32 x i8] c"Error! Could not open BIN file!\00"
@str.10 = [36 x i8] c"Error! Could not open license file!\00"
define i32 @Iso2Raw_licenseFile(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [37632 x i8]
%4 = getelementptr inbounds [37632 x i8], [37632 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.10, i64 0, i64 0))
br label %43
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0))
%14 = tail call i32 @fclose(i32* %5)
br label %43
15: ; preds = %9
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %5, i32 0, i32 %16)
%18 = tail call i32 @ftell(i32* %5)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %5, i32 0, i32 %19)
%21 = icmp eq i32 %18, 37632
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.8, i64 0, i64 0))
%24 = tail call i32 @fclose(i32* %5)
%25 = tail call i32 @fclose(i32* %10)
br label %43
26: ; preds = %15
%27 = load i32, i32* @SEEK_END
%28 = tail call i32 @fseek(i32* %10, i32 0, i32 %27)
%29 = tail call i32 @ftell(i32* %10)
%30 = load i32, i32* @SEEK_SET
%31 = tail call i32 @fseek(i32* %10, i32 0, i32 %30)
%32 = srem i32 %29, 2352
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %26
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.7, i64 0, i64 0))
%36 = tail call i32 @fclose(i32* %5)
%37 = tail call i32 @fclose(i32* %10)
br label %43
38: ; preds = %26
%39 = call i32 @fread(i8* %4, i32 1, i32 37632, i32* %5)
%40 = call i32 @fwrite(i8* %4, i32 1, i32 37632, i32* %10)
%41 = tail call i32 @fclose(i32* %5)
%42 = tail call i32 @fclose(i32* %10)
br label %45
43: ; preds = %34, %22, %12, %7
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %38, %43
%46 = phi i32 [ 0, %43 ], [ 1, %38 ]
ret i32 %46
}