#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 EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fin, *fout;
  size_t mysize;
  int val, i;
  int audio[8] = {0x40, 0x00, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11};
  int audioi = 0;
  int audiofound = 0;
  int offset = 0;
  int lastaudio = 0;
  if (argc == 2) {
    printf("[inputfile=%s]\n", argv[1]);
  } else {
    printf("more arguments needed... %s <file_to_patch>\n", argv[0]);
    exit(1);
  }
  fin = fopen(argv[1], "rb");
  for (i = 0; i < 20; i) {
    val = fgetc(fin);
    if (val == EOF)
      break;
    if (val == audio[audioi]) {
      if (audioi == 7) {
        printf("found hidden (patched) audio stream at offset 0x%x\n",
               offset - 7);
        audioi = 0;
        lastaudio = offset - 7;
        audiofound++;
      } else
        audioi++;
    } else
      audioi = 0;
    offset++;
    if (offset == 0xA000)
      break;
  }
  fclose(fin);
  printf("-----------------------------------------\n");
  if (lastaudio != 0) {
    if (audiofound == 1) {
      printf("Will now patch at offset 0x%x.", lastaudio);
      fout = fopen(argv[1], "r+b");
      fseek(fout, lastaudio + 1, SEEK_SET);
      fputc(0x9E, fout);
      fclose(fout);
      printf(" DONE! OK! \n");
    } else
      printf("ERROR! More than one offset found, I can not patch!\n");
  } else
    printf("ERROR! found no hidden audio stream, no patching done!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f3 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1212 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x14,-0x30(%rbp)
jge    12e5 <main+0x175>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%eax
jne    125e <main+0xee>
jmp    12e5 <main+0x175>
mov    -0x2c(%rbp),%eax
movslq -0x54(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jne    12b9 <main+0x149>
cmpl   $0x7,-0x54(%rbp)
jne    12ab <main+0x13b>
mov    -0x5c(%rbp),%esi
sub    $0x7,%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x5c(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12b4 <main+0x144>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12c0 <main+0x150>
movl   $0x0,-0x54(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0xa000,-0x5c(%rbp)
jne    12db <main+0x16b>
jmp    12e5 <main+0x175>
jmp    12e0 <main+0x170>
jmp    1231 <main+0xc1>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x60(%rbp)
je     138e <main+0x21e>
cmpl   $0x1,-0x58(%rbp)
jne    137b <main+0x20b>
mov    -0x60(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdae(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x60(%rbp),%esi
add    $0x1,%esi
mov    0x2c8e(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rsi
mov    $0x9e,%edi
call   1060 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1389 <main+0x219>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    139c <main+0x22c>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12ec <main+0x16c>
mov    0x8(%rbx),%rsi
lea    0xe7b(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,0x10(%rsp)
mov    0x8(%rbx),%rdi
lea    0xe9e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0xfffffff9,%ebp
mov    0x2e15(%rip),%r12
lea    0xe26(%rip),%r14
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
jmp    121e <main+0x9e>
xor    %r13d,%r13d
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
addl   $0x1,0x8(%rsp)
mov    %ebp,0xc(%rsp)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r13d,%r15d
cmp    $0x9ff9,%ebp
je     1247 <main+0xc7>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
je     1247 <main+0xc7>
movslq %r15d,%rcx
xor    %r13d,%r13d
cmp    (%r14,%rcx,4),%eax
jne    1210 <main+0x90>
cmp    $0x7,%r15d
je     11ec <main+0x6c>
add    $0x1,%r15d
mov    %r15d,%r13d
jmp    1210 <main+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%ebp
test   %ebp,%ebp
je     12c6 <main+0x146>
cmpl   $0x1,0x8(%rsp)
jne    12cf <main+0x14f>
lea    0xe23(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
add    $0x1,%ebp
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <fseek@plt>
mov    $0x9e,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe88(%rip),%rdi
jmp    12d6 <main+0x156>
lea    0xe14(%rip),%rdi
jmp    12d6 <main+0x156>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xd3a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.audio = [8 x i32] [i32 64, i32 0, i32 105, i32 248, i32 77, i32 91, i32 207, i32 17]
@.str = [16 x i8] c"[inputfile=%s]\0A\00"
@.str.1 = [45 x i8] c"more arguments needed... %s <file_to_patch>\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.3 = [52 x i8] c"found hidden (patched) audio stream at offset 0x%x\0A\00"
@.str.4 = [43 x i8] c"-----------------------------------------\0A\00"
@.str.5 = [31 x i8] c"Will now patch at offset 0x%x.\00"
@.str.6 = [4 x i8] c"r+b\00"
@SEEK_SET = global i32 0
@.str.7 = [13 x i8] c" DONE! OK! \0A\00"
@.str.8 = [53 x i8] c"ERROR! More than one offset found, I can not patch!\0A\00"
@.str.9 = [56 x i8] c"ERROR! found no hidden audio stream, no patching done!\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 i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [8 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [8 x i32]* %11 to i8*
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %30
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %6
store i32 0, i32* %10
br label %35
35: ; preds = %75, %30
%36 = load i32, i32* %10
%37 = icmp slt i32 %36, 20
br i1 %37, label %38, label %77
38: ; preds = %35
%39 = load i32*, i32** %6
%40 = call i32 @fgetc(i32* %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %38
br label %77
45: ; preds = %38
%46 = load i32, i32* %9
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp eq i32 %46, %50
br i1 %51, label %52, label %67
52: ; preds = %45
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 7
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = load i32, i32* %14
%57 = sub nsw i32 %56, 7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %57)
store i32 0, i32* %12
%59 = load i32, i32* %14
%60 = sub nsw i32 %59, 7
store i32 %60, i32* %15
%61 = load i32, i32* %13
%62 = add nsw i32 %61, 1
store i32 %62, i32* %13
br label %66
63: ; preds = %52
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %66
66: ; preds = %63, %55
br label %68
67: ; preds = %45
store i32 0, i32* %12
br label %68
68: ; preds = %67, %66
%69 = load i32, i32* %14
%70 = add nsw i32 %69, 1
store i32 %70, i32* %14
%71 = load i32, i32* %14
%72 = icmp eq i32 %71, 40960
br i1 %72, label %73, label %74
73: ; preds = %68
br label %77
74: ; preds = %68
br label %75
75: ; preds = %74
%76 = load i32, i32* %10
br label %35
77: ; preds = %73, %44, %35
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%81 = load i32, i32* %15
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %106
83: ; preds = %77
%84 = load i32, i32* %13
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %103
86: ; preds = %83
%87 = load i32, i32* %15
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %87)
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = call i32* @fopen(i8* %91, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i32* %92, i32** %7
%93 = load i32*, i32** %7
%94 = load i32, i32* %15
%95 = add nsw i32 %94, 1
%96 = load i32, i32* @SEEK_SET
%97 = call i32 @fseek(i32* %93, i32 %95, i32 %96)
%98 = load i32*, i32** %7
%99 = call i32 @fputc(i32 158, i32* %98)
%100 = load i32*, i32** %7
%101 = call i32 @fclose(i32* %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %105
103: ; preds = %83
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0))
br label %105
105: ; preds = %103, %86
br label %108
106: ; preds = %77
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
br label %108
108: ; preds = %106, %105
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
@__const.main.audio = [8 x i32] [i32 64, i32 0, i32 105, i32 248, i32 77, i32 91, i32 207, i32 17]
@.str = [16 x i8] c"[inputfile=%s]\0A\00"
@.str.1 = [45 x i8] c"more arguments needed... %s <file_to_patch>\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.3 = [52 x i8] c"found hidden (patched) audio stream at offset 0x%x\0A\00"
@.str.5 = [31 x i8] c"Will now patch at offset 0x%x.\00"
@.str.6 = [4 x i8] c"r+b\00"
@SEEK_SET = global i32 0
@str = [42 x i8] c"-----------------------------------------\00"
@str.10 = [55 x i8] c"ERROR! found no hidden audio stream, no patching done!\00"
@str.11 = [52 x i8] c"ERROR! More than one offset found, I can not patch!\00"
@str.12 = [12 x i8] c" DONE! OK! \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %5
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %14
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %35, %4
%15 = phi i32 [ 0, %4 ], [ %36, %35 ]
%16 = phi i32 [ 0, %4 ], [ %37, %35 ]
%17 = phi i32 [ 0, %4 ], [ %39, %35 ]
%18 = phi i32 [ 0, %4 ], [ %38, %35 ]
%19 = tail call i32 @fgetc(i32* %9)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %41, label %22
22: ; preds = %14
%23 = sext i32 %15 to i64
%24 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.main.audio, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %19, %25
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = icmp eq i32 %15, 7
br i1 %28, label %29, label %33
29: ; preds = %27
%30 = add nsw i32 %17, -7
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = add nsw i32 %16, 1
br label %35
33: ; preds = %27
%34 = add nsw i32 %15, 1
br label %35
35: ; preds = %22, %29, %33
%36 = phi i32 [ 0, %29 ], [ %34, %33 ], [ 0, %22 ]
%37 = phi i32 [ %32, %29 ], [ %16, %33 ], [ %16, %22 ]
%38 = phi i32 [ %30, %29 ], [ %18, %33 ], [ %18, %22 ]
%39 = add nuw nsw i32 %17, 1
%40 = icmp eq i32 %39, 40960
br i1 %40, label %41, label %14
41: ; preds = %35, %14
%42 = phi i32 [ %16, %14 ], [ %37, %35 ]
%43 = phi i32 [ %18, %14 ], [ %38, %35 ]
%44 = tail call i32 @fclose(i32* %9)
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%46 = icmp eq i32 %43, 0
br i1 %46, label %58, label %47
47: ; preds = %41
%48 = icmp eq i32 %42, 1
br i1 %48, label %49, label %58
49: ; preds = %47
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%51 = load i8*, i8** %5
%52 = tail call i32* @fopen(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%53 = add nsw i32 %43, 1
%54 = load i32, i32* @SEEK_SET
%55 = tail call i32 @fseek(i32* %52, i32 %53, i32 %54)
%56 = tail call i32 @fputc(i32 158, i32* %52)
%57 = tail call i32 @fclose(i32* %52)
br label %58
58: ; preds = %41, %47, %49
%59 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0), %49 ], [ getelementptr inbounds ([52 x i8], [52 x i8]* @str.11, i64 0, i64 0), %47 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @str.10, i64 0, i64 0), %41 ]
%60 = tail call i32 @puts(i8* dereferenceable(1) %59)
ret i32 0
}