#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc > 1) {
    uint8_t buffer;
    FILE *fdres;
    long fsize;
    uint32_t magicnum;
    uint32_t footerbegin;
    bool erase;
    fdres = fopen(argv[1], "r+");
    if (fdres == NULL) {
      perror("fopen error");
      exit(1);
    }
    fread(&magicnum, sizeof(uint32_t), 1, fdres);
    if (magicnum != 0x0042524F) {
      printf("Incorrect magic number!\n"
             "Not a ORB ressource file!\n");
      exit(EXIT_FAILURE);
    }
    fseek(fdres, 0L, SEEK_END);
    fsize = ftell(fdres);
    fseek(fdres, 12, SEEK_SET);
    fread(&footerbegin, sizeof(uint32_t), 1, fdres);
    fseek(fdres, footerbegin, SEEK_SET);
    for (;;) {
      if (fsize == ftell(fdres)) {
        break;
      }
      erase = false;
      for (int i = 0; i < 16; ++i) {
        fread(&buffer, sizeof(uint8_t), 1, fdres);
        if (!buffer) {
          erase = true;
        }
        if (erase) {
          buffer = 0;
          fseek(fdres, -1, SEEK_CUR);
          fwrite(&buffer, sizeof(uint8_t), 1, fdres);
        }
      }
      fseek(fdres, 16, SEEK_CUR);
    }
    fclose(fdres);
    return EXIT_SUCCESS;
  }
  return EXIT_FAILURE;
}


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   $0x1,-0x8(%rbp)
jle    1379 <main+0x1e9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <main+0x59>
lea    0xe29(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmpl   $0x42524f,-0x2c(%rbp)
je     1227 <main+0x97>
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    12b1 <main+0x121>
jmp    135f <main+0x1cf>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x10,-0x38(%rbp)
jge    1343 <main+0x1b3>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12f1 <main+0x161>
movl   $0x1,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1330 <main+0x1a0>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
jmp    1335 <main+0x1a5>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12bf <main+0x12f>
mov    -0x20(%rbp),%rdi
mov    0x2c92(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1070 <fseek@plt>
jmp    128b <main+0xfb>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1385 <main+0x1f5>
mov    0x2c48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1309 <main+0x179>
mov    0x8(%rsi),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1321 <main+0x191>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmpl   $0x42524f,0xc(%rsp)
jne    1337 <main+0x1a7>
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    0x2dc1(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1070 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x1,%r12d
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0x8(%rsp),%esi
mov    (%r14),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %r15,0x10(%rsp)
cmp    %rax,%r15
je     12f8 <main+0x168>
lea    0x4(%rsp),%r15
mov    0x2d73(%rip),%r13
xor    %r14d,%r14d
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmpl   $0x0,0x4(%rsp)
cmove  %r12d,%r14d
test   %r14d,%r14d
je     12c1 <main+0x131>
movl   $0x0,0x4(%rsp)
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
add    $0x1,%ebp
cmp    $0x10,%ebp
jne    1270 <main+0xe0>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    $0x0,%ebp
mov    $0x0,%r14d
cmp    %rax,0x10(%rsp)
jne    1270 <main+0xe0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cb9(%rip),%rax
jmp    1310 <main+0x180>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcdb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xcd1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [12 x i8] c"fopen error\00"
@.str.2 = [51 x i8] c"Incorrect magic number!\0ANot a ORB ressource file!\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %86
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, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = load i32*, i32** %7
%27 = call i32 @fread(i32* %9, i32 4, i32 1, i32* %26)
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 4346447
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25
%35 = load i32*, i32** %7
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %7
%39 = call i64 @ftell(i32* %38)
store i64 %39, i64* %8
%40 = load i32*, i32** %7
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %40, i32 12, i32 %41)
%43 = load i32*, i32** %7
%44 = call i32 @fread(i32* %10, i32 4, i32 1, i32* %43)
%45 = load i32*, i32** %7
%46 = load i32, i32* %10
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @fseek(i32* %45, i32 %46, i32 %47)
br label %49
49: ; preds = %78, %34
%50 = load i64, i64* %8
%51 = load i32*, i32** %7
%52 = call i64 @ftell(i32* %51)
%53 = icmp eq i64 %50, %52
br i1 %53, label %54, label %55
54: ; preds = %49
br label %82
55: ; preds = %49
store i32 0, i32* %11
store i32 0, i32* %12
br label %56
56: ; preds = %75, %55
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, 16
br i1 %58, label %59, label %78
59: ; preds = %56
%60 = load i32*, i32** %7
%61 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %60)
%62 = load i32, i32* %6
%63 = icmp ne i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %59
store i32 1, i32* %11
br label %65
65: ; preds = %64, %59
%66 = load i32, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %65
store i32 0, i32* %6
%69 = load i32*, i32** %7
%70 = load i32, i32* @SEEK_CUR
%71 = call i32 @fseek(i32* %69, i32 -1, i32 %70)
%72 = load i32*, i32** %7
%73 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %72)
br label %74
74: ; preds = %68, %65
br label %75
75: ; preds = %74
%76 = load i32, i32* %12
%77 = add nsw i32 %76, 1
store i32 %77, i32* %12
br label %56
78: ; preds = %56
%79 = load i32*, i32** %7
%80 = load i32, i32* @SEEK_CUR
%81 = call i32 @fseek(i32* %79, i32 16, i32 %80)
br label %49
82: ; preds = %54
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
%85 = load i32, i32* @EXIT_SUCCESS
store i32 %85, i32* %3
br label %88
86: ; preds = %2
%87 = load i32, i32* @EXIT_FAILURE
store i32 %87, i32* %3
br label %88
88: ; preds = %86, %82
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [12 x i8] c"fopen error\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [50 x i8] c"Incorrect magic number!\0ANot a ORB ressource file!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %64
7: ; preds = %2
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %7
%19 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %13)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 4346447
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
%27 = load i32, i32* @SEEK_END
%28 = tail call i32 @fseek(i32* %13, i32 0, i32 %27)
%29 = tail call i64 @ftell(i32* %13)
%30 = load i32, i32* @SEEK_SET
%31 = tail call i32 @fseek(i32* %13, i32 12, i32 %30)
%32 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %13)
%33 = load i32, i32* %5
%34 = load i32, i32* @SEEK_SET
%35 = tail call i32 @fseek(i32* %13, i32 %33, i32 %34)
%36 = tail call i64 @ftell(i32* %13)
%37 = icmp eq i64 %29, %36
br i1 %37, label %61, label %43
38: ; preds = %55
%39 = load i32, i32* @SEEK_CUR
%40 = tail call i32 @fseek(i32* %13, i32 16, i32 %39)
%41 = tail call i64 @ftell(i32* %13)
%42 = icmp eq i64 %29, %41
br i1 %42, label %61, label %58
43: ; preds = %26, %58
%44 = phi i32 [ %59, %58 ], [ 0, %26 ]
%45 = phi i32 [ %60, %58 ], [ 0, %26 ]
%46 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %13)
%47 = load i32, i32* %3
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 1, i32 %45
%50 = icmp eq i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %43
store i32 0, i32* %3
%52 = load i32, i32* @SEEK_CUR
%53 = tail call i32 @fseek(i32* %13, i32 -1, i32 %52)
%54 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %13)
br label %55
55: ; preds = %43, %51
%56 = add nuw nsw i32 %44, 1
%57 = icmp eq i32 %56, 16
br i1 %57, label %38, label %58
58: ; preds = %55, %38
%59 = phi i32 [ %56, %55 ], [ 0, %38 ]
%60 = phi i32 [ %49, %55 ], [ 0, %38 ]
br label %43
61: ; preds = %38, %26
%62 = tail call i32 @fclose(i32* %13)
%63 = load i32, i32* @EXIT_SUCCESS
br label %66
64: ; preds = %2
%65 = load i32, i32* @EXIT_FAILURE
br label %66
66: ; preds = %64, %61
%67 = phi i32 [ %63, %61 ], [ %65, %64 ]
ret i32 %67
}